writeback: stop background writeback when below background threshold
[linux-block.git] / mm / page-writeback.c
index 5f378dd588027c227dc95551e27e4b6431e5df60..3c78fc316202fcfdb76a446a6228ef03e149a56e 100644 (file)
@@ -44,12 +44,15 @@ static long ratelimit_pages = 32;
 /*
  * When balance_dirty_pages decides that the caller needs to perform some
  * non-background writeback, this is how many pages it will attempt to write.
- * It should be somewhat larger than RATELIMIT_PAGES to ensure that reasonably
+ * It should be somewhat larger than dirtied pages to ensure that reasonably
  * large amounts of I/O are submitted.
  */
-static inline long sync_writeback_pages(void)
+static inline long sync_writeback_pages(unsigned long dirtied)
 {
-       return ratelimit_pages + ratelimit_pages / 2;
+       if (dirtied < ratelimit_pages)
+               dirtied = ratelimit_pages;
+
+       return dirtied + dirtied / 2;
 }
 
 /* The following parameters are exported via /proc/sys/vm */
@@ -477,7 +480,8 @@ get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty,
  * If we're over `background_thresh' then pdflush is woken to perform some
  * writeout.
  */
-static void balance_dirty_pages(struct address_space *mapping)
+static void balance_dirty_pages(struct address_space *mapping,
+                               unsigned long write_chunk)
 {
        long nr_reclaimable, bdi_nr_reclaimable;
        long nr_writeback, bdi_nr_writeback;
@@ -485,7 +489,6 @@ static void balance_dirty_pages(struct address_space *mapping)
        unsigned long dirty_thresh;
        unsigned long bdi_thresh;
        unsigned long pages_written = 0;
-       unsigned long write_chunk = sync_writeback_pages();
        unsigned long pause = 1;
 
        struct backing_dev_info *bdi = mapping->backing_dev_info;
@@ -590,10 +593,10 @@ static void balance_dirty_pages(struct address_space *mapping)
         * background_thresh, to keep the amount of dirty memory low.
         */
        if ((laptop_mode && pages_written) ||
-           (!laptop_mode && ((nr_writeback = global_page_state(NR_FILE_DIRTY)
-                                         + global_page_state(NR_UNSTABLE_NFS))
+           (!laptop_mode && ((global_page_state(NR_FILE_DIRTY)
+                              + global_page_state(NR_UNSTABLE_NFS))
                                          > background_thresh)))
-               bdi_start_writeback(bdi, nr_writeback);
+               bdi_start_writeback(bdi, 0);
 }
 
 void set_page_dirty_balance(struct page *page, int page_mkwrite)
@@ -640,9 +643,10 @@ void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
        p =  &__get_cpu_var(bdp_ratelimits);
        *p += nr_pages_dirtied;
        if (unlikely(*p >= ratelimit)) {
+               ratelimit = sync_writeback_pages(*p);
                *p = 0;
                preempt_enable();
-               balance_dirty_pages(mapping);
+               balance_dirty_pages(mapping, ratelimit);
                return;
        }
        preempt_enable();