nfsd4: reshuffle lease-setting code to allow reuse
[safe/jmp/linux-2.6] / fs / fs-writeback.c
index 15944f7..1a7c42c 100644 (file)
@@ -242,6 +242,7 @@ static void bdi_sync_writeback(struct backing_dev_info *bdi,
 /**
  * bdi_start_writeback - start writeback
  * @bdi: the backing device to write from
+ * @sb: write inodes from this super_block
  * @nr_pages: the number of pages to write
  *
  * Description:
@@ -250,9 +251,11 @@ static void bdi_sync_writeback(struct backing_dev_info *bdi,
  *   completion. Caller need not hold sb s_umount semaphore.
  *
  */
-void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages)
+void bdi_start_writeback(struct backing_dev_info *bdi, struct super_block *sb,
+                        long nr_pages)
 {
        struct wb_writeback_args args = {
+               .sb             = sb,
                .sync_mode      = WB_SYNC_NONE,
                .nr_pages       = nr_pages,
                .range_cyclic   = 1,
@@ -334,13 +337,38 @@ static void move_expired_inodes(struct list_head *delaying_queue,
                               struct list_head *dispatch_queue,
                                unsigned long *older_than_this)
 {
+       LIST_HEAD(tmp);
+       struct list_head *pos, *node;
+       struct super_block *sb = NULL;
+       struct inode *inode;
+       int do_sb_sort = 0;
+
        while (!list_empty(delaying_queue)) {
-               struct inode *inode = list_entry(delaying_queue->prev,
-                                               struct inode, i_list);
+               inode = list_entry(delaying_queue->prev, struct inode, i_list);
                if (older_than_this &&
                    inode_dirtied_after(inode, *older_than_this))
                        break;
-               list_move(&inode->i_list, dispatch_queue);
+               if (sb && sb != inode->i_sb)
+                       do_sb_sort = 1;
+               sb = inode->i_sb;
+               list_move(&inode->i_list, &tmp);
+       }
+
+       /* just one sb in list, splice to dispatch_queue and we're done */
+       if (!do_sb_sort) {
+               list_splice(&tmp, dispatch_queue);
+               return;
+       }
+
+       /* Move inodes from one superblock together */
+       while (!list_empty(&tmp)) {
+               inode = list_entry(tmp.prev, struct inode, i_list);
+               sb = inode->i_sb;
+               list_for_each_prev_safe(pos, node, &tmp) {
+                       inode = list_entry(pos, struct inode, i_list);
+                       if (inode->i_sb == sb)
+                               list_move(&inode->i_list, dispatch_queue);
+               }
        }
 }
 
@@ -449,10 +477,15 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
        spin_lock(&inode_lock);
        inode->i_state &= ~I_SYNC;
        if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
-               if (inode->i_state & I_DIRTY) {
+               if ((inode->i_state & I_DIRTY_PAGES) && wbc->for_kupdate) {
                        /*
-                        * Someone redirtied the inode while were writing back
-                        * the pages.
+                        * More pages get dirtied by a fast dirtier.
+                        */
+                       goto select_queue;
+               } else if (inode->i_state & I_DIRTY) {
+                       /*
+                        * At least XFS will redirty the inode during the
+                        * writeback (delalloc) and on io completion (isize).
                         */
                        redirty_tail(inode);
                } else if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
@@ -477,6 +510,7 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
                                 * soon as the queue becomes uncongested.
                                 */
                                inode->i_state |= I_DIRTY_PAGES;
+select_queue:
                                if (wbc->nr_to_write <= 0) {
                                        /*
                                         * slice used up: queue for next turn
@@ -515,6 +549,17 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
        return ret;
 }
 
+static void unpin_sb_for_writeback(struct super_block **psb)
+{
+       struct super_block *sb = *psb;
+
+       if (sb) {
+               up_read(&sb->s_umount);
+               put_super(sb);
+               *psb = NULL;
+       }
+}
+
 /*
  * For WB_SYNC_NONE writeback, the caller does not have the sb pinned
  * before calling writeback. So make sure that we do pin it, so it doesn't
@@ -524,11 +569,20 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
  * 1 if we failed.
  */
 static int pin_sb_for_writeback(struct writeback_control *wbc,
-                                  struct inode *inode)
+                               struct inode *inode, struct super_block **psb)
 {
        struct super_block *sb = inode->i_sb;
 
        /*
+        * If this sb is already pinned, nothing more to do. If not and
+        * *psb is non-NULL, unpin the old one first
+        */
+       if (sb == *psb)
+               return 0;
+       else if (*psb)
+               unpin_sb_for_writeback(psb);
+
+       /*
         * Caller must already hold the ref for this
         */
        if (wbc->sync_mode == WB_SYNC_ALL) {
@@ -541,7 +595,7 @@ static int pin_sb_for_writeback(struct writeback_control *wbc,
        if (down_read_trylock(&sb->s_umount)) {
                if (sb->s_root) {
                        spin_unlock(&sb_lock);
-                       return 0;
+                       goto pinned;
                }
                /*
                 * umounted, drop rwsem again and fall through to failure
@@ -552,25 +606,15 @@ static int pin_sb_for_writeback(struct writeback_control *wbc,
        sb->s_count--;
        spin_unlock(&sb_lock);
        return 1;
-}
-
-static void unpin_sb_for_writeback(struct writeback_control *wbc,
-                                  struct inode *inode)
-{
-       struct super_block *sb = inode->i_sb;
-
-       if (wbc->sync_mode == WB_SYNC_ALL)
-               return;
-
-       up_read(&sb->s_umount);
-       put_super(sb);
+pinned:
+       *psb = sb;
+       return 0;
 }
 
 static void writeback_inodes_wb(struct bdi_writeback *wb,
                                struct writeback_control *wbc)
 {
-       struct super_block *sb = wbc->sb;
-       const int is_blkdev_sb = sb_is_blkdev_sb(sb);
+       struct super_block *sb = wbc->sb, *pin_sb = NULL;
        const unsigned long start = jiffies;    /* livelock avoidance */
 
        spin_lock(&inode_lock);
@@ -591,36 +635,11 @@ static void writeback_inodes_wb(struct bdi_writeback *wb,
                        continue;
                }
 
-               if (!bdi_cap_writeback_dirty(wb->bdi)) {
-                       redirty_tail(inode);
-                       if (is_blkdev_sb) {
-                               /*
-                                * Dirty memory-backed blockdev: the ramdisk
-                                * driver does this.  Skip just this inode
-                                */
-                               continue;
-                       }
-                       /*
-                        * Dirty memory-backed inode against a filesystem other
-                        * than the kernel-internal bdev filesystem.  Skip the
-                        * entire superblock.
-                        */
-                       break;
-               }
-
                if (inode->i_state & (I_NEW | I_WILL_FREE)) {
                        requeue_io(inode);
                        continue;
                }
 
-               if (wbc->nonblocking && bdi_write_congested(wb->bdi)) {
-                       wbc->encountered_congestion = 1;
-                       if (!is_blkdev_sb)
-                               break;          /* Skip a congested fs */
-                       requeue_io(inode);
-                       continue;               /* Skip a congested blockdev */
-               }
-
                /*
                 * Was this inode dirtied after sync_sb_inodes was called?
                 * This keeps sync from extra jobs and livelock.
@@ -628,7 +647,7 @@ static void writeback_inodes_wb(struct bdi_writeback *wb,
                if (inode_dirtied_after(inode, start))
                        break;
 
-               if (pin_sb_for_writeback(wbc, inode)) {
+               if (pin_sb_for_writeback(wbc, inode, &pin_sb)) {
                        requeue_io(inode);
                        continue;
                }
@@ -637,7 +656,6 @@ static void writeback_inodes_wb(struct bdi_writeback *wb,
                __iget(inode);
                pages_skipped = wbc->pages_skipped;
                writeback_single_inode(inode, wbc);
-               unpin_sb_for_writeback(wbc, inode);
                if (wbc->pages_skipped != pages_skipped) {
                        /*
                         * writeback is not making progress due to locked
@@ -657,6 +675,8 @@ static void writeback_inodes_wb(struct bdi_writeback *wb,
                        wbc->more_io = 1;
        }
 
+       unpin_sb_for_writeback(&pin_sb);
+
        spin_unlock(&inode_lock);
        /* Leave any unwritten inodes on b_io */
 }
@@ -711,6 +731,7 @@ static long wb_writeback(struct bdi_writeback *wb,
                .sync_mode              = args->sync_mode,
                .older_than_this        = NULL,
                .for_kupdate            = args->for_kupdate,
+               .for_background         = args->for_background,
                .range_cyclic           = args->range_cyclic,
        };
        unsigned long oldest_jif;
@@ -742,7 +763,6 @@ static long wb_writeback(struct bdi_writeback *wb,
                        break;
 
                wbc.more_io = 0;
-               wbc.encountered_congestion = 0;
                wbc.nr_to_write = MAX_WRITEBACK_PAGES;
                wbc.pages_skipped = 0;
                writeback_inodes_wb(wb, &wbc);
@@ -1163,11 +1183,28 @@ void writeback_inodes_sb(struct super_block *sb)
        nr_to_write = nr_dirty + nr_unstable +
                        (inodes_stat.nr_inodes - inodes_stat.nr_unused);
 
-       bdi_writeback_all(sb, nr_to_write);
+       bdi_start_writeback(sb->s_bdi, sb, nr_to_write);
 }
 EXPORT_SYMBOL(writeback_inodes_sb);
 
 /**
+ * writeback_inodes_sb_if_idle -       start writeback if none underway
+ * @sb: the superblock
+ *
+ * Invoke writeback_inodes_sb if no writeback is currently underway.
+ * Returns 1 if writeback was started, 0 if not.
+ */
+int writeback_inodes_sb_if_idle(struct super_block *sb)
+{
+       if (!writeback_in_progress(sb->s_bdi)) {
+               writeback_inodes_sb(sb);
+               return 1;
+       } else
+               return 0;
+}
+EXPORT_SYMBOL(writeback_inodes_sb_if_idle);
+
+/**
  * sync_inodes_sb      -       sync sb inode pages
  * @sb: the superblock
  *