linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>, Wu Fengguang <fengguang.wu@intel.com>,
	Christoph Hellwig <hch@lst.de>,
	Trond Myklebust <Trond.Myklebust@netapp.com>,
	Dave Chinner <david@fromorbit.com>, Theodore Ts'o <tytso@mit.edu>,
	Chris Mason <chris.mason@oracle.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Mel Gorman <mel@csn.ul.ie>, Rik van Riel <riel@redhat.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Greg Thelen <gthelen@google.com>,
	Minchan Kim <minchan.kim@gmail.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	Andrea Righi <arighi@develer.com>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	linux-mm <linux-mm@kvack.org>,
	linux-fsdevel@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 05/12] writeback: smoothed dirty threshold and limit
Date: Sat, 16 Apr 2011 21:25:51 +0800	[thread overview]
Message-ID: <20110416134333.047784214@intel.com> (raw)
In-Reply-To: 20110416132546.765212221@intel.com

[-- Attachment #1: writeback-dirty-thresh-limit.patch --]
[-- Type: text/plain, Size: 5671 bytes --]

Both the global/bdi dirty thresholds may fluctuate undesirably.

- the start of a heavy weight application (ie. KVM) may instantly knock
  down determine_dirtyable_memory() and hence the global/bdi dirty thresholds.

- in JBOD setup, the bdi dirty thresholds are observed to fluctuate more

So maintain a version of smoothed bdi dirty threshold in
bdi->dirty_threshold and introduce the global dirty limit in
default_backing_dev_info.dirty_threshold.

The global limit can effectively mask out the impact of sudden drop of
dirtyable memory.  Without it, the dirtier tasks may be blocked in the
block area for 10s after someone eats 500MB memory; with the limit, the
dirtier tasks will be throttled at eg. 1/8 => 1/4 => 1/2 => original
dirty bandwith by the main control line and bring down the dirty pages
at reasonable speeds.

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 include/linux/backing-dev.h |    2 +
 include/linux/writeback.h   |   38 ++++++++++++++++++++++++++++
 mm/backing-dev.c            |    1 
 mm/page-writeback.c         |   45 ++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)

--- linux-next.orig/include/linux/writeback.h	2011-04-16 17:53:50.000000000 +0800
+++ linux-next/include/linux/writeback.h	2011-04-16 17:54:02.000000000 +0800
@@ -12,6 +12,44 @@ struct backing_dev_info;
 extern spinlock_t inode_wb_list_lock;
 
 /*
+ * 4MB minimal write chunk size
+ */
+#define MIN_WRITEBACK_PAGES	(4096UL >> (PAGE_CACHE_SHIFT - 10))
+
+/*
+ * The 1/4 region under the global dirty thresh is for smooth dirty throttling:
+ *
+ *		(thresh - thresh/DIRTY_FULL_SCOPE, thresh)
+ *
+ * The 1/8 region under the global dirty limit will be more rigidly throttled:
+ *
+ *		(limit - limit/DIRTY_BRAKE, limit)
+ *
+ * The 1/16 region above the global dirty limit will be put to maximum pauses:
+ *
+ *		(limit, limit + limit/DIRTY_MAXPAUSE)
+ *
+ * The 1/16 region above the max-pause region, dirty exceeded bdi's will be put
+ * to loops:
+ *
+ *		(limit + limit/DIRTY_MAXPAUSE, limit + limit/DIRTY_PASSGOOD)
+ *
+ * Further beyond, all dirtier tasks will enter a loop waiting (possibly long
+ * time) for the dirty pages to drop.
+ *
+ * The global dirty threshold is normally at the low bound of the brake region,
+ * except when the system suddenly allocates a lot of anonymous memory and
+ * knocks down the global dirty threshold quickly, in which case the global
+ * dirty limit will follow down slowly to prevent livelocking all dirtier tasks.
+ */
+#define DIRTY_RAMPUP		32
+#define DIRTY_SCOPE		8
+#define DIRTY_FULL_SCOPE	(DIRTY_SCOPE / 2)
+#define DIRTY_BRAKE		8
+#define DIRTY_MAXPAUSE		16
+#define DIRTY_PASSGOOD		8
+
+/*
  * fs/fs-writeback.c
  */
 enum writeback_sync_modes {
--- linux-next.orig/mm/page-writeback.c	2011-04-16 17:54:01.000000000 +0800
+++ linux-next/mm/page-writeback.c	2011-04-16 17:54:02.000000000 +0800
@@ -562,6 +562,49 @@ static void __bdi_update_write_bandwidth
 	bdi->avg_write_bandwidth = avg;
 }
 
+static void update_dirty_limit(unsigned long thresh,
+			       unsigned long dirty)
+{
+	unsigned long limit = default_backing_dev_info.dirty_threshold;
+	unsigned long min = dirty + limit / DIRTY_BRAKE;
+
+	thresh += thresh / DIRTY_BRAKE;
+
+	if (limit < thresh) {
+		limit = thresh;
+		goto update;
+	}
+
+	/* take care not to follow into the brake area */
+	if (limit > thresh &&
+	    limit > min) {
+		limit -= (limit - max(thresh, min)) >> 5;
+		goto update;
+	}
+	return;
+update:
+	default_backing_dev_info.dirty_threshold = limit;
+}
+
+static void bdi_update_dirty_threshold(struct backing_dev_info *bdi,
+				       unsigned long thresh,
+				       unsigned long dirty)
+{
+	unsigned long old = bdi->old_dirty_threshold;
+	unsigned long avg = bdi->dirty_threshold;
+
+	thresh = bdi_dirty_limit(bdi, thresh);
+
+	if (avg > old && old >= thresh)
+		avg -= (avg - old) >> 3;
+
+	if (avg < old && old <= thresh)
+		avg += (old - avg) >> 3;
+
+	bdi->dirty_threshold = avg;
+	bdi->old_dirty_threshold = thresh;
+}
+
 void bdi_update_bandwidth(struct backing_dev_info *bdi,
 			  unsigned long thresh,
 			  unsigned long dirty,
@@ -595,10 +638,12 @@ void bdi_update_bandwidth(struct backing
 
 	if (thresh &&
 	    now - default_backing_dev_info.bw_time_stamp >= HZ / 5) {
+		update_dirty_limit(thresh, dirty);
 		bdi_update_dirty_smooth(&default_backing_dev_info, dirty);
 		default_backing_dev_info.bw_time_stamp = now;
 	}
 	if (thresh) {
+		bdi_update_dirty_threshold(bdi, thresh, dirty);
 		bdi_update_dirty_smooth(bdi, bdi_dirty);
 	}
 	__bdi_update_write_bandwidth(bdi, elapsed, written);
--- linux-next.orig/include/linux/backing-dev.h	2011-04-16 17:54:01.000000000 +0800
+++ linux-next/include/linux/backing-dev.h	2011-04-16 17:54:02.000000000 +0800
@@ -79,6 +79,8 @@ struct backing_dev_info {
 	unsigned long avg_write_bandwidth;
 	unsigned long avg_dirty;
 	unsigned long old_dirty;
+	unsigned long dirty_threshold;
+	unsigned long old_dirty_threshold;
 
 	struct prop_local_percpu completions;
 	int dirty_exceeded;
--- linux-next.orig/mm/backing-dev.c	2011-04-16 17:54:01.000000000 +0800
+++ linux-next/mm/backing-dev.c	2011-04-16 17:54:02.000000000 +0800
@@ -671,6 +671,7 @@ int bdi_init(struct backing_dev_info *bd
 
 	bdi->avg_dirty = 0;
 	bdi->old_dirty = 0;
+	bdi->dirty_threshold = MIN_WRITEBACK_PAGES;
 
 	err = prop_local_init_percpu(&bdi->completions);
 


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2011-04-16 14:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-16 13:25 [PATCH 00/12] IO-less dirty throttling v7 Wu Fengguang
2011-04-16 13:25 ` [PATCH 01/12] writeback: account per-bdi accumulated written pages Wu Fengguang
2011-04-16 13:25 ` [PATCH 02/12] writeback: account per-bdi accumulated dirtied pages Wu Fengguang
2011-04-16 13:25 ` [PATCH 03/12] writeback: bdi write bandwidth estimation Wu Fengguang
2011-04-16 13:25 ` [PATCH 04/12] writeback: smoothed global/bdi dirty pages Wu Fengguang
2011-04-16 13:25 ` Wu Fengguang [this message]
2011-04-16 13:25 ` [PATCH 06/12] writeback: enforce 1/4 gap between the dirty/background thresholds Wu Fengguang
2011-04-16 13:25 ` [PATCH 07/12] writeback: base throttle bandwidth and position ratio Wu Fengguang
2011-04-16 13:25 ` [PATCH 08/12] writeback: IO-less balance_dirty_pages() Wu Fengguang
2011-04-16 13:25 ` [PATCH 09/12] writeback: show bdi write bandwidth in debugfs Wu Fengguang
2011-04-16 13:25 ` [PATCH 10/12] writeback: trace dirty_ratelimit Wu Fengguang
2011-04-16 13:25 ` [PATCH 11/12] writeback: trace balance_dirty_pages Wu Fengguang
2011-04-16 13:25 ` [PATCH 12/12] writeback: trace global_dirty_state Wu Fengguang
2011-04-16 16:27 ` [PATCH 00/12] IO-less dirty throttling v7 Sedat Dilek
2011-04-17  1:44   ` Wu Fengguang
2011-04-17  3:18     ` Sedat Dilek
2011-04-17  4:10       ` Wu Fengguang
2011-04-17  4:46         ` Sedat Dilek
2011-04-17  6:46           ` Sedat Dilek
2011-04-18  0:13         ` Wu Fengguang
2011-04-18  6:57           ` Sedat Dilek
2011-04-18  8:18             ` Wu Fengguang
2011-04-18 10:22               ` Sedat Dilek
2011-04-17  7:31 ` Marco Stornelli
2011-04-17  9:30   ` Wu Fengguang
2011-04-17 17:44     ` Marco Stornelli
2011-04-17 23:31       ` Wu Fengguang
2011-04-26 17:19 ` Vivek Goyal
2011-04-28 14:27   ` Wu Fengguang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110416134333.047784214@intel.com \
    --to=fengguang.wu@intel.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=arighi@develer.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=chris.mason@oracle.com \
    --cc=david@fromorbit.com \
    --cc=gthelen@google.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=minchan.kim@gmail.com \
    --cc=riel@redhat.com \
    --cc=tytso@mit.edu \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).