Skip to contentSkip to conversation

ext4: fix lazyinit thread prevent from sleep

PATCH In review Lukas Czerner 2 participants 2 messages Oct 22, 2010 – Oct 25, 2010 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: fix lazyinit thread prevent from sleep

In my test lazyinit threat (in linux-next tree) consumes too much CPU (90%). The reason is that there is a bug preventing the threat to sleep and hence it keeps walking the li_request_list until the time for next scheduled request comes.

It is because the next_wakeup is originally set to jiffies - 1 so the thread is assuming that there is no reason to sleep, because the time for next scheduled event is already came, however that is not true.

I have fixed that by setting next_wakeup to MAX_JIFFY_OFFSET initially and than setting value of the next scheduled request (the one with the smallest lr_next_sched value). It has been tested and now the CPU utilization of lazyinit thread is under 1% (with one request in the list).

---
 fs/ext4/super.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
fs/ext4/super.c +5 -4
index 82ceb8b..f0b424a 100644
@@ -2710,7 +2710,7 @@ static int ext4_lazyinit_thread(void *arg)
 
 cont_thread:
 	while (true) {
-		next_wakeup = jiffies-1;
+		next_wakeup = MAX_JIFFY_OFFSET;
 
 		mutex_lock(&eli->li_list_mtx);
 		if (list_empty(&eli->li_request_list)) {
@@ -2722,10 +2722,11 @@ cont_thread:
 			elr = list_entry(pos, struct ext4_li_request,
 					 lr_request);
 
-			if (time_before_eq(jiffies, elr->lr_next_sched))
-				continue;
+			if (time_after_eq(jiffies, elr->lr_next_sched))
+				ret = ext4_run_li_request(elr);
 
-			if ((ret = ext4_run_li_request(elr)) != 0) {
+			if (ret) {
+				ret = 0;
 				ext4_remove_li_request(elr);
 				continue;
 			}
Signature · 1 line
1.7.2.3
maintainer
#1 lore raw
Quoted 9 lines · Lukas Czerner

In my test lazyinit threat (in linux-next tree) consumes too much CPU (90%). The reason is that there is a bug preventing the threat to sleep and hence it keeps walking the li_request_list until the time for next scheduled request comes.

It is because the next_wakeup is originally set to jiffies - 1 so the thread is assuming that there is no reason to sleep, because the time for next scheduled event is already came, however that is not true.

Quoted 6 lines

I have fixed that by setting next_wakeup to MAX_JIFFY_OFFSET initially and than setting value of the next scheduled request (the one with the smallest lr_next_sched value). It has been tested and now the CPU utilization of lazyinit thread is under 1% (with one request in the list).

Thanks, I've merged this into the lazy-init patch in the ext4 patch queue.

- Ted