From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wu Fengguang Subject: [PATCH 31/45] writeback: sync old inodes first in background writeback Date: Wed, 07 Oct 2009 15:38:49 +0800 Message-ID: <20091007074905.131727024@intel.com> References: <20091007073818.318088777@intel.com> Cc: Theodore Tso , Christoph Hellwig , Dave Chinner , Chris Mason , Peter Zijlstra , "Li Shaohua" , "Myklebust Trond" , "jens.axboe@oracle.com" , Jan Kara , Nick Piggin , , Wu Fengguang To: Andrew Morton Return-path: Received: from mga03.intel.com ([143.182.124.21]:28327 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934031AbZJGICh (ORCPT ); Wed, 7 Oct 2009 04:02:37 -0400 Cc: LKML Content-Disposition: inline; filename=writeback-expired-for-background.patch Sender: linux-fsdevel-owner@vger.kernel.org List-ID: A background flush work may run for ever. So it's reasonable for it to mimic the kupdate behavior of syncing old/expired inodes first. CC: Jan Kara Signed-off-by: Wu Fengguang --- fs/fs-writeback.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- linux.orig/fs/fs-writeback.c 2009-10-06 23:39:28.000000000 +0800 +++ linux/fs/fs-writeback.c 2009-10-06 23:39:31.000000000 +0800 @@ -680,7 +680,7 @@ static long writeback_inodes_wb(struct b spin_lock(&inode_lock); - if (!wbc->for_kupdate || list_empty(&wb->b_io)) + if (list_empty(&wb->b_io)) queue_io(wb, wbc->older_than_this); while (!list_empty(&wb->b_io)) { @@ -793,14 +793,15 @@ static long wb_writeback(struct bdi_writ .range_cyclic = args->range_cyclic, }; unsigned long oldest_jif; + int expire_interval = msecs_to_jiffies(dirty_expire_interval * 10); + int fg_rounds = 0; long wrote = 0; long nr; struct inode *inode; - if (wbc.for_kupdate) { + if (wbc.for_kupdate || wbc.for_background) { wbc.older_than_this = &oldest_jif; - oldest_jif = jiffies - - msecs_to_jiffies(dirty_expire_interval * 10); + oldest_jif = jiffies - expire_interval; } if (!wbc.range_cyclic) { wbc.range_start = 0; @@ -828,6 +829,18 @@ static long wb_writeback(struct bdi_writ args->nr_pages -= nr; wrote += nr; + if (args->for_background && expire_interval && + ++fg_rounds && list_empty(&wb->b_io)) { + if (fg_rounds < 10) + expire_interval >>= 1; + if (expire_interval) + oldest_jif = jiffies - expire_interval; + else + wbc.older_than_this = 0; + fg_rounds = 0; + continue; + } + /* * Bail if no more IO */