aboutsummaryrefslogtreecommitdiffstats
path: root/mm/page-writeback.c
diff options
context:
space:
mode:
authorWu Fengguang <fengguang.wu@intel.com>2010-08-29 13:22:30 -0400
committerWu Fengguang <fengguang.wu@intel.com>2011-07-10 01:09:01 -0400
commite98be2d599207c6b31e9bb340d52a231b2f3662d (patch)
tree3ae28e7d621a6e2ddf8e7462f8d282901c113d5c /mm/page-writeback.c
parentf7d2b1ecd0c714adefc7d3a942ef87beb828a763 (diff)
writeback: bdi write bandwidth estimation
The estimation value will start from 100MB/s and adapt to the real bandwidth in seconds. It tries to update the bandwidth only when disk is fully utilized. Any inactive period of more than one second will be skipped. The estimated bandwidth will be reflecting how fast the device can writeout when _fully utilized_, and won't drop to 0 when it goes idle. The value will remain constant at disk idle time. At busy write time, if not considering fluctuations, it will also remain high unless be knocked down by possible concurrent reads that compete for the disk time and bandwidth with async writes. The estimation is not done purely in the flusher because there is no guarantee for write_cache_pages() to return timely to update bandwidth. The bdi->avg_write_bandwidth smoothing is very effective for filtering out sudden spikes, however may be a little biased in long term. The overheads are low because the bdi bandwidth update only occurs at 200ms intervals. The 200ms update interval is suitable, because it's not possible to get the real bandwidth for the instance at all, due to large fluctuations. The NFS commits can be as large as seconds worth of data. One XFS completion may be as large as half second worth of data if we are going to increase the write chunk to half second worth of data. In ext4, fluctuations with time period of around 5 seconds is observed. And there is another pattern of irregular periods of up to 20 seconds on SSD tests. That's why we are not only doing the estimation at 200ms intervals, but also averaging them over a period of 3 seconds and then go further to do another level of smoothing in avg_write_bandwidth. CC: Li Shaohua <shaohua.li@intel.com> CC: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Diffstat (limited to 'mm/page-writeback.c')
-rw-r--r--mm/page-writeback.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 8cd71376c63..446bdf7b975 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -37,6 +37,11 @@
37#include <trace/events/writeback.h> 37#include <trace/events/writeback.h>
38 38
39/* 39/*
40 * Estimate write bandwidth at 200ms intervals.
41 */
42#define BANDWIDTH_INTERVAL max(HZ/5, 1)
43
44/*
40 * After a CPU has dirtied this many pages, balance_dirty_pages_ratelimited 45 * After a CPU has dirtied this many pages, balance_dirty_pages_ratelimited
41 * will look to see if it needs to force writeback or throttling. 46 * will look to see if it needs to force writeback or throttling.
42 */ 47 */
@@ -471,6 +476,85 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
471 return bdi_dirty; 476 return bdi_dirty;
472} 477}
473 478
479static void bdi_update_write_bandwidth(struct backing_dev_info *bdi,
480 unsigned long elapsed,
481 unsigned long written)
482{
483 const unsigned long period = roundup_pow_of_two(3 * HZ);
484 unsigned long avg = bdi->avg_write_bandwidth;
485 unsigned long old = bdi->write_bandwidth;
486 u64 bw;
487
488 /*
489 * bw = written * HZ / elapsed
490 *
491 * bw * elapsed + write_bandwidth * (period - elapsed)
492 * write_bandwidth = ---------------------------------------------------
493 * period
494 */
495 bw = written - bdi->written_stamp;
496 bw *= HZ;
497 if (unlikely(elapsed > period)) {
498 do_div(bw, elapsed);
499 avg = bw;
500 goto out;
501 }
502 bw += (u64)bdi->write_bandwidth * (period - elapsed);
503 bw >>= ilog2(period);
504
505 /*
506 * one more level of smoothing, for filtering out sudden spikes
507 */
508 if (avg > old && old >= (unsigned long)bw)
509 avg -= (avg - old) >> 3;
510
511 if (avg < old && old <= (unsigned long)bw)
512 avg += (old - avg) >> 3;
513
514out:
515 bdi->write_bandwidth = bw;
516 bdi->avg_write_bandwidth = avg;
517}
518
519void __bdi_update_bandwidth(struct backing_dev_info *bdi,
520 unsigned long start_time)
521{
522 unsigned long now = jiffies;
523 unsigned long elapsed = now - bdi->bw_time_stamp;
524 unsigned long written;
525
526 /*
527 * rate-limit, only update once every 200ms.
528 */
529 if (elapsed < BANDWIDTH_INTERVAL)
530 return;
531
532 written = percpu_counter_read(&bdi->bdi_stat[BDI_WRITTEN]);
533
534 /*
535 * Skip quiet periods when disk bandwidth is under-utilized.
536 * (at least 1s idle time between two flusher runs)
537 */
538 if (elapsed > HZ && time_before(bdi->bw_time_stamp, start_time))
539 goto snapshot;
540
541 bdi_update_write_bandwidth(bdi, elapsed, written);
542
543snapshot:
544 bdi->written_stamp = written;
545 bdi->bw_time_stamp = now;
546}
547
548static void bdi_update_bandwidth(struct backing_dev_info *bdi,
549 unsigned long start_time)
550{
551 if (time_is_after_eq_jiffies(bdi->bw_time_stamp + BANDWIDTH_INTERVAL))
552 return;
553 spin_lock(&bdi->wb.list_lock);
554 __bdi_update_bandwidth(bdi, start_time);
555 spin_unlock(&bdi->wb.list_lock);
556}
557
474/* 558/*
475 * balance_dirty_pages() must be called by processes which are generating dirty 559 * balance_dirty_pages() must be called by processes which are generating dirty
476 * data. It looks at the number of dirty pages in the machine and will force 560 * data. It looks at the number of dirty pages in the machine and will force
@@ -490,6 +574,7 @@ static void balance_dirty_pages(struct address_space *mapping,
490 unsigned long pause = 1; 574 unsigned long pause = 1;
491 bool dirty_exceeded = false; 575 bool dirty_exceeded = false;
492 struct backing_dev_info *bdi = mapping->backing_dev_info; 576 struct backing_dev_info *bdi = mapping->backing_dev_info;
577 unsigned long start_time = jiffies;
493 578
494 for (;;) { 579 for (;;) {
495 nr_reclaimable = global_page_state(NR_FILE_DIRTY) + 580 nr_reclaimable = global_page_state(NR_FILE_DIRTY) +
@@ -544,6 +629,8 @@ static void balance_dirty_pages(struct address_space *mapping,
544 if (!bdi->dirty_exceeded) 629 if (!bdi->dirty_exceeded)
545 bdi->dirty_exceeded = 1; 630 bdi->dirty_exceeded = 1;
546 631
632 bdi_update_bandwidth(bdi, start_time);
633
547 /* Note: nr_reclaimable denotes nr_dirty + nr_unstable. 634 /* Note: nr_reclaimable denotes nr_dirty + nr_unstable.
548 * Unstable writes are a feature of certain networked 635 * Unstable writes are a feature of certain networked
549 * filesystems (i.e. NFS) in which data may have been 636 * filesystems (i.e. NFS) in which data may have been