Both sys_sync() and the kupdate function need to precalculate the numberof
pages which they are prepared to write.  Mainly for livelock avoidance.

But they also must write inodes, and dirty inodes do not contribute to dirty
page accounting (oops).  Net effect: when there are lots of dirty inodes and
few dirty pages, we forget to write inodes.

This mainly affects atime updates, because most other inode-dirtying activity
will generate dirty pages too.

It mainly affects ext2.


Now, writing an ext2 inode will just dirty the underlying blockdev pagecache
page.  So what the patch does is to assume that writing one inode will dirty
up to one pagecache page.  So the patch adds (inodes_stat.nr_inodes -
inodes_stat.nr_unused) into the number of pages to be written.

I considered creating inodes_stat.nr_dirty.  It looks fairly messy, neednig
to know not to account for memory-backed inodes, etc.  But it is probably a
better thing to do.



 fs/fs-writeback.c   |    7 ++++++-
 mm/page-writeback.c |    3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff -puN fs/fs-writeback.c~sync-write-more-pages fs/fs-writeback.c
--- 25/fs/fs-writeback.c~sync-write-more-pages	2003-06-13 02:13:28.000000000 -0700
+++ 25-akpm/fs/fs-writeback.c	2003-06-13 02:13:28.000000000 -0700
@@ -369,6 +369,9 @@ writeback_inodes(struct writeback_contro
  *
  * A finite limit is set on the number of pages which will be written.
  * To prevent infinite livelock of sys_sync().
+ *
+ * We add in the number of potentially dirty inodes, because each inode write
+ * can dirty pagecache in the underlying blockdev.
  */
 void sync_inodes_sb(struct super_block *sb, int wait)
 {
@@ -382,7 +385,9 @@ void sync_inodes_sb(struct super_block *
 
 	get_page_state(&ps);
 	wbc.nr_to_write = ps.nr_dirty + ps.nr_unstable +
-		(ps.nr_dirty + ps.nr_unstable) / 4;
+			(inodes_stat.nr_inodes - inodes_stat.nr_unused) +
+			ps.nr_dirty + ps.nr_unstable;
+	wbc.nr_to_write += wbc.nr_to_write / 2;		/* Bit more for luck */
 	spin_lock(&inode_lock);
 	sync_sb_inodes(sb, &wbc);
 	spin_unlock(&inode_lock);
diff -puN mm/page-writeback.c~sync-write-more-pages mm/page-writeback.c
--- 25/mm/page-writeback.c~sync-write-more-pages	2003-06-13 02:13:28.000000000 -0700
+++ 25-akpm/mm/page-writeback.c	2003-06-13 02:13:28.000000000 -0700
@@ -331,7 +331,8 @@ static void wb_kupdate(unsigned long arg
 	oldest_jif = jiffies - (dirty_expire_centisecs * HZ) / 100;
 	start_jif = jiffies;
 	next_jif = start_jif + (dirty_writeback_centisecs * HZ) / 100;
-	nr_to_write = ps.nr_dirty + ps.nr_unstable;
+	nr_to_write = ps.nr_dirty + ps.nr_unstable +
+			(inodes_stat.nr_inodes - inodes_stat.nr_unused);
 	while (nr_to_write > 0) {
 		wbc.encountered_congestion = 0;
 		wbc.nr_to_write = MAX_WRITEBACK_PAGES;

_