]> git.hungrycats.org Git - linux/commitdiff
[PATCH] dirty inode writeback fix
authorAndrew Morton <akpm@digeo.com>
Fri, 20 Jun 2003 15:14:49 +0000 (08:14 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Fri, 20 Jun 2003 15:14:49 +0000 (08:14 -0700)
Both sys_sync() and the kupdate function need to precalculate the number of
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, needing
to know not to account for memory-backed inodes, etc.  But it is probably a
better thing to do.

fs/fs-writeback.c
mm/page-writeback.c

index ffece5ab894c6969a0f84f7770597f06df059907..92682b02ff12416c5efc19cd8c506d320f246491 100644 (file)
@@ -369,6 +369,9 @@ writeback_inodes(struct writeback_control *wbc)
  *
  * 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 *sb, int wait)
 
        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);
index 793cce9a80e2880acd10c3e4d1fe202753e8a3e7..db2e96ea0fdfdc1179f18faecddf90836c8cfe8d 100644 (file)
@@ -323,7 +323,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;