提交 c5f7ad23 编写于 作者: A Artem Bityutskiy 提交者: Jens Axboe

writeback: do not lose wake-ups in the forker thread - 1

Currently the forker thread can lose wake-ups which may lead to unnecessary
delays in processing bdi works. E.g., consider the following scenario.

1. 'bdi_forker_thread()' walks the 'bdi_list', finds out there is nothing to
   do, and is about to finish the loop.
2. A bdi thread decides to exit because it was inactive for long time.
3. 'bdi_queue_work()' adds a work to the bdi which just exited, so it wakes up
   the forker thread.
4. but 'bdi_forker_thread()' executes 'set_current_state(TASK_INTERRUPTIBLE)'
   and goes sleep. We lose a wake-up.

Losing the wake-up is not fatal, but this means that the bdi work processing
will be delayed by up to 5 sec. This race is theoretical, I never hit it, but
it is worth fixing.

The fix is to execute 'set_current_state(TASK_INTERRUPTIBLE)' _before_ walking
'bdi_list', not after.
Signed-off-by: NArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NJens Axboe <jaxboe@fusionio.com>
上级 94eac5e6
...@@ -342,6 +342,7 @@ static int bdi_forker_thread(void *ptr) ...@@ -342,6 +342,7 @@ static int bdi_forker_thread(void *ptr)
wb_do_writeback(me, 0); wb_do_writeback(me, 0);
spin_lock_bh(&bdi_lock); spin_lock_bh(&bdi_lock);
set_current_state(TASK_INTERRUPTIBLE);
/* /*
* Check if any existing bdi's have dirty data without * Check if any existing bdi's have dirty data without
...@@ -357,8 +358,6 @@ static int bdi_forker_thread(void *ptr) ...@@ -357,8 +358,6 @@ static int bdi_forker_thread(void *ptr)
bdi_add_default_flusher_thread(bdi); bdi_add_default_flusher_thread(bdi);
} }
set_current_state(TASK_INTERRUPTIBLE);
if (list_empty(&bdi_pending_list)) { if (list_empty(&bdi_pending_list)) {
unsigned long wait; unsigned long wait;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册