>From b4c4af0be4ff04648d2033dc3ac4dd4d50d5864d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 19 May 2009 11:26:58 +0200 Subject: [PATCH 2/3] writeback: attempt to allocate work struct in bdi_start_writeback() If the allocation works, then we don't have to wait for the threads to wake up and notice the work. So it would potentially cause less lag in bdi_start_writeback(). If it fails, just fall back to an on-stack work struct again. Signed-off-by: Jens Axboe --- fs/fs-writeback.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 6052701..f80afaa 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -191,14 +191,25 @@ static void bdi_wait_on_work_start(struct bdi_work *work) int bdi_start_writeback(struct backing_dev_info *bdi, struct super_block *sb, long nr_pages) { - struct bdi_work work; + struct bdi_work work_stack, *work; int ret; - bdi_work_init_on_stack(&work, sb, nr_pages); + work = kmalloc(sizeof(*work), GFP_ATOMIC); + if (work) + bdi_work_init(work, sb, nr_pages); + else { + work = &work_stack; + bdi_work_init_on_stack(work, sb, nr_pages); + } - ret = bdi_queue_writeback(bdi, &work); + ret = bdi_queue_writeback(bdi, work); - bdi_wait_on_work_start(&work); + /* + * If this came from our stack, we need to wait until the wb threads + * have noticed this work before we return (and invalidate the stack) + */ + if (work == &work_stack) + bdi_wait_on_work_start(work); return ret; } -- 1.6.3.9.g6345