linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] fs-writeback: Using spin_lock to check for work_list empty
@ 2011-08-31  5:11 Rajan Aggarwal
  2011-08-31  6:46 ` Rajan Aggarwal
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Rajan Aggarwal @ 2011-08-31  5:11 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel, Rajan Aggarwal

The bdi_writeback_thread function does not use spin_lock to
see if the work_list is empty.

If the list is not empty, and if an interrupt happens before we
set the current->state to TASK_RUNNING then we could be stuck in
a schedule() due to kernel preemption.

This patch acquires and releases the wb_lock to avoid this scenario.

Signed-off-by: Rajan Aggarwal <rajan.aggarwal85@gmail.com>
---
 fs/fs-writeback.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 04cf3b9..e333898 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -936,11 +936,14 @@ int bdi_writeback_thread(void *data)
 		if (pages_written)
 			wb->last_active = jiffies;
 
+		spin_lock_bh(&bdi->wb_lock);
 		set_current_state(TASK_INTERRUPTIBLE);
 		if (!list_empty(&bdi->work_list) || kthread_should_stop()) {
 			__set_current_state(TASK_RUNNING);
+			spin_unlock_bh(&bdi->wb_lock);
 			continue;
 		}
+		spin_unlock_bh(&bdi->wb_lock);
 
 		if (wb_has_dirty_io(wb) && dirty_writeback_interval)
 			schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-09-01 11:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-31  5:11 [PATCH 1/1] fs-writeback: Using spin_lock to check for work_list empty Rajan Aggarwal
2011-08-31  6:46 ` Rajan Aggarwal
2011-08-31  6:51   ` Rajan Aggarwal
2011-08-31 21:27 ` Andrew Morton
2011-09-01  7:54 ` KAMEZAWA Hiroyuki
2011-09-01 11:56 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).