writeback: get rid to incorrect references to pdflush in comments
[safe/jmp/linux-2.6] / fs / fs-writeback.c
index 55f0d4e..15944f7 100644 (file)
@@ -41,8 +41,9 @@ struct wb_writeback_args {
        long nr_pages;
        struct super_block *sb;
        enum writeback_sync_modes sync_mode;
-       int for_kupdate;
-       int range_cyclic;
+       int for_kupdate:1;
+       int range_cyclic:1;
+       int for_background:1;
 };
 
 /*
@@ -97,6 +98,11 @@ static void bdi_work_clear(struct bdi_work *work)
 {
        clear_bit(WS_USED_B, &work->state);
        smp_mb__after_clear_bit();
+       /*
+        * work can have disappeared at this point. bit waitq functions
+        * should be able to tolerate this, provided bdi_sched_wait does
+        * not dereference it's pointer argument.
+       */
        wake_up_bit(&work->state, WS_USED_B);
 }
 
@@ -113,6 +119,7 @@ static void bdi_work_free(struct rcu_head *head)
 static void wb_work_complete(struct bdi_work *work)
 {
        const enum writeback_sync_modes sync_mode = work->args.sync_mode;
+       int onstack = bdi_work_on_stack(work);
 
        /*
         * For allocated work, we can clear the done/seen bit right here.
@@ -120,9 +127,9 @@ static void wb_work_complete(struct bdi_work *work)
         * to after the RCU grace period, since the stack could be invalidated
         * as soon as bdi_work_clear() has done the wakeup.
         */
-       if (!bdi_work_on_stack(work))
+       if (!onstack)
                bdi_work_clear(work);
-       if (sync_mode == WB_SYNC_NONE || bdi_work_on_stack(work))
+       if (sync_mode == WB_SYNC_NONE || onstack)
                call_rcu(&work->rcu_head, bdi_work_free);
 }
 
@@ -151,10 +158,10 @@ static void bdi_queue_work(struct backing_dev_info *bdi, struct bdi_work *work)
        BUG_ON(!bdi->wb_cnt);
 
        /*
-        * Make sure stores are seen before it appears on the list
+        * list_add_tail_rcu() contains the necessary barriers to
+        * make sure the above stores are seen before the item is
+        * noticed on the list
         */
-       smp_mb();
-
        spin_lock(&bdi->wb_lock);
        list_add_tail_rcu(&work->list, &bdi->work_list);
        spin_unlock(&bdi->wb_lock);
@@ -168,13 +175,7 @@ static void bdi_queue_work(struct backing_dev_info *bdi, struct bdi_work *work)
        else {
                struct bdi_writeback *wb = &bdi->wb;
 
-               /*
-                * End work now if this wb has no dirty IO pending. Otherwise
-                * wakeup the handling thread
-                */
-               if (!wb_has_dirty_io(wb))
-                       wb_clear_pending(wb, work);
-               else if (wb->task)
+               if (wb->task)
                        wake_up_process(wb->task);
        }
 }
@@ -257,6 +258,15 @@ void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages)
                .range_cyclic   = 1,
        };
 
+       /*
+        * We treat @nr_pages=0 as the special case to do background writeback,
+        * ie. to sync pages until the background dirty threshold is reached.
+        */
+       if (!nr_pages) {
+               args.nr_pages = LONG_MAX;
+               args.for_background = 1;
+       }
+
        bdi_alloc_queue_work(bdi, &args);
 }
 
@@ -310,7 +320,7 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)
         * For inodes being constantly redirtied, dirtied_when can get stuck.
         * It _appears_ to be in the future, but is actually in distant past.
         * This test is necessary to prevent such wrapped-around relative times
-        * from permanently stopping the whole pdflush writeback.
+        * from permanently stopping the whole bdi writeback.
         */
        ret = ret && time_before_eq(inode->dirtied_when, jiffies);
 #endif
@@ -439,8 +449,13 @@ 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) &&
-                   mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
+               if (inode->i_state & I_DIRTY) {
+                       /*
+                        * Someone redirtied the inode while were writing back
+                        * the pages.
+                        */
+                       redirty_tail(inode);
+               } else if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
                        /*
                         * We didn't write back all the pages.  nfs_writepages()
                         * sometimes bales out without doing anything. Redirty
@@ -484,12 +499,6 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
                                inode->i_state |= I_DIRTY_PAGES;
                                redirty_tail(inode);
                        }
-               } else if (inode->i_state & I_DIRTY) {
-                       /*
-                        * Someone redirtied the inode while were writing back
-                        * the pages.
-                        */
-                       redirty_tail(inode);
                } else if (atomic_read(&inode->i_count)) {
                        /*
                         * The inode is clean, inuse
@@ -706,6 +715,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;
@@ -719,20 +729,16 @@ static long wb_writeback(struct bdi_writeback *wb,
 
        for (;;) {
                /*
-                * Don't flush anything for non-integrity writeback where
-                * no nr_pages was given
+                * Stop writeback when nr_pages has been consumed
                 */
-               if (!args->for_kupdate && args->nr_pages <= 0 &&
-                    args->sync_mode == WB_SYNC_NONE)
+               if (args->nr_pages <= 0)
                        break;
 
                /*
-                * If no specific pages were given and this is just a
-                * periodic background writeout and we are below the
-                * background dirty threshold, don't do anything
+                * For background writeout, stop when we are below the
+                * background dirty threshold
                 */
-               if (args->for_kupdate && args->nr_pages <= 0 &&
-                   !over_bground_thresh())
+               if (args->for_background && !over_bground_thresh())
                        break;
 
                wbc.more_io = 0;
@@ -744,13 +750,32 @@ static long wb_writeback(struct bdi_writeback *wb,
                wrote += MAX_WRITEBACK_PAGES - wbc.nr_to_write;
 
                /*
-                * If we ran out of stuff to write, bail unless more_io got set
+                * If we consumed everything, see if we have more
                 */
-               if (wbc.nr_to_write > 0 || wbc.pages_skipped > 0) {
-                       if (wbc.more_io && !wbc.for_kupdate)
-                               continue;
+               if (wbc.nr_to_write <= 0)
+                       continue;
+               /*
+                * Didn't write everything and we don't have more IO, bail
+                */
+               if (!wbc.more_io)
                        break;
+               /*
+                * Did we write something? Try for more
+                */
+               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);
        }
 
        return wrote;
@@ -772,8 +797,9 @@ static struct bdi_work *get_next_work_item(struct backing_dev_info *bdi,
        rcu_read_lock();
 
        list_for_each_entry_rcu(work, &bdi->work_list, list) {
-               if (!test_and_clear_bit(wb->nr, &work->seen))
+               if (!test_bit(wb->nr, &work->seen))
                        continue;
+               clear_bit(wb->nr, &work->seen);
 
                ret = work;
                break;
@@ -884,8 +910,7 @@ int bdi_writeback_task(struct bdi_writeback *wb)
                }
 
                wait_jiffies = msecs_to_jiffies(dirty_writeback_interval * 10);
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(wait_jiffies);
+               schedule_timeout_interruptible(wait_jiffies);
                try_to_freeze();
        }
 
@@ -1060,9 +1085,6 @@ EXPORT_SYMBOL(__mark_inode_dirty);
  * If older_than_this is non-NULL, then only write out inodes which
  * had their first dirtying at a time earlier than *older_than_this.
  *
- * If we're a pdlfush thread, then implement pdflush collision avoidance
- * against the entire list.
- *
  * If `bdi' is non-zero then we're being asked to writeback a specific queue.
  * This function assumes that the blockdev superblock's inodes are backed by
  * a variety of queues, so all inodes are searched.  For other superblocks,