[Linux-cachefs] [PATCH] cachefilesd can spin when disk space is short.

NeilBrown neilb at suse.de
Tue Feb 4 04:47:00 UTC 2014


When cachefilesd finds that it needs to cull, but that culling doesn't
achieve anything, it sets an alarm to wake it in 30 seconds to try again.
But as read_cache_state() will detect that culling is still needed, it will
immediately try again anyway.

This results in 100% cpu usage of no value.

This patch causes culling to be blocked until the 30 second alarm goes off.

It also changes the test to decide whether to enter poll() after blocking
signals to test exactly those values that might be changed by a signal.
Testing these is important, testing anything else is pointless.

Signed-off-by: NeilBrown <neilb at suse.de>

diff --git a/cachefilesd.c b/cachefilesd.c
index 705987699021..c1b204a5abef 100644
--- a/cachefilesd.c
+++ b/cachefilesd.c
@@ -98,6 +98,7 @@ static struct object **cullready;
 static int oldest_build = -1;
 static int oldest_ready = -1;
 static int ncullable = 0;
+static int cull_delayed = 0;
 
 
 static const char *configfile = "/etc/cachefilesd.conf";
@@ -244,6 +245,7 @@ static void sigio(int sig)
 static void sigalrm(int sig)
 {
 	jumpstart_scan = 1;
+	cull_delayed = 0;
 }
 
 /*****************************************************************************/
@@ -605,11 +607,11 @@ static void cachefilesd(void)
 
 		/* sleep without racing on reap and cull with the signal
 		 * handlers */
-		if (!scan && !reap && !cull) {
+		if (!scan && !reap && !(cull && !cull_delayed)) {
 			if (sigprocmask(SIG_BLOCK, &sigs, &osigs) < 0)
 				oserror("Unable to block signals");
 
-			if (!reap && !cull) {
+			if (!reap && !stop && !jumpstart_scan) {
 				if (ppoll(pollfds, 1, NULL, &osigs) < 0 &&
 				    errno != EINTR)
 					oserror("Unable to suspend process");
@@ -636,7 +638,7 @@ static void cachefilesd(void)
 			if (cull) {
 				if (oldest_ready >= 0)
 					cull_objects();
-				else if (oldest_build < 0)
+				else if (oldest_build < 0 && !cull_delayed)
 					jumpstart_scan = 1;
 			}
 
@@ -1351,6 +1353,7 @@ static void decant_cull_table(void)
 
 	/* if nothing there, scan again in a short while */
 	if (oldest_build < 0) {
+		cull_delayed = 1;
 		signal(SIGALRM, sigalrm);
 		alarm(30);
 		return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/linux-cachefs/attachments/20140204/8a8a05a8/attachment.sig>


More information about the Linux-cachefs mailing list