writeback: restructure bdi forker loop a little

This patch re-structures the bdi forker a little:
1. Add 'bdi_cap_flush_forker(bdi)' condition check to the bdi loop. The reason
   for this is that the forker thread can start _before_ the 'BDI_registered'
   flag is set (see 'bdi_register()'), so the WARN() statement will fire for
   the default bdi. I observed this warning at boot-up.

2. Introduce an enum 'action' and use "switch" statement in the outer loop.
   This is a preparation to the further patch which will teach the forker
   thread killing bdi threads, so we'll have another case in the "switch"
   statement. This change was suggested by Christoph Hellwig.

This patch is just a small step towards the coming change where the forker
thread will kill the bdi threads. It should simplify reviewing the following
changes, which would otherwise be larger.

This patch also amends comments a little.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
This commit is contained in:
Artem Bityutskiy 2010-07-25 14:29:19 +03:00 committed by Jens Axboe
parent ecd584030d
commit adf3924070

View file

@ -329,9 +329,12 @@ static int bdi_forker_thread(void *ptr)
set_user_nice(current, 0); set_user_nice(current, 0);
for (;;) { for (;;) {
bool fork = false;
struct task_struct *task; struct task_struct *task;
struct backing_dev_info *bdi; struct backing_dev_info *bdi;
enum {
NO_ACTION, /* Nothing to do */
FORK_THREAD, /* Fork bdi thread */
} action = NO_ACTION;
/* /*
* Temporary measure, we want to make sure we don't see * Temporary measure, we want to make sure we don't see
@ -348,56 +351,62 @@ static int bdi_forker_thread(void *ptr)
* a thread registered. If so, set that up. * a thread registered. If so, set that up.
*/ */
list_for_each_entry(bdi, &bdi_list, bdi_list) { list_for_each_entry(bdi, &bdi_list, bdi_list) {
if (!bdi_cap_writeback_dirty(bdi)) bool have_dirty_io;
continue;
if (bdi->wb.task) if (!bdi_cap_writeback_dirty(bdi) ||
continue; bdi_cap_flush_forker(bdi))
if (list_empty(&bdi->work_list) &&
!bdi_has_dirty_io(bdi))
continue; continue;
WARN(!test_bit(BDI_registered, &bdi->state), WARN(!test_bit(BDI_registered, &bdi->state),
"bdi %p/%s is not registered!\n", bdi, bdi->name); "bdi %p/%s is not registered!\n", bdi, bdi->name);
fork = true; have_dirty_io = !list_empty(&bdi->work_list) ||
wb_has_dirty_io(&bdi->wb);
/*
* If the bdi has work to do, but the thread does not
* exist - create it.
*/
if (!bdi->wb.task && have_dirty_io) {
/* /*
* Set the pending bit - if someone will try to * Set the pending bit - if someone will try to
* unregister this bdi - it'll wait on this bit. * unregister this bdi - it'll wait on this bit.
*/ */
set_bit(BDI_pending, &bdi->state); set_bit(BDI_pending, &bdi->state);
action = FORK_THREAD;
break; break;
} }
}
spin_unlock_bh(&bdi_lock); spin_unlock_bh(&bdi_lock);
/* Keep working if default bdi still has things to do */ /* Keep working if default bdi still has things to do */
if (!list_empty(&me->bdi->work_list)) if (!list_empty(&me->bdi->work_list))
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
if (!fork) { switch (action) {
unsigned long wait; case FORK_THREAD:
wait = msecs_to_jiffies(dirty_writeback_interval * 10);
if (wait)
schedule_timeout(wait);
else
schedule();
try_to_freeze();
continue;
}
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
task = kthread_run(bdi_writeback_thread, &bdi->wb, "flush-%s", task = kthread_run(bdi_writeback_thread, &bdi->wb, "flush-%s",
dev_name(bdi->dev)); dev_name(bdi->dev));
if (IS_ERR(task)) { if (IS_ERR(task)) {
/* /*
* If thread creation fails, force writeout of the bdi * If thread creation fails, force writeout of
* from the thread. * the bdi from the thread.
*/ */
bdi_flush_io(bdi); bdi_flush_io(bdi);
} else } else
bdi->wb.task = task; bdi->wb.task = task;
break;
case NO_ACTION:
if (dirty_writeback_interval)
schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
else
schedule();
try_to_freeze();
/* Back to the main loop */
continue;
}
} }
return 0; return 0;