public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: Fix busyloop in wb_writeback()
@ 2009-09-16 17:22 Jan Kara
  2009-09-16 18:41 ` Jens Axboe
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Jan Kara @ 2009-09-16 17:22 UTC (permalink / raw)
  To: jens.axboe; +Cc: LKML, Jan Kara, Wu Fengguang

If all inodes are under writeback (e.g. in case when there's only one inode
with dirty pages), wb_writeback() with WB_SYNC_NONE work basically degrades
to busylooping until I_SYNC flags of the inode is cleared. Fix the problem by
waiting on I_SYNC flags of an inode on b_more_io list in case we failed to
write anything.

CC: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/fs-writeback.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 8e1e5e1..c59d673 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -706,6 +706,7 @@ static long wb_writeback(struct bdi_writeback *wb,
 	};
 	unsigned long oldest_jif;
 	long wrote = 0;
+	struct inode *inode;
 
 	if (wbc.for_kupdate) {
 		wbc.older_than_this = &oldest_jif;
@@ -747,8 +748,24 @@ static long wb_writeback(struct bdi_writeback *wb,
 		 * If we ran out of stuff to write, bail unless more_io got set
 		 */
 		if (wbc.nr_to_write > 0 || wbc.pages_skipped > 0) {
-			if (wbc.more_io && !wbc.for_kupdate)
+			if (wbc.more_io && !wbc.for_kupdate) {
+				if (wbc.nr_to_write < MAX_WRITEBACK_PAGES)
+					continue;
+				/*
+				 * Nothing written. Wait for some inode to
+				 * become available for writeback. Otherwise
+				 * we'll just busyloop.
+				 */
+				spin_lock(&inode_lock);
+				if (!list_empty(&wb->b_more_io))  {
+					inode = list_entry(
+							wb->b_more_io.prev,
+							struct inode, i_list);
+					inode_wait_for_writeback(inode);
+				}
+				spin_unlock(&inode_lock);
 				continue;
+			}
 			break;
 		}
 	}
-- 
1.6.0.2


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2009-09-23  7:56 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-16 17:22 [PATCH] fs: Fix busyloop in wb_writeback() Jan Kara
2009-09-16 18:41 ` Jens Axboe
2009-09-17  9:09   ` Jan Kara
2009-09-21 13:01   ` Wu Fengguang
2009-09-21 13:06     ` Jens Axboe
2009-09-21 13:10       ` Wu Fengguang
2009-09-21 13:40         ` Jens Axboe
2009-09-21 13:19     ` Jan Kara
2009-09-21 13:28       ` Wu Fengguang
2009-09-19  1:53 ` Wu Fengguang
2009-09-20  2:35 ` Wu Fengguang
2009-09-20 17:43   ` Jan Kara
2009-09-21  1:08     ` Wu Fengguang
2009-09-21 13:45       ` Jan Kara
2009-09-21 14:11         ` Wu Fengguang
2009-09-21 14:19           ` Chris Mason
2009-09-21 14:31             ` Wu Fengguang
2009-09-21 14:45               ` Chris Mason
2009-09-22  9:14                 ` Wu Fengguang
2009-09-23  7:56 ` Wu Fengguang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox