Subject: writeback: limit max dirty pause time Date: Sat Jun 11 19:21:43 CST 2011 Apply two policies to scale down the max pause time for 1) small number of concurrent dirtiers 2) small memory system (comparing to storage bandwidth) MAX_PAUSE=200ms may only be suitable for high end servers with lots of concurrent dirtiers, where the large pause time can reduce much overheads. Otherwise, smaller pause time is desirable whenever possible, so as to get good responsiveness and smooth user experiences. It's actually required for good disk utilization in the case when all the dirty pages can be synced to disk within MAX_PAUSE=200ms. Signed-off-by: Wu Fengguang --- mm/page-writeback.c | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) --- linux-next.orig/mm/page-writeback.c 2011-08-07 14:23:45.000000000 +0800 +++ linux-next/mm/page-writeback.c 2011-08-07 14:25:29.000000000 +0800 @@ -856,6 +856,42 @@ static unsigned long ratelimit_pages(uns return 1; } +static unsigned long bdi_max_pause(struct backing_dev_info *bdi, + unsigned long bdi_dirty) +{ + unsigned long hi = ilog2(bdi->write_bandwidth); + unsigned long lo = ilog2(bdi->dirty_ratelimit); + unsigned long t; + + /* target for ~10ms pause on 1-dd case */ + t = HZ / 50; + + /* + * Scale up pause time for concurrent dirtiers in order to reduce CPU + * overheads. + * + * (N * 20ms) on 2^N concurrent tasks. + */ + if (hi > lo) + t += (hi - lo) * (20 * HZ) / 1024; + + /* + * Limit pause time for small memory systems. If sleeping for too long + * time, a small pool of dirty/writeback pages may go empty and disk go + * idle. + * + * 1ms for every 1MB; may further consider bdi bandwidth. + */ + if (bdi_dirty) + t = min(t, bdi_dirty >> (30 - PAGE_CACHE_SHIFT - ilog2(HZ))); + + /* + * The pause time will be settled within range (max_pause/4, max_pause). + * Apply a minimal value of 4 to get a non-zero max_pause/4. + */ + return clamp_val(t, 4, MAX_PAUSE); +} + /* * balance_dirty_pages() must be called by processes which are generating dirty * data. It looks at the number of dirty pages in the machine and will force @@ -873,6 +909,7 @@ static void balance_dirty_pages(struct a unsigned long dirty_thresh; unsigned long bdi_thresh; long pause = 0; + long max_pause; bool dirty_exceeded = false; unsigned long bw; unsigned long base_bw; @@ -930,16 +967,18 @@ static void balance_dirty_pages(struct a if (unlikely(!writeback_in_progress(bdi))) bdi_start_background_writeback(bdi); + max_pause = bdi_max_pause(bdi, bdi_dirty); + base_bw = bdi->dirty_ratelimit; bw = bdi_position_ratio(bdi, dirty_thresh, nr_dirty, bdi_thresh, bdi_dirty); if (unlikely(bw == 0)) { - pause = MAX_PAUSE; + pause = max_pause; goto pause; } bw = (u64)base_bw * bw >> BANDWIDTH_CALC_SHIFT; pause = (HZ * pages_dirtied + bw / 2) / (bw | 1); - pause = min(pause, MAX_PAUSE); + pause = min(pause, max_pause); pause: trace_balance_dirty_pages(bdi,