File fix-cpu-spin.patch of Package cachefilesd

Git-commit: 9a4160bcfc4b859b848fabed112ee9382be3cc27
From: NeilBrown <neilb@suse.de>
Date: Tue, 4 Feb 2014 15:47:00 +1100
Subject: [PATCH] cachefilesd can spin when disk space is short.
References:  bnc#843575

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@suse.de>

---
 cachefilesd.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- cachefilesd-0.10.5.orig/cachefilesd.c
+++ cachefilesd-0.10.5/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;
openSUSE Build Service is sponsored by