[PATCH 2/3] writeback: attempt to allocate work struct in bdi_start_writeback()

From: Jens Axboe
Date: Tue May 19 2009 - 05:26:58 EST


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 <jens.axboe@xxxxxxxxxx>
---
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


--cWoXeonUoKmBZSoM
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0003-writeback-mm-backing-dev.c-bdi_start_fn-should-use-b.patch"