Skip to contentSkip to conversation

IO-less balance_dirty_pages() v2 (simple approach)

RFC PATCH In review Jan Kara 6 participants 40 messages Mar 8, 2011 – Mar 29, 2011

Subsystems (5)
lore
Share & tools
lore

Jan Kara

author maintainer
#0 lore raw

cover IO-less balance_dirty_pages() v2 (simple approach)

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control. Fengguang is currently running some tests on my patches so that we can compare the approaches.

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

Since last version I've implemented cleanups as suggested by Peter Zilstra. The patches undergone more throughout testing. So far I've tested different filesystems (ext2, ext3, ext4, xfs, nfs), also a combination of a local filesystem and nfs. The load was either various number of dd threads or fio with several threads each dirtying pages at different speed.

Results and test scripts can be found at
http://beta.suse.com/private/jack/balance_dirty_pages-v2/
See README file for some explanation of test framework, tests, and graphs. Except for ext3 in data=ordered mode, where kjournald creates high fluctuations in waiting time of throttled processes (and also high latencies), the results look OK. Parallel dd threads are being throttled in the same way (in a 2s window threads spend the same time waiting) and also latencies of individual waits seem OK - except for ext3 they fit in 100 ms for local filesystems. They are in 200-500 ms range for NFS, which isn't that nice but to fix that we'd have to modify current ratelimiting scheme to take into account on which bdi a page is dirtied. Then we could ratelimit slower BDIs more often thus reducing latencies in individual waits...

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

I'm planning to run some tests with multiple SATA drives to verify whether there aren't some unexpected fluctuations. But currently I have some trouble with the HW...

As usual comments are welcome :).

Honza

author maintainer
#1 lore raw

PATCH 1/5 writeback: account per-bdi accumulated written pages

Introduce the BDI_WRITTEN counter. It will be used for waking up waiters in balance_dirty_pages().

Peter Zijlstra <[email protected]>:
Move BDI_WRITTEN accounting into __bdi_writeout_inc(). This will cover and fix fuse, which only calls bdi_writeout_inc().

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 include/linux/backing-dev.h |    1 +
 mm/backing-dev.c            |    6 ++++--
 mm/page-writeback.c         |    1 +
 3 files changed, 6 insertions(+), 2 deletions(-)
include/linux/backing-dev.h +1 -0
index 4ce34fa..63ab4a5 100644
@@ -40,6 +40,7 @@ typedef int (congested_fn)(void *, int);
 enum bdi_stat_item {
 	BDI_RECLAIMABLE,
 	BDI_WRITEBACK,
+	BDI_WRITTEN,
 	NR_BDI_STAT_ITEMS
 };
 
mm/backing-dev.c +4 -2
index 027100d..4d14072 100644
@@ -92,6 +92,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   "BdiDirtyThresh:   %8lu kB\n"
 		   "DirtyThresh:      %8lu kB\n"
 		   "BackgroundThresh: %8lu kB\n"
+		   "BdiWritten:       %8lu kB\n"
 		   "b_dirty:          %8lu\n"
 		   "b_io:             %8lu\n"
 		   "b_more_io:        %8lu\n"
@@ -99,8 +100,9 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 		   "state:            %8lx\n",
 		   (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
 		   (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)),
-		   K(bdi_thresh), K(dirty_thresh),
-		   K(background_thresh), nr_dirty, nr_io, nr_more_io,
+		   K(bdi_thresh), K(dirty_thresh), K(background_thresh),
+		   (unsigned long) K(bdi_stat(bdi, BDI_WRITTEN)),
+		   nr_dirty, nr_io, nr_more_io,
 		   !list_empty(&bdi->bdi_list), bdi->state);
 #undef K
 
mm/page-writeback.c +1 -0
index 2cb01f6..c472c1c 100644
@@ -219,6 +219,7 @@ int dirty_bytes_handler(struct ctl_table *table, int write,
  */
 static inline void __bdi_writeout_inc(struct backing_dev_info *bdi)
 {
+	__inc_bdi_stat(bdi, BDI_WRITTEN);
 	__prop_inc_percpu_max(&vm_completions, &bdi->completions,
 			      bdi->max_prop_frac);
 }
Signature · 1 line
1.7.1
author maintainer
#2 lore raw

PATCH 2/5 mm: Properly reflect task dirty limits in dirty_exceeded logic

In reply to Jan Kara

We set bdi->dirty_exceeded (and thus ratelimiting code starts to call balance_dirty_pages() every 8 pages) when a per-bdi limit is exceeded or global limit is exceeded. But per-bdi limit also depends on the task. Thus different tasks reach the limit on that bdi at different levels of dirty pages. The result is that with current code bdi->dirty_exceeded ping-ponged between 1 and 0 depending on which task just got into balance_dirty_pages().

We fix the issue by clearing bdi->dirty_exceeded only when per-bdi amount of dirty pages drops below the threshold (7/8 * bdi_dirty_limit) where task limits already do not have any influence.

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 mm/page-writeback.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
mm/page-writeback.c +16 -2
index c472c1c..f388f70 100644
@@ -275,12 +275,13 @@ static inline void task_dirties_fraction(struct task_struct *tsk,
  * effectively curb the growth of dirty pages. Light dirtiers with high enough
  * dirty threshold may never get throttled.
  */
+#define TASK_LIMIT_FRACTION 8
 static unsigned long task_dirty_limit(struct task_struct *tsk,
 				       unsigned long bdi_dirty)
 {
 	long numerator, denominator;
 	unsigned long dirty = bdi_dirty;
-	u64 inv = dirty >> 3;
+	u64 inv = dirty / TASK_LIMIT_FRACTION;
 
 	task_dirties_fraction(tsk, &numerator, &denominator);
 	inv *= numerator;
@@ -291,6 +292,12 @@ static unsigned long task_dirty_limit(struct task_struct *tsk,
 	return max(dirty, bdi_dirty/2);
 }
 
+/* Minimum limit for any task */
+static unsigned long task_min_dirty_limit(unsigned long bdi_dirty)
+{
+	return bdi_dirty - bdi_dirty / TASK_LIMIT_FRACTION;
+}
+
 /*
  *
  */
@@ -484,9 +491,11 @@ static void balance_dirty_pages(struct address_space *mapping,
 	unsigned long background_thresh;
 	unsigned long dirty_thresh;
 	unsigned long bdi_thresh;
+	unsigned long min_bdi_thresh = ULONG_MAX;
 	unsigned long pages_written = 0;
 	unsigned long pause = 1;
 	bool dirty_exceeded = false;
+	bool min_dirty_exceeded = false;
 	struct backing_dev_info *bdi = mapping->backing_dev_info;
 
 	for (;;) {
@@ -513,6 +522,7 @@ static void balance_dirty_pages(struct address_space *mapping,
 			break;
 
 		bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
+		min_bdi_thresh = task_min_dirty_limit(bdi_thresh);
 		bdi_thresh = task_dirty_limit(current, bdi_thresh);
 
 		/*
@@ -542,6 +552,9 @@ static void balance_dirty_pages(struct address_space *mapping,
 		dirty_exceeded =
 			(bdi_nr_reclaimable + bdi_nr_writeback > bdi_thresh)
 			|| (nr_reclaimable + nr_writeback > dirty_thresh);
+		min_dirty_exceeded =
+			(bdi_nr_reclaimable + bdi_nr_writeback > min_bdi_thresh)
+			|| (nr_reclaimable + nr_writeback > dirty_thresh);
 
 		if (!dirty_exceeded)
 			break;
@@ -579,7 +592,8 @@ static void balance_dirty_pages(struct address_space *mapping,
 			pause = HZ / 10;
 	}
 
-	if (!dirty_exceeded && bdi->dirty_exceeded)
+	/* Clear dirty_exceeded flag only when no task can exceed the limit */
+	if (!min_dirty_exceeded && bdi->dirty_exceeded)
 		bdi->dirty_exceeded = 0;
 
 	if (writeback_in_progress(bdi))
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 2/5] mm: Properly reflect task dirty limits in dirty_exceeded logic

Quoted 42 lines · Jan Kara

We set bdi->dirty_exceeded (and thus ratelimiting code starts to call balance_dirty_pages() every 8 pages) when a per-bdi limit is exceeded or global limit is exceeded. But per-bdi limit also depends on the task. Thus different tasks reach the limit on that bdi at different levels of dirty pages. The result is that with current code bdi->dirty_exceeded ping-ponged between 1 and 0 depending on which task just got into balance_dirty_pages().

We fix the issue by clearing bdi->dirty_exceeded only when per-bdi amount of dirty pages drops below the threshold (7/8 * bdi_dirty_limit) where task limits already do not have any influence.

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 mm/page-writeback.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
mm/page-writeback.c +2 -1
index c472c1c..f388f70 100644
@@ -275,12 +275,13 @@ static inline void task_dirties_fraction(struct task_struct *tsk,
  * effectively curb the growth of dirty pages. Light dirtiers with high enough
  * dirty threshold may never get throttled.
  */
+#define TASK_LIMIT_FRACTION 8
 static unsigned long task_dirty_limit(struct task_struct *tsk,
 				       unsigned long bdi_dirty)
 {
 	long numerator, denominator;
 	unsigned long dirty = bdi_dirty;
-	u64 inv = dirty >> 3;
+	u64 inv = dirty / TASK_LIMIT_FRACTION;
 
 	task_dirties_fraction(tsk, &numerator, &denominator);
 	inv *= numerator;

mm/page-writeback.c static unsigned long task_dirty_limit(struct task_struct *tsk, · line 300

Quoted 9 lines
mm/page-writeback.c +6 -0
@@ -291,6 +292,12 @@ static unsigned long task_dirty_limit(struct task_struct *tsk,
 	return max(dirty, bdi_dirty/2);
 }
 
+/* Minimum limit for any task */
+static unsigned long task_min_dirty_limit(unsigned long bdi_dirty)
+{
+	return bdi_dirty - bdi_dirty / TASK_LIMIT_FRACTION;
+}
+

Hi Jan,

Should the above be called bdi_min_dirty_limit()? In essense we seem to be setting bdi->bdi_exceeded when dirty pages on bdi cross bdi_thresh and clear it when dirty pages on bdi are below 7/8*bdi_thresh. So there does not seem to be any dependency on task dirty limit here hence string "task" sounds confusing to me. In fact, would bdi_dirty_exceeded_clear_thresh() be a better name?

Quoted 16 lines
mm/page-writeback.c +2 -0
 /*
  *
  */
@@ -484,9 +491,11 @@ static void balance_dirty_pages(struct address_space *mapping,
 	unsigned long background_thresh;
 	unsigned long dirty_thresh;
 	unsigned long bdi_thresh;
+	unsigned long min_bdi_thresh = ULONG_MAX;
 	unsigned long pages_written = 0;
 	unsigned long pause = 1;
 	bool dirty_exceeded = false;
+	bool min_dirty_exceeded = false;
 	struct backing_dev_info *bdi = mapping->backing_dev_info;
 
 	for (;;) {

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 526

Quoted 5 lines
mm/page-writeback.c +1 -0
@@ -513,6 +522,7 @@ static void balance_dirty_pages(struct address_space *mapping,
 			break;
 
 		bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
+		min_bdi_thresh = task_min_dirty_limit(bdi_thresh);
 		bdi_thresh = task_dirty_limit(current, bdi_thresh);
                ^^^^^

This patch aside, we use bdi_thresh name both for bdi threshold as well as per task per bdi threshold. will task_bdi_thresh be a better name here.

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 557

Quoted 9 lines
mm/page-writeback.c +3 -0
 		/*
@@ -542,6 +552,9 @@ static void balance_dirty_pages(struct address_space *mapping,
 		dirty_exceeded =
 			(bdi_nr_reclaimable + bdi_nr_writeback > bdi_thresh)
 			|| (nr_reclaimable + nr_writeback > dirty_thresh);
+		min_dirty_exceeded =
+			(bdi_nr_reclaimable + bdi_nr_writeback > min_bdi_thresh)
+			|| (nr_reclaimable + nr_writeback > dirty_thresh);

Would following be easier to understand.

		clear_dirty_exceeded =
			(bdi_nr_reclaimable + bdi_nr_writeback <
				dirty_exceeded_reset_thresh)
			&& (nr_reclaimable + nr_writeback < dirty_thresh);

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 597

Quoted 11 lines
mm/page-writeback.c +2 -1
 		if (!dirty_exceeded)
 			break;
@@ -579,7 +592,8 @@ static void balance_dirty_pages(struct address_space *mapping,
 			pause = HZ / 10;
 	}
 
-	if (!dirty_exceeded && bdi->dirty_exceeded)
+	/* Clear dirty_exceeded flag only when no task can exceed the limit */
+	if (!min_dirty_exceeded && bdi->dirty_exceeded)
 		bdi->dirty_exceeded = 0;

similiarly...

	if (bdi->dirty_exceeded && clear_dirty_exceeded)
		bdi->dirty_exceeded = 0;

I was confused with the term min_dirty_limit and task_min_dirty_limit() for sometime as patch said that we are trying to move away from dependence on task specific bdi_thres for clearing bdi->bdi_thresh. May be it is just me...

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#4 lore raw

Re: [PATCH 2/5] mm: Properly reflect task dirty limits in dirty_exceeded logic

Quoted 5 lines · Vivek Goyal
Quoted 4 lines · Jan Kara
mm/page-writeback.c +0 -0
@@ -291,6 +292,12 @@ static unsigned long task_dirty_limit(struct task_struct *tsk,
 	return max(dirty, bdi_dirty/2);
 }
 
Quoted 12 lines

mm/page-writeback.c static unsigned long task_dirty_limit(struct task_struct *tsk, · line 300

Quoted 6 lines
mm/page-writeback.c +6 -0
+/* Minimum limit for any task */
+static unsigned long task_min_dirty_limit(unsigned long bdi_dirty)
+{
+	return bdi_dirty - bdi_dirty / TASK_LIMIT_FRACTION;
+}
+

Should the above be called bdi_min_dirty_limit()? In essense we seem to be setting bdi->bdi_exceeded when dirty pages on bdi cross bdi_thresh and clear it when dirty pages on bdi are below 7/8*bdi_thresh. So there does not seem to be any dependency on task dirty limit here hence string "task" sounds confusing to me. In fact, would bdi_dirty_exceeded_clear_thresh() be a better name?

See below...

Quoted 18 lines
Quoted 18 lines
mm/page-writeback.c +2 -0
 /*
  *
  */
@@ -484,9 +491,11 @@ static void balance_dirty_pages(struct address_space *mapping,
 	unsigned long background_thresh;
 	unsigned long dirty_thresh;
 	unsigned long bdi_thresh;
+	unsigned long min_bdi_thresh = ULONG_MAX;
 	unsigned long pages_written = 0;
 	unsigned long pause = 1;
 	bool dirty_exceeded = false;
+	bool min_dirty_exceeded = false;
 	struct backing_dev_info *bdi = mapping->backing_dev_info;
 
 	for (;;) {
@@ -513,6 +522,7 @@ static void balance_dirty_pages(struct address_space *mapping,
 			break;
 
Quoted 7 lines

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 526

Quoted 3 lines
mm/page-writeback.c +1 -0
 		bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
+		min_bdi_thresh = task_min_dirty_limit(bdi_thresh);
 		bdi_thresh = task_dirty_limit(current, bdi_thresh);
                ^^^^^

This patch aside, we use bdi_thresh name both for bdi threshold as well as per task per bdi threshold. will task_bdi_thresh be a better name here.

I agree that the naming is a bit confusing altough it is traditional :).
The renaming to task_bdi_thresh makes sense to me. Then we could name the limit when we clear dirty_exceeded as: min_task_bdi_thresh(). The task in the name tries to say that this is a limit for "any task" so I'd like to keep it there. What do you think?

Quoted 10 lines

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 557

Quoted 7 lines
mm/page-writeback.c +3 -0
@@ -542,6 +552,9 @@ static void balance_dirty_pages(struct address_space *mapping,
 		dirty_exceeded =
 			(bdi_nr_reclaimable + bdi_nr_writeback > bdi_thresh)
 			|| (nr_reclaimable + nr_writeback > dirty_thresh);
+		min_dirty_exceeded =
+			(bdi_nr_reclaimable + bdi_nr_writeback > min_bdi_thresh)
+			|| (nr_reclaimable + nr_writeback > dirty_thresh);

Would following be easier to understand.

Quoted 4 lines
		clear_dirty_exceeded =
			(bdi_nr_reclaimable + bdi_nr_writeback <
				dirty_exceeded_reset_thresh)
			&& (nr_reclaimable + nr_writeback < dirty_thresh);

Yes, this looks better. I'll change it.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

Re: [PATCH 2/5] mm: Properly reflect task dirty limits in dirty_exceeded logic

Quoted 45 lines · Jan Kara
Quoted 5 lines · Vivek Goyal
Quoted 4 lines · Jan Kara
mm/page-writeback.c +0 -0
@@ -291,6 +292,12 @@ static unsigned long task_dirty_limit(struct task_struct *tsk,
 	return max(dirty, bdi_dirty/2);
 }
 
Quoted 12 lines

mm/page-writeback.c static unsigned long task_dirty_limit(struct task_struct *tsk, · line 300

Quoted 6 lines
mm/page-writeback.c +6 -0
+/* Minimum limit for any task */
+static unsigned long task_min_dirty_limit(unsigned long bdi_dirty)
+{
+	return bdi_dirty - bdi_dirty / TASK_LIMIT_FRACTION;
+}
+

Should the above be called bdi_min_dirty_limit()? In essense we seem to be setting bdi->bdi_exceeded when dirty pages on bdi cross bdi_thresh and clear it when dirty pages on bdi are below 7/8*bdi_thresh. So there does not seem to be any dependency on task dirty limit here hence string "task" sounds confusing to me. In fact, would bdi_dirty_exceeded_clear_thresh() be a better name?

See below...

Quoted 18 lines
Quoted 18 lines
mm/page-writeback.c +2 -0
 /*
  *
  */
@@ -484,9 +491,11 @@ static void balance_dirty_pages(struct address_space *mapping,
 	unsigned long background_thresh;
 	unsigned long dirty_thresh;
 	unsigned long bdi_thresh;
+	unsigned long min_bdi_thresh = ULONG_MAX;
 	unsigned long pages_written = 0;
 	unsigned long pause = 1;
 	bool dirty_exceeded = false;
+	bool min_dirty_exceeded = false;
 	struct backing_dev_info *bdi = mapping->backing_dev_info;
 
 	for (;;) {
@@ -513,6 +522,7 @@ static void balance_dirty_pages(struct address_space *mapping,
 			break;
 
Quoted 7 lines

mm/page-writeback.c static void balance_dirty_pages(struct address_space *mapping, · line 526

Quoted 3 lines
mm/page-writeback.c +1 -0
 		bdi_thresh = bdi_dirty_limit(bdi, dirty_thresh);
+		min_bdi_thresh = task_min_dirty_limit(bdi_thresh);
 		bdi_thresh = task_dirty_limit(current, bdi_thresh);
                ^^^^^

This patch aside, we use bdi_thresh name both for bdi threshold as well as per task per bdi threshold. will task_bdi_thresh be a better name here.

Quoted 5 lines

I agree that the naming is a bit confusing altough it is traditional :).
The renaming to task_bdi_thresh makes sense to me. Then we could name the limit when we clear dirty_exceeded as: min_task_bdi_thresh(). The task in the name tries to say that this is a limit for "any task" so I'd like to keep it there. What do you think?

Ok, so for a task, minimum task_bdi_thresh can be
(bdi_dirty - bdi_dirty / TASK_LIMIT_FRACTION).

So min_task_dirty_limit() makes sense. Or if you happen to rename above "bdi_thresh" to "task_bdi_thresh" then "min_task_bdi_thresh()" might be even better. It is up to you depending on context of your later patches.

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#6 lore raw

PATCH 3/5 mm: Implement IO-less balance_dirty_pages()

In reply to Jan Kara

This patch changes balance_dirty_pages() throttling so that the function does not submit writes on its own but rather waits for flusher thread to do enough writes. This has an advantage that we have a single source of IO allowing for better writeback locality. Also we do not have to reenter filesystems from a non-trivial context.

The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, later the interval should be autotuned based on observed IO completion rate), accumulated page IO completions are distributed equally among waiting tasks.

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results. Note that the dependency on the number of waiters is inevitable, since all the waiters compete for a common resource so their number has to be somehow reflected in waiting time.

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 include/linux/backing-dev.h      |    7 +
 include/linux/writeback.h        |    1 +
 include/trace/events/writeback.h |   65 +++++++-
 mm/backing-dev.c                 |    8 +
 mm/page-writeback.c              |  345 +++++++++++++++++++++++++-------------
 5 files changed, 310 insertions(+), 116 deletions(-)
include/linux/backing-dev.h +7 -0
index 63ab4a5..65b6e61 100644
@@ -89,6 +89,13 @@ struct backing_dev_info {
 
 	struct timer_list laptop_mode_wb_timer;
 
+	spinlock_t balance_lock;	/* lock protecting four entries below */
+	unsigned long written_start;	/* BDI_WRITTEN last time we scanned balance_list*/
+	struct list_head balance_list;	/* waiters in balance_dirty_pages */
+	unsigned int balance_waiters;	/* number of waiters in the list */
+	struct delayed_work balance_work;	/* work distributing page
+						   completions among waiters */
+
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debug_dir;
 	struct dentry *debug_stats;
include/linux/writeback.h +1 -0
index 0ead399..901c33f 100644
@@ -129,6 +129,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi,
 			       unsigned long dirty);
 
 void page_writeback_init(void);
+void distribute_page_completions(struct work_struct *work);
 void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
 					unsigned long nr_pages_dirtied);
 
include/trace/events/writeback.h +62 -3

73 lines not on this page · raw message

mm/backing-dev.c +8 -0
index 4d14072..2ecc3fe 100644
@@ -652,6 +652,12 @@ int bdi_init(struct backing_dev_info *bdi)
 	INIT_LIST_HEAD(&bdi->bdi_list);
 	INIT_LIST_HEAD(&bdi->work_list);
 
+	spin_lock_init(&bdi->balance_lock);
+	INIT_LIST_HEAD(&bdi->balance_list);
+	bdi->written_start = 0;
+	bdi->balance_waiters = 0;
+	INIT_DELAYED_WORK(&bdi->balance_work, distribute_page_completions);
+
 	bdi_wb_init(&bdi->wb, bdi);
 
 	for (i = 0; i < NR_BDI_STAT_ITEMS; i++) {
@@ -691,6 +697,8 @@ void bdi_destroy(struct backing_dev_info *bdi)
 		spin_unlock(&inode_lock);
 	}
 
+	cancel_delayed_work_sync(&bdi->balance_work);
+	WARN_ON(!list_empty(&bdi->balance_list));
 	bdi_unregister(bdi);
 
 	for (i = 0; i < NR_BDI_STAT_ITEMS; i++)
mm/page-writeback.c +232 -113

378 lines not on this page · raw message

Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 35 lines · Jan Kara

This patch changes balance_dirty_pages() throttling so that the function does not submit writes on its own but rather waits for flusher thread to do enough writes. This has an advantage that we have a single source of IO allowing for better writeback locality. Also we do not have to reenter filesystems from a non-trivial context.

The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, later the interval should be autotuned based on observed IO completion rate), accumulated page IO completions are distributed equally among waiting tasks.

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results. Note that the dependency on the number of waiters is inevitable, since all the waiters compete for a common resource so their number has to be somehow reflected in waiting time.

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 include/linux/backing-dev.h      |    7 +
 include/linux/writeback.h        |    1 +
 include/trace/events/writeback.h |   65 +++++++-
 mm/backing-dev.c                 |    8 +
 mm/page-writeback.c              |  345 +++++++++++++++++++++++++-------------
 5 files changed, 310 insertions(+), 116 deletions(-)

[..]

Quoted 35 lines
mm/page-writeback.c +28 -5
+/*
+ * 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
+ * the caller to perform writeback if the system is over `vm_dirty_ratio'.
+ * If we're over `background_thresh' then the writeback threads are woken to
+ * perform some writeout.
+ */
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 694

Quoted 10 lines
mm/page-writeback.c +5 -3
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;

Will it make sense to move out bdi_task_limit_exceeded() check in a separate if condition statement as follows. May be this is little easier to read.

	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) {
		if (bdi->dirty_exceeded)
			bdi->dirty_exceeded = 0;

		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
			bdi_start_background_writeback(bdi);

		return;
	}

	if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
	    !bdi_task_limit_exceeded(&st, current))
		return;   

	/* Either task is throttled or we crossed global dirty ratio */
	if (!bdi->dirty_exceeded)
		bdi->dirty_exceeded = 1;

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#8 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 43 lines · Vivek Goyal
Quoted 28 lines
mm/page-writeback.c +21 -5
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 694

Quoted 10 lines
mm/page-writeback.c +5 -3
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;

Will it make sense to move out bdi_task_limit_exceeded() check in a separate if condition statement as follows. May be this is little easier to read.

Quoted 13 lines
	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) {
		if (bdi->dirty_exceeded)
			bdi->dirty_exceeded = 0;

		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
			bdi_start_background_writeback(bdi);

		return;
	}

	if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
	    !bdi_task_limit_exceeded(&st, current))
		return;   

But then we have to start background writeback here as well. Which is
actually a bug in the original patch as well! So clearly your way is more readable :) I'll change it. Thanks.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#9 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 54 lines · Jan Kara
Quoted 53 lines · Vivek Goyal
Quoted 28 lines
mm/page-writeback.c +21 -5
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 694

Quoted 10 lines
mm/page-writeback.c +5 -3
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;

Will it make sense to move out bdi_task_limit_exceeded() check in a separate if condition statement as follows. May be this is little easier to read.

	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) {
		if (bdi->dirty_exceeded)
			bdi->dirty_exceeded = 0;

		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
			bdi_start_background_writeback(bdi);

		return;
	}
Quoted 6 lines
Quoted 3 lines
	if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
	    !bdi_task_limit_exceeded(&st, current))
		return;   

But then we have to start background writeback here as well. Which is
actually a bug in the original patch as well! So clearly your way is more readable :) I'll change it. Thanks.

I was thinking about that starting of bdi writeback here. But I was assuming that if we are here then we most likely have visited above loop of < DIRTY_MAY_EXCEED_LIMIT and started background writeback.

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Hi Jan:

Quoted 58 lines · Vivek Goyal
Quoted 57 lines · Jan Kara
Quoted 56 lines · Vivek Goyal
Quoted 33 lines
mm/page-writeback.c +14 -0
+static void balance_dirty_pages(struct address_space *mapping,
+                         unsigned long write_chunk)
+{
+ struct backing_dev_info *bdi = mapping->backing_dev_info;
+ struct balance_waiter bw;
+ struct dirty_limit_state st;
+ int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+ if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+     (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+      !bdi_task_limit_exceeded(&st, current))) {
+         if (bdi->dirty_exceeded &&
+             dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+                 bdi->dirty_exceeded = 0;

          /*
-          * Increase the delay for each loop, up to our previous
-          * default of taking a 100ms nap.
+          * In laptop mode, we wait until hitting the higher threshold
+          * before starting background writeout, and then write out all
+          * the way down to the lower threshold.  So slow writers cause
+          * minimal disk activity.
+          *
+          * In normal mode, we start background writeout at the lower
+          * background_thresh, to keep the amount of dirty memory low. */
-         pause <<= 1;
-         if (pause > HZ / 10)
-                 pause = HZ / 10;
+         if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+                 bdi_start_background_writeback(bdi);
+         return;
  }

Quoted 5 lines

- /* Clear dirty_exceeded flag only when no task can exceed the limit */
- if (!min_dirty_exceeded && bdi->dirty_exceeded)
-         bdi->dirty_exceeded = 0;
+ if (!bdi->dirty_exceeded)
+         bdi->dirty_exceeded = 1;

Will it make sense to move out bdi_task_limit_exceeded() check in a separate if condition statement as follows. May be this is little easier to read.

    if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) { if (bdi->dirty_exceeded) bdi->dirty_exceeded = 0;

            if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND) bdi_start_background_writeback(bdi);

            return;
    }

    if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT && !bdi_task_limit_exceeded(&st, current)) return;

Quoted 7 lines
Quoted 3 lines

  But then we have to start background writeback here as well. Which is actually a bug in the original patch as well! So clearly your way is more readable :) I'll change it. Thanks.

I was thinking about that starting of bdi writeback here. But I was assuming that if we are here then we most likely have visited above loop of < DIRTY_MAY_EXCEED_LIMIT and started background writeback.

Maybe I'm missing something, but at the point in balance_dirty_pages() where we kick the flusher thread , before we put the current task to sleep, how do you know that background writeback is taking place? Are you simply assuming that in previous calls to balance_dirty_pages(), that background writeback has been started, and is still taking place at the time we need to do throttling?

Thanks,
Curt

Quoted 11 lines

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 69 lines · Curt Wohlgemuth

Hi Jan:

Quoted 58 lines · Vivek Goyal
Quoted 57 lines · Jan Kara
Quoted 56 lines · Vivek Goyal
Quoted 33 lines
mm/page-writeback.c +14 -0
+static void balance_dirty_pages(struct address_space *mapping,
+                         unsigned long write_chunk)
+{
+ struct backing_dev_info *bdi = mapping->backing_dev_info;
+ struct balance_waiter bw;
+ struct dirty_limit_state st;
+ int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+ if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+     (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+      !bdi_task_limit_exceeded(&st, current))) {
+         if (bdi->dirty_exceeded &&
+             dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+                 bdi->dirty_exceeded = 0;

          /*
-          * Increase the delay for each loop, up to our previous
-          * default of taking a 100ms nap.
+          * In laptop mode, we wait until hitting the higher threshold
+          * before starting background writeout, and then write out all
+          * the way down to the lower threshold.  So slow writers cause
+          * minimal disk activity.
+          *
+          * In normal mode, we start background writeout at the lower
+          * background_thresh, to keep the amount of dirty memory low. */
-         pause <<= 1;
-         if (pause > HZ / 10)
-                 pause = HZ / 10;
+         if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+                 bdi_start_background_writeback(bdi);
+         return;
  }

Quoted 5 lines

- /* Clear dirty_exceeded flag only when no task can exceed the limit */
- if (!min_dirty_exceeded && bdi->dirty_exceeded)
-         bdi->dirty_exceeded = 0;
+ if (!bdi->dirty_exceeded)
+         bdi->dirty_exceeded = 1;

Will it make sense to move out bdi_task_limit_exceeded() check in a separate if condition statement as follows. May be this is little easier to read.

    if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) { if (bdi->dirty_exceeded) bdi->dirty_exceeded = 0;

            if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND) bdi_start_background_writeback(bdi);

            return;
    }

    if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT && !bdi_task_limit_exceeded(&st, current)) return;

Quoted 7 lines
Quoted 3 lines

  But then we have to start background writeback here as well. Which is actually a bug in the original patch as well! So clearly your way is more readable :) I'll change it. Thanks.

I was thinking about that starting of bdi writeback here. But I was assuming that if we are here then we most likely have visited above loop of < DIRTY_MAY_EXCEED_LIMIT and started background writeback.

Quoted 6 lines

Maybe I'm missing something, but at the point in balance_dirty_pages() where we kick the flusher thread , before we put the current task to sleep, how do you know that background writeback is taking place?  Are you simply assuming that in previous calls to balance_dirty_pages(), that background writeback has been started, and is still taking place at the time we need to do throttling?

Never mind, I see that I'm not completely familiar with the writeback changes for 2.6.38. I see where we'll kick of BG writeback in wb_check_background_flush() once we kick the flusher thread.

Curt

Quoted 16 lines

Thanks,
Curt

Quoted 11 lines

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

In reply to Jan Kara

On Tue, Mar 08, 2011 at 11:31:13PM +0100, Jan Kara wrote:

[..]

Quoted 66 lines
mm/page-writeback.c +43 -16
+/*
+ * 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
+ * the caller to perform writeback if the system is over `vm_dirty_ratio'.
+ * If we're over `background_thresh' then the writeback threads are woken to
+ * perform some writeout.
+ */
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;
 
-	if (writeback_in_progress(bdi))
-		return;
+	trace_writeback_balance_dirty_pages_waiting(bdi, write_chunk);
+	/* Kick flusher thread to start doing work if it isn't already */
+	bdi_start_background_writeback(bdi);
 
+	bw.bw_wait_pages = write_chunk;
+	bw.bw_task = current;
+	spin_lock(&bdi->balance_lock);
 	/*
-	 * In laptop mode, we wait until hitting the higher threshold before
-	 * starting background writeout, and then write out all the way down
-	 * to the lower threshold.  So slow writers cause minimal disk activity.
-	 *
-	 * In normal mode, we start background writeout at the lower
-	 * background_thresh, to keep the amount of dirty memory low.
+	 * First item? Need to schedule distribution of IO completions among
+	 * items on balance_list
+	 */
+	if (list_empty(&bdi->balance_list)) {

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 717

Quoted 10 lines
mm/page-writeback.c +10 -0
+		bdi->written_start = bdi_stat_sum(bdi, BDI_WRITTEN);
+		/* FIXME: Delay should be autotuned based on dev throughput */
+		schedule_delayed_work(&bdi->balance_work, HZ/10);
+	}
+	/*
+	 * Add work to the balance list, from now on the structure is handled
+	 * by distribute_page_completions()
+	 */
+	list_add_tail(&bw.bw_list, &bdi->balance_list);
+	bdi->balance_waiters++;

Hi Jan,

Had a query.

- What makes sure that flusher thread will not stop writing back till all the waiters on the bdi have been woken up. IIUC, flusher thread will stop once global background ratio is with-in limit. Is it possible that there are still some waiter on some bdi waiting for more pages to finish writeback and that might not happen for sometime.

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#13 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 80 lines · Vivek Goyal

On Tue, Mar 08, 2011 at 11:31:13PM +0100, Jan Kara wrote:
[..]

Quoted 66 lines
mm/page-writeback.c +43 -16
+/*
+ * 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
+ * the caller to perform writeback if the system is over `vm_dirty_ratio'.
+ * If we're over `background_thresh' then the writeback threads are woken to
+ * perform some writeout.
+ */
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;
 
-	if (writeback_in_progress(bdi))
-		return;
+	trace_writeback_balance_dirty_pages_waiting(bdi, write_chunk);
+	/* Kick flusher thread to start doing work if it isn't already */
+	bdi_start_background_writeback(bdi);
 
+	bw.bw_wait_pages = write_chunk;
+	bw.bw_task = current;
+	spin_lock(&bdi->balance_lock);
 	/*
-	 * In laptop mode, we wait until hitting the higher threshold before
-	 * starting background writeout, and then write out all the way down
-	 * to the lower threshold.  So slow writers cause minimal disk activity.
-	 *
-	 * In normal mode, we start background writeout at the lower
-	 * background_thresh, to keep the amount of dirty memory low.
+	 * First item? Need to schedule distribution of IO completions among
+	 * items on balance_list
+	 */
+	if (list_empty(&bdi->balance_list)) {

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 717

Quoted 10 lines
mm/page-writeback.c +10 -0
+		bdi->written_start = bdi_stat_sum(bdi, BDI_WRITTEN);
+		/* FIXME: Delay should be autotuned based on dev throughput */
+		schedule_delayed_work(&bdi->balance_work, HZ/10);
+	}
+	/*
+	 * Add work to the balance list, from now on the structure is handled
+	 * by distribute_page_completions()
+	 */
+	list_add_tail(&bw.bw_list, &bdi->balance_list);
+	bdi->balance_waiters++;

Had a query.

Quoted 5 lines

- What makes sure that flusher thread will not stop writing back till all the waiters on the bdi have been woken up. IIUC, flusher thread will stop once global background ratio is with-in limit. Is it possible that there are still some waiter on some bdi waiting for more pages to finish writeback and that might not happen for sometime.

Yes, this can possibly happen but once distribute_page_completions()
gets called (after a given time), it will notice that we are below limits and wake all waiters. Under normal circumstances, we should have a decent estimate when distribute_page_completions() needs to be called and that should be long before flusher thread finishes it's work. But in cases when a bdi has only a small share of global dirty limit, what you describe can possibly happen.

Honza

Signature · 9 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>
#14 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 86 lines · Jan Kara
Quoted 80 lines · Vivek Goyal

On Tue, Mar 08, 2011 at 11:31:13PM +0100, Jan Kara wrote:
[..]

Quoted 66 lines
mm/page-writeback.c +43 -16
+/*
+ * 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
+ * the caller to perform writeback if the system is over `vm_dirty_ratio'.
+ * If we're over `background_thresh' then the writeback threads are woken to
+ * perform some writeout.
+ */
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;
 
-	if (writeback_in_progress(bdi))
-		return;
+	trace_writeback_balance_dirty_pages_waiting(bdi, write_chunk);
+	/* Kick flusher thread to start doing work if it isn't already */
+	bdi_start_background_writeback(bdi);
 
+	bw.bw_wait_pages = write_chunk;
+	bw.bw_task = current;
+	spin_lock(&bdi->balance_lock);
 	/*
-	 * In laptop mode, we wait until hitting the higher threshold before
-	 * starting background writeout, and then write out all the way down
-	 * to the lower threshold.  So slow writers cause minimal disk activity.
-	 *
-	 * In normal mode, we start background writeout at the lower
-	 * background_thresh, to keep the amount of dirty memory low.
+	 * First item? Need to schedule distribution of IO completions among
+	 * items on balance_list
+	 */
+	if (list_empty(&bdi->balance_list)) {

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 717

Quoted 10 lines
mm/page-writeback.c +10 -0
+		bdi->written_start = bdi_stat_sum(bdi, BDI_WRITTEN);
+		/* FIXME: Delay should be autotuned based on dev throughput */
+		schedule_delayed_work(&bdi->balance_work, HZ/10);
+	}
+	/*
+	 * Add work to the balance list, from now on the structure is handled
+	 * by distribute_page_completions()
+	 */
+	list_add_tail(&bw.bw_list, &bdi->balance_list);
+	bdi->balance_waiters++;

Had a query.

Quoted 5 lines

- What makes sure that flusher thread will not stop writing back till all the waiters on the bdi have been woken up. IIUC, flusher thread will stop once global background ratio is with-in limit. Is it possible that there are still some waiter on some bdi waiting for more pages to finish writeback and that might not happen for sometime.

Quoted 8 lines

Yes, this can possibly happen but once distribute_page_completions()
gets called (after a given time), it will notice that we are below limits and wake all waiters.
Under normal circumstances, we should have a decent
estimate when distribute_page_completions() needs to be called and that should be long before flusher thread finishes it's work. But in cases when a bdi has only a small share of global dirty limit, what you describe can possibly happen.

So if a bdi share is small then it can happen that global background threshold is fine but per bdi threshold is not. That means task_bdi_threshold is also above limit and IIUC, distribute_page_completion() will not wake up the waiter until bdi_task_limit_exceeded() is in control.

/*
* Wake tasks that might have gotten below their limits and
* compute
* the number of pages we wait for
*/
list_for_each_entry_safe(waiter, tmpw, &bdi->balance_list,

bw_list) {
                if (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
                    !bdi_task_limit_exceeded(&st, waiter->bw_task))
                        balance_waiter_done(bdi, waiter);
                else if (waiter->bw_wait_pages < min_pages)
                        min_pages = waiter->bw_wait_pages;
        }

So it can happen that global background threshold is under limit but a specific task bdi threshold is not and I am failing to see who will wake up the task in that situation.

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#15 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

Quoted 96 lines · Vivek Goyal
Quoted 86 lines · Jan Kara
Quoted 80 lines · Vivek Goyal

On Tue, Mar 08, 2011 at 11:31:13PM +0100, Jan Kara wrote:
[..]

Quoted 66 lines
mm/page-writeback.c +43 -16
+/*
+ * 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
+ * the caller to perform writeback if the system is over `vm_dirty_ratio'.
+ * If we're over `background_thresh' then the writeback threads are woken to
+ * perform some writeout.
+ */
+static void balance_dirty_pages(struct address_space *mapping,
+				unsigned long write_chunk)
+{
+	struct backing_dev_info *bdi = mapping->backing_dev_info;
+	struct balance_waiter bw;
+	struct dirty_limit_state st;
+	int dirty_exceeded = check_dirty_limits(bdi, &st);
+
+	if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT ||
+	    (dirty_exceeded == DIRTY_MAY_EXCEED_LIMIT &&
+	     !bdi_task_limit_exceeded(&st, current))) {
+		if (bdi->dirty_exceeded &&
+		    dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT)
+			bdi->dirty_exceeded = 0;
 		/*
-		 * Increase the delay for each loop, up to our previous
-		 * default of taking a 100ms nap.
+		 * In laptop mode, we wait until hitting the higher threshold
+		 * before starting background writeout, and then write out all
+		 * the way down to the lower threshold.  So slow writers cause
+		 * minimal disk activity.
+		 *
+		 * In normal mode, we start background writeout at the lower
+		 * background_thresh, to keep the amount of dirty memory low.
 		 */
-		pause <<= 1;
-		if (pause > HZ / 10)
-			pause = HZ / 10;
+		if (!laptop_mode && dirty_exceeded == DIRTY_EXCEED_BACKGROUND)
+			bdi_start_background_writeback(bdi);
+		return;
 	}
 
-	/* Clear dirty_exceeded flag only when no task can exceed the limit */
-	if (!min_dirty_exceeded && bdi->dirty_exceeded)
-		bdi->dirty_exceeded = 0;
+	if (!bdi->dirty_exceeded)
+		bdi->dirty_exceeded = 1;
 
-	if (writeback_in_progress(bdi))
-		return;
+	trace_writeback_balance_dirty_pages_waiting(bdi, write_chunk);
+	/* Kick flusher thread to start doing work if it isn't already */
+	bdi_start_background_writeback(bdi);
 
+	bw.bw_wait_pages = write_chunk;
+	bw.bw_task = current;
+	spin_lock(&bdi->balance_lock);
 	/*
-	 * In laptop mode, we wait until hitting the higher threshold before
-	 * starting background writeout, and then write out all the way down
-	 * to the lower threshold.  So slow writers cause minimal disk activity.
-	 *
-	 * In normal mode, we start background writeout at the lower
-	 * background_thresh, to keep the amount of dirty memory low.
+	 * First item? Need to schedule distribution of IO completions among
+	 * items on balance_list
+	 */
+	if (list_empty(&bdi->balance_list)) {

mm/page-writeback.c unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty) · line 717

Quoted 10 lines
mm/page-writeback.c +10 -0
+		bdi->written_start = bdi_stat_sum(bdi, BDI_WRITTEN);
+		/* FIXME: Delay should be autotuned based on dev throughput */
+		schedule_delayed_work(&bdi->balance_work, HZ/10);
+	}
+	/*
+	 * Add work to the balance list, from now on the structure is handled
+	 * by distribute_page_completions()
+	 */
+	list_add_tail(&bw.bw_list, &bdi->balance_list);
+	bdi->balance_waiters++;

Had a query.

Quoted 5 lines

- What makes sure that flusher thread will not stop writing back till all the waiters on the bdi have been woken up. IIUC, flusher thread will stop once global background ratio is with-in limit. Is it possible that there are still some waiter on some bdi waiting for more pages to finish writeback and that might not happen for sometime.

Quoted 8 lines

Yes, this can possibly happen but once distribute_page_completions()
gets called (after a given time), it will notice that we are below limits and wake all waiters.
Under normal circumstances, we should have a decent
estimate when distribute_page_completions() needs to be called and that should be long before flusher thread finishes it's work. But in cases when a bdi has only a small share of global dirty limit, what you describe can possibly happen.

Quoted 4 lines

So if a bdi share is small then it can happen that global background threshold is fine but per bdi threshold is not. That means task_bdi_threshold is also above limit and IIUC, distribute_page_completion() will not wake up the waiter until bdi_task_limit_exceeded() is in control.

It will wake them. What you miss is the check right at the beginning of
distribute_page_completions():

      dirty_exceeded = check_dirty_limits(bdi, &st);
      if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) {
               /* Wakeup everybody */

...

When we are globally below (background+limit)/2, dirty_exceeded is set to
DIRTY_OK or DIRTY_BACKGROUND and thus we just wake all the waiters.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#16 lore raw

Re: [PATCH 3/5] mm: Implement IO-less balance_dirty_pages()

On Wed, Mar 16, 2011 at 08:58:44PM +0100, Jan Kara wrote:

[..]

Quoted 22 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines

Had a query.

- What makes sure that flusher thread will not stop writing back till all the waiters on the bdi have been woken up. IIUC, flusher thread will stop once global background ratio is with-in limit. Is it possible that there are still some waiter on some bdi waiting for more pages to finish writeback and that might not happen for sometime.

Quoted 8 lines

Yes, this can possibly happen but once distribute_page_completions()
gets called (after a given time), it will notice that we are below limits and wake all waiters.
Under normal circumstances, we should have a decent
estimate when distribute_page_completions() needs to be called and that should be long before flusher thread finishes it's work. But in cases when a bdi has only a small share of global dirty limit, what you describe can possibly happen.

Quoted 4 lines

So if a bdi share is small then it can happen that global background threshold is fine but per bdi threshold is not. That means task_bdi_threshold is also above limit and IIUC, distribute_page_completion() will not wake up the waiter until bdi_task_limit_exceeded() is in control.

It will wake them. What you miss is the check right at the beginning of
distribute_page_completions():

Quoted 7 lines
      dirty_exceeded = check_dirty_limits(bdi, &st);
      if (dirty_exceeded < DIRTY_MAY_EXCEED_LIMIT) {
               /* Wakeup everybody */

...

When we are globally below (background+limit)/2, dirty_exceeded is set to
DIRTY_OK or DIRTY_BACKGROUND and thus we just wake all the waiters.

Ok, thanks. Now I see it.

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#17 lore raw

PATCH 4/5 mm: Remove low limit from sync_writeback_pages()

In reply to Jan Kara

sync_writeback_pages() limited minimal amount of pages to write in balance_dirty_pages() to 3/2*ratelimit_pages (6 MB) to submit reasonably sized IO. Since we do not submit any IO anymore, be more fair and let the task wait only for 3/2*(the amount dirtied).

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 mm/page-writeback.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
mm/page-writeback.c +2 -7
index 697dd8e..ff07280 100644
@@ -43,16 +43,11 @@
 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 dirtied pages to ensure that reasonably
- * large amounts of I/O are submitted.
+ * When balance_dirty_pages decides that the caller needs to wait for some
+ * writeback to happen, this is how many pages it will attempt to write.
  */
 static inline long sync_writeback_pages(unsigned long dirtied)
 {
-	if (dirtied < ratelimit_pages)
-		dirtied = ratelimit_pages;
-
 	return dirtied + dirtied / 2;
 }
 
Signature · 8 lines
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>
author maintainer
#18 lore raw

PATCH 5/5 mm: Autotune interval between distribution of page completions

In reply to Jan Kara

To avoid throttling processes in balance_dirty_pages() for too long, it is desirable to distribute page completions often enough. On the other hand we do not want to distribute them too often so that we do not burn too much CPU. Obviously, the proper interval depends on the amount of pages we wait for and on the speed the underlying device can write them. So we estimate the throughput of the device, compute the number of pages we need to be completed, and from that compute desired time of next distribution of page completions. To avoid extremities, we force the computed sleep time to be in [HZ/50..HZ/4] interval.

CC Andrew Morton <[email protected]>
CC Christoph Hellwig <[email protected]>
CC Dave Chinner <[email protected]>
CC Wu Fengguang <[email protected]>
CC Peter Zijlstra <[email protected]>
---
 include/linux/backing-dev.h      |    6 ++-
 include/trace/events/writeback.h |   25 ++++++++++
 mm/backing-dev.c                 |    2 +
 mm/page-writeback.c              |   90 ++++++++++++++++++++++++++++++++-----
 4 files changed, 108 insertions(+), 15 deletions(-)
include/linux/backing-dev.h +4 -2
index 65b6e61..a4f9133 100644
@@ -89,12 +89,14 @@ struct backing_dev_info {
 
 	struct timer_list laptop_mode_wb_timer;
 
-	spinlock_t balance_lock;	/* lock protecting four entries below */
-	unsigned long written_start;	/* BDI_WRITTEN last time we scanned balance_list*/
+	spinlock_t balance_lock;	/* lock protecting entries below */
 	struct list_head balance_list;	/* waiters in balance_dirty_pages */
 	unsigned int balance_waiters;	/* number of waiters in the list */
 	struct delayed_work balance_work;	/* work distributing page
 						   completions among waiters */
+	unsigned long written_start;	/* BDI_WRITTEN last time we scanned balance_list*/
+	unsigned long start_jiffies;	/* time when we last scanned list */
+	unsigned long pages_per_s;	/* estimated throughput of bdi */
 
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debug_dir;
include/trace/events/writeback.h +25 -0
index 74815fa..00b06a2 100644
@@ -211,6 +211,31 @@ TRACE_EVENT(writeback_distribute_page_completions_wakeall,
 	)
 );
 
+TRACE_EVENT(writeback_distribute_page_completions_scheduled,
+	TP_PROTO(struct backing_dev_info *bdi, unsigned long nap,
+		 unsigned long pages),
+	TP_ARGS(bdi, nap, pages),
+	TP_STRUCT__entry(
+		__array(char, name, 32)
+		__field(unsigned long, nap)
+		__field(unsigned long, pages)
+		__field(unsigned long, waiters)
+		__field(unsigned long, pages_per_s)
+	),
+	TP_fast_assign(
+		strncpy(__entry->name, dev_name(bdi->dev), 32);
+		__entry->nap = nap;
+		__entry->pages = pages;
+		__entry->waiters = bdi->balance_waiters;
+		__entry->pages_per_s = bdi->pages_per_s;
+	),
+	TP_printk("bdi=%s sleep=%u ms want_pages=%lu waiters=%lu"
+		  " pages_per_s=%lu",
+		  __entry->name, jiffies_to_msecs(__entry->nap),
+		  __entry->pages, __entry->waiters, __entry->pages_per_s
+	)
+);
+
 DECLARE_EVENT_CLASS(writeback_congest_waited_template,
 
 	TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed),
mm/backing-dev.c +2 -0
index 2ecc3fe..e2cbe5c 100644
@@ -655,8 +655,10 @@ int bdi_init(struct backing_dev_info *bdi)
 	spin_lock_init(&bdi->balance_lock);
 	INIT_LIST_HEAD(&bdi->balance_list);
 	bdi->written_start = 0;
+	bdi->start_jiffies = 0;
 	bdi->balance_waiters = 0;
 	INIT_DELAYED_WORK(&bdi->balance_work, distribute_page_completions);
+	bdi->pages_per_s = 1;
 
 	bdi_wb_init(&bdi->wb, bdi);
 
mm/page-writeback.c +77 -13

136 lines not on this page · raw message

Signature · 1 line
1.7.1
#19 lore raw
In reply to Jan Kara

Hi Jan:

Quoted 49 lines · Jan Kara

 Hello,

 I'm posting second version of my IO-less balance_dirty_pages() patches. This is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control. Fengguang is currently running some tests on my patches so that we can compare the approaches.

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
 number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

Since last version I've implemented cleanups as suggested by Peter Zilstra. The patches undergone more throughout testing. So far I've tested different filesystems (ext2, ext3, ext4, xfs, nfs), also a combination of a local filesystem and nfs. The load was either various number of dd threads or fio with several threads each dirtying pages at different speed.

Results and test scripts can be found at
 http://beta.suse.com/private/jack/balance_dirty_pages-v2/
See README file for some explanation of test framework, tests, and graphs. Except for ext3 in data=ordered mode, where kjournald creates high fluctuations in waiting time of throttled processes (and also high latencies), the results look OK. Parallel dd threads are being throttled in the same way (in a 2s window threads spend the same time waiting) and also latencies of individual waits seem OK - except for ext3 they fit in 100 ms for local filesystems. They are in 200-500 ms range for NFS, which isn't that nice but to fix that we'd have to modify current ratelimiting scheme to take into account on which bdi a page is dirtied. Then we could ratelimit slower BDIs more often thus reducing latencies in individual waits...

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

Quoted 5 lines

I'm planning to run some tests with multiple SATA drives to verify whether there aren't some unexpected fluctuations. But currently I have some trouble with the HW...

As usual comments are welcome :).

The design of IO-less foreground throttling of writeback in the context of memory cgroups is being discussed in the memcg patch threads (e.g., "[PATCH v6 0/9] memcg: per cgroup dirty page accounting"), but I've got another concern as well. And that's how restricting per-BDI writeback to a single task will affect proposed changes for tracking and accounting of buffered writes to the IO scheduler ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes", https://lkml.org/lkml/2011/3/8/332 ).

It seems totally reasonable that reducing competition for write requests to a BDI -- by using the flusher thread to "handle" foreground writeout -- would increase throughput to that device. At Google, we experiemented with this in a hacked-up fashion several months ago (FG task would enqueue a work item and sleep for some period of time, wake up and see if it was below the dirty limit), and found that we were indeed getting better throughput.

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler. We saw that in practice, which led to abandoning our attempt at "IO-less throttling."

One possible solution would be to put some of the disk isolation smarts into the writeback path, so the flusher thread could choose inodes with this as a criteria, but this seems ugly on its face, and makes my head hurt.

Otherwise, I'm having trouble thinking of a way to do effective isolation in the IO scheduler without having competing threads -- for different cgroups -- making write requests for buffered data. Perhaps the best we could do would be to enable IO-less throttling in writeback as a config option?

Thoughts?

Thanks,
Curt

Quoted 7 lines

                                                               Honza --
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#20 lore raw
Quoted 3 lines · Curt Wohlgemuth

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler.

If you use any kind of buffered I/O you already fail in that respect. Writeback from balance_dirty_page really is just the wort case right now with more I/O supposed to be handled by the background threads. So if you want to implement isolation properly you need to track the originator of the I/O between the copy to the pagecache and actual writeback.

#21 lore raw

Hi Christoph:

Quoted 11 lines · Christoph Hellwig
Quoted 3 lines · Curt Wohlgemuth

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler.

If you use any kind of buffered I/O you already fail in that respect. Writeback from balance_dirty_page really is just the wort case right now with more I/O supposed to be handled by the background threads.  So if you want to implement isolation properly you need to track the originator of the I/O between the copy to the pagecache and actual writeback.

Which is indeed part of the patchset I referred to above ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes",
https://lkml.org/lkml/2011/3/8/332 ).

Thanks,
Curt
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw
Quoted 3 lines · Curt Wohlgemuth

Which is indeed part of the patchset I referred to above ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes",
https://lkml.org/lkml/2011/3/8/332 ).

So what about letting us fix normal writeback first and then later look into cgroups properly. And to do it properly we'll need to implement something similar to the I/O less balance dirty pages - be that targeted writeback from the flusher thread including proper tagging of pages, or be that writeback from balance_dirty_pages in a why that we keep multiple processes from writing at the same time. Although I'd prefer something that keeps the CG case as close as possible to the normal code, right now we already have a huge mess with memcg and it's own handrolled version of direct reclaim which is an even worse stack hog than the already overly painfull "normal" direct reclaim.

author maintainer
#23 lore raw
In reply to Curt Wohlgemuth
Quoted 16 lines · Curt Wohlgemuth

On Tue, Mar 8, 2011 at 2:31 PM, Jan Kara <[email protected]> wrote:
The design of IO-less foreground throttling of writeback in the context of memory cgroups is being discussed in the memcg patch threads (e.g., "[PATCH v6 0/9] memcg: per cgroup dirty page accounting"), but I've got another concern as well. And that's how restricting per-BDI writeback to a single task will affect proposed changes for tracking and accounting of buffered writes to the IO scheduler ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes", https://lkml.org/lkml/2011/3/8/332 ).

It seems totally reasonable that reducing competition for write requests to a BDI -- by using the flusher thread to "handle" foreground writeout -- would increase throughput to that device. At Google, we experiemented with this in a hacked-up fashion several months ago (FG task would enqueue a work item and sleep for some period of time, wake up and see if it was below the dirty limit), and found that we were indeed getting better throughput.

Quoted 4 lines

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler. We saw that in practice, which led to abandoning our attempt at "IO-less throttling."

Let me check if I understand: The problem you have with one flusher
thread is that when written pages all belong to a single memcg, there is nothing IO scheduler can prioritize, right?

Quoted 3 lines

One possible solution would be to put some of the disk isolation smarts into the writeback path, so the flusher thread could choose inodes with this as a criteria, but this seems ugly on its face, and makes my head hurt.

Well, I think it could be implemented in a reasonable way but then you
still miss reads and direct IO from the mix so it will be a poor isolation. But maybe we could propagate the information from IO scheduler to flusher thread? If IO scheduler sees memcg has run out of its limit, it could hint to a flusher thread that it should switch to an inode from a different memcg. But still the details get nasty as I think about them (how to pick next memcg, how to pick inodes,...). Essentially, we'd have to do with flusher threads what old pdflush did when handling congested devices. Ugh.

Quoted 4 lines

Otherwise, I'm having trouble thinking of a way to do effective isolation in the IO scheduler without having competing threads -- for different cgroups -- making write requests for buffered data. Perhaps the best we could do would be to enable IO-less throttling in writeback as a config option?

Well, nothing prevents us to choose to do foreground writeback throttling
for memcgs and IO-less one without them but as Christoph writes, this doesn't seem very compeling either... I'll let this brew in my head for some time and maybe something comes.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#24 lore raw
Quoted 17 lines · Jan Kara
Quoted 16 lines · Curt Wohlgemuth

On Tue, Mar 8, 2011 at 2:31 PM, Jan Kara <[email protected]> wrote:
The design of IO-less foreground throttling of writeback in the context of memory cgroups is being discussed in the memcg patch threads (e.g., "[PATCH v6 0/9] memcg: per cgroup dirty page accounting"), but I've got another concern as well.  And that's how restricting per-BDI writeback to a single task will affect proposed changes for tracking and accounting of buffered writes to the IO scheduler ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes", https://lkml.org/lkml/2011/3/8/332 ).

It seems totally reasonable that reducing competition for write requests to a BDI -- by using the flusher thread to "handle" foreground writeout -- would increase throughput to that device.  At Google, we experiemented with this in a hacked-up fashion several months ago (FG task would enqueue a work item and sleep for some period of time, wake up and see if it was below the dirty limit), and found that we were indeed getting better throughput.

Quoted 8 lines
Quoted 4 lines

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler.  We saw that in practice, which led to abandoning our attempt at "IO-less throttling."

 Let me check if I understand: The problem you have with one flusher thread is that when written pages all belong to a single memcg, there is nothing IO scheduler can prioritize, right?

Correct. Well, perhaps. Given that the memory cgroups and the IO cgroups may not overlap, it's possible that write requests from a single memcg might be targeted to multiple IO cgroups, and scheduling priorities can be maintained. Of course, the other way round might be the case as well.

The point is just that from however many memcgs the flusher thread is working on behalf of, there's only a single stream of requests, which are *likely* for a single IO cgroup, and hence there's nothing to prioritize.

Quoted 5 lines
Quoted 3 lines

One possible solution would be to put some of the disk isolation smarts into the writeback path, so the flusher thread could choose inodes with this as a criteria, but this seems ugly on its face, and makes my head hurt.

 Well, I think it could be implemented in a reasonable way but then you still miss reads and direct IO from the mix so it will be a poor isolation.

Um, not really, would it? Presumably there are separate tasks (directly) issuing simultaneous requests for reads, and DIO writes; these should interact just fine with writes from the single flusher thread.

Quoted 6 lines

But maybe we could propagate the information from IO scheduler to flusher thread? If IO scheduler sees memcg has run out of its limit, it could hint to a flusher thread that it should switch to an inode from a different memcg. But still the details get nasty as I think about them (how to pick next memcg, how to pick inodes,...). Essentially, we'd have to do with flusher threads what old pdflush did when handling congested devices. Ugh.

Yeah, plus what I said above, that memcgs and IO cgroups aren't necessarily the same cgroups.

Quoted 9 lines
Quoted 4 lines

Otherwise, I'm having trouble thinking of a way to do effective isolation in the IO scheduler without having competing threads -- for different cgroups -- making write requests for buffered data.  Perhaps the best we could do would be to enable IO-less throttling in writeback as a config option?

 Well, nothing prevents us to choose to do foreground writeback throttling for memcgs and IO-less one without them but as Christoph writes, this doesn't seem very compeling either... I'll let this brew in my head for some time and maybe something comes.

I agree with Christoph too; I mainly wanted to get the issue out there, and will be thinking on it more as well.

Thanks,
Curt
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw
Quoted 27 lines · Curt Wohlgemuth
Quoted 17 lines · Jan Kara
Quoted 16 lines · Curt Wohlgemuth

On Tue, Mar 8, 2011 at 2:31 PM, Jan Kara <[email protected]> wrote:
The design of IO-less foreground throttling of writeback in the context of memory cgroups is being discussed in the memcg patch threads (e.g., "[PATCH v6 0/9] memcg: per cgroup dirty page accounting"), but I've got another concern as well.  And that's how restricting per-BDI writeback to a single task will affect proposed changes for tracking and accounting of buffered writes to the IO scheduler ("[RFC] [PATCH 0/6] Provide cgroup isolation for buffered writes", https://lkml.org/lkml/2011/3/8/332 ).

It seems totally reasonable that reducing competition for write requests to a BDI -- by using the flusher thread to "handle" foreground writeout -- would increase throughput to that device.  At Google, we experiemented with this in a hacked-up fashion several months ago (FG task would enqueue a work item and sleep for some period of time, wake up and see if it was below the dirty limit), and found that we were indeed getting better throughput.

Quoted 8 lines
Quoted 4 lines

But if one of one's goals is to provide some sort of disk isolation based on cgroup parameters, than having at most one stream of write requests effectively neuters the IO scheduler.  We saw that in practice, which led to abandoning our attempt at "IO-less throttling."

 Let me check if I understand: The problem you have with one flusher thread is that when written pages all belong to a single memcg, there is nothing IO scheduler can prioritize, right?

Quoted 5 lines

Correct. Well, perhaps. Given that the memory cgroups and the IO cgroups may not overlap, it's possible that write requests from a single memcg might be targeted to multiple IO cgroups, and scheduling priorities can be maintained. Of course, the other way round might be the case as well.

[CCing some folks who were involved in other mail thread]

I think that for buffered write case it would make most sense when memory controller and IO controller are co-mounted and working with each other. The reason being that for async writes we need to control the dirty share of a cgroup as well as try to prioritize the IO at device level from cgroup.

It would not make any sense that a low prio async group is choked at device level and its footprint in page cache is increasing resulting in choking other fast writers.

So we need to make sure that slow writers don't have huge page cache footprint and hence I think using memory and IO controller together makes sense. Do you have other use cases where it does not make sense?

Quoted 5 lines

The point is just that from however many memcgs the flusher thread is working on behalf of, there's only a single stream of requests, which are *likely* for a single IO cgroup, and hence there's nothing to prioritize.

I think even single submitter stream can also make sense if underlying device/bdi is slow and submitter is fast and switches frequently between memory cgroups for selection of inodes.

So we have IO control at device level and we have IO queues for each cgroup and if flusher thread can move quickly (say submit 512 pages from one cgroup and then move to next), from one cgroup to other, then we should automatically get the IO difference.

In other mail I suggested that if we can keep per memory cgroup per BDI stats for number of writes in progress, then flusher thread can skip submitting IO from cgroups which are slow and there are many pending writebacks. That is a hint to flusher thread that IO scheduler is giving this cgroup a lower priority hence high number of writes in flight which are simply queued up at IO schduler. For high priority cgroups which are making progress, pending writebacks will be small or zero and flusher can submit more inodes/pages from that memory cgroup. That way a higher weight group should get more IO done as compared to a slower group.

I am assuming that prioritizing async request is primarily is for slow media like single SATA disk. If yes, then flusher thread should be able to submit pages much faster then device can complete those and can cgroup IO queues busy at end device hence IO scheduler should be able to prioritize.

Thoughts?

Thanks
Vivek

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

#26 lore raw
In reply to Jan Kara

Hi Jan,

Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

(brief listing first: I've just returned from travel)

Quoted 2 lines

Fengguang is currently running some tests on my patches so that we can compare the approaches.

Yup, here are the tracing patches and graphs:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/

Quoted 9 lines

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

Quoted 5 lines

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

When there comes no IO completion in 1 second (normal in NFS), the tasks will all get stuck. It is fixable based on your v2 code base (detailed below), however will likely bring the same level of complexity as the base bandwidth solution.

As for v2, there are still big gap to fill. NFS dirtiers are constantly doing 20-25 seconds long delays

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-1dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-31/balance_dirty_pages-pause.png
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-pause.png

and the tasks are bumping forwards

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-task-bw.png

Quoted 6 lines

Since last version I've implemented cleanups as suggested by Peter Zilstra. The patches undergone more throughout testing. So far I've tested different filesystems (ext2, ext3, ext4, xfs, nfs), also a combination of a local filesystem and nfs. The load was either various number of dd threads or fio with several threads each dirtying pages at different speed.

Quoted 12 lines

Results and test scripts can be found at
http://beta.suse.com/private/jack/balance_dirty_pages-v2/
See README file for some explanation of test framework, tests, and graphs. Except for ext3 in data=ordered mode, where kjournald creates high fluctuations in waiting time of throttled processes (and also high latencies), the results look OK. Parallel dd threads are being throttled in the same way (in a 2s window threads spend the same time waiting) and also latencies of individual waits seem OK - except for ext3 they fit in 100 ms for local filesystems. They are in 200-500 ms range for NFS, which isn't that nice but to fix that we'd have to modify current ratelimiting scheme to take into account on which bdi a page is dirtied. Then we could ratelimit slower BDIs more often thus reducing latencies in individual waits...

Yes the per-cpu rate limit is a problem, so I'm switching to per-task rate limit.

The direct input from IO completion is another issue. It leaves the dirty tasks at the mercy of low layer (VFS/FS/bdev) fluctuations and latencies. So I'm introducing the base bandwidth as a buffer layer. You may employ the similar technique: to simulate a more smooth flow of IO completion events based on the average write bandwidth. Then it naturally introduce the problem of rate mismatch between simulated/real IO completions, and the need to do more elaborated position control.

Quoted 5 lines

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

The base bandwidth based throttling can do better and provide almost perfect fairness, because all tasks writing to one bdi derive their own throttle bandwidth based on the same per-bdi base bandwidth. So the heavier dirtiers will converge to equal dirty rate and weight.

Quoted 5 lines

I'm planning to run some tests with multiple SATA drives to verify whether there aren't some unexpected fluctuations. But currently I have some trouble with the HW...

As usual comments are welcome :).

Thanks,
Fengguang

author maintainer
#27 lore raw

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Quoted 15 lines
Quoted 9 lines

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

Quoted 5 lines

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

Quoted 4 lines

When there comes no IO completion in 1 second (normal in NFS), the tasks will all get stuck. It is fixable based on your v2 code base (detailed below), however will likely bring the same level of complexity as the base bandwidth solution.

I have some plans how to account for bumpy IO completion when we wait for
a long time and then get completion of much more IO than we actually need. But in case where processes use all the bandwidth and the latency of the device is high, sure they take the penalty and have to wait for a long time in balance_dirty_pages().

Quoted 5 lines

As for v2, there are still big gap to fill. NFS dirtiers are constantly doing 20-25 seconds long delays

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-1dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-31/balance_dirty_pages-pause.png
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-pause.png

Yeah, this is because they want lots of pages each
(3/2*MAX_WRITEBACK_PAGES). I'll try to change ratelimiting to make several shorter sleeps. But ultimately you have to wait this much. Just you can split those big sleeps in more of smaller ones.

Quoted 3 lines

and the tasks are bumping forwards

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-task-bw.png

Yeah, that's a result of bumpy NFS writeout and basically the consequence
of the above. Maybe it can be helped but I don't find this to be a problem on its own...

Quoted 19 lines
Quoted 6 lines

Since last version I've implemented cleanups as suggested by Peter Zilstra. The patches undergone more throughout testing. So far I've tested different filesystems (ext2, ext3, ext4, xfs, nfs), also a combination of a local filesystem and nfs. The load was either various number of dd threads or fio with several threads each dirtying pages at different speed.

Quoted 12 lines

Results and test scripts can be found at
http://beta.suse.com/private/jack/balance_dirty_pages-v2/
See README file for some explanation of test framework, tests, and graphs. Except for ext3 in data=ordered mode, where kjournald creates high fluctuations in waiting time of throttled processes (and also high latencies), the results look OK. Parallel dd threads are being throttled in the same way (in a 2s window threads spend the same time waiting) and also latencies of individual waits seem OK - except for ext3 they fit in 100 ms for local filesystems. They are in 200-500 ms range for NFS, which isn't that nice but to fix that we'd have to modify current ratelimiting scheme to take into account on which bdi a page is dirtied. Then we could ratelimit slower BDIs more often thus reducing latencies in individual waits...

Quoted 2 lines

Yes the per-cpu rate limit is a problem, so I'm switching to per-task rate limit.

BTW: Have you considered per-bdi ratelimiting? Both per-task and per-bdi
make sense just they are going to have slightly different properties... Current per-cpu ratelimit counters tend to behave like per-task ratelimiting at least for fast dirtiers because once a task is blocked in balance_dirty_pages() another task runs on that cpu and uses the counter for itself. So I wouldn't expect big differences from per-task ratelimiting...

Quoted 8 lines

The direct input from IO completion is another issue. It leaves the dirty tasks at the mercy of low layer (VFS/FS/bdev) fluctuations and latencies. So I'm introducing the base bandwidth as a buffer layer. You may employ the similar technique: to simulate a more smooth flow of IO completion events based on the average write bandwidth. Then it naturally introduce the problem of rate mismatch between simulated/real IO completions, and the need to do more elaborated position control.

Exacttly, that's why I don't want to base throttling on some computed
value (well, I also somehow estimate necessary sleep time but that's more a performance optimization) but rather leave tasks "at the mercy of lower layers" as you write ;) I don't think it's necessarily a bad thing.

Quoted 10 lines
Quoted 5 lines

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

The base bandwidth based throttling can do better and provide almost perfect fairness, because all tasks writing to one bdi derive their own throttle bandwidth based on the same per-bdi base bandwidth. So the heavier dirtiers will converge to equal dirty rate and weight.

So what do you consider a perfect fairness in this case and are you sure
it is desirable? I was thinking about this and I'm not sure...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#28 lore raw
Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

This is my major concern - maintainability of the code. It's all well and good to evaluate the code based on it's current performance, but what about 2 or 3 years down the track when for some reason it's not working like it was intended - just like what happened with slow degradation in writeback performance between ~2.6.15 and ~2.6.30.

Fundamentally, the _only_ thing I want balance_dirty_pages() to do is _not issue IO_. Issuing IO in balance_dirty_pages() simply does not scale, especially for devices that have no inherent concurrency. I don't care if the solution is not perfectly fair or that there is some latency jitter between threads, I just want to avoid having the IO issue patterns change drastically when the system runs out of clean pages.

IMO, that's all we should be trying to acheive with IO-less write throttling right now. Get that algorithm and infrastructure right first, then we can work out how to build on that to do more fancy stuff.

Quoted 8 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

I agree completely.

FWIW (and that may not be much), the IO-less write throttling that I wrote for Irix back in 2004 was very simple and very effective - input and output bandwidth estimation updated once per second, with a variable write syscall delay applied on each syscall also calculated once per second. The change to the delay was based on the difference between input and output rates and the number of write syscalls per second.

I tried all sorts of fancy stuff to improve it, but the corner cases in anything fancy led to substantial complexity of algorithms and code and workloads that just didn't work well. In the end, simple worked better than fancy and complex and was easier to understand, predict and tune....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#29 lore raw

Hi Dave,

Quoted 12 lines · Dave Chinner
Quoted 11 lines · Jan Kara

Hello Fengguang,

Quoted 8 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

To start with, let me explain the below items and you judge whether they are desirable ones now and future.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(1) latency

The potential impact a write(2) syscall get blocked for over 200ms could be

- user perceptible unresponsiveness

- interrupted IO pipeline in such kind of applications

        loop {
                read(buf)
                write(buf)
        }

In particular the read() IO stream will be interrupted. If it's a read stream from another disk, then the disk may go idle for the period. If it's a read stream from network, the client side uploading files via an ADSL link will find the upload bandwidth under-utilized.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(2) fairness

This is raised by Jan Kara. It should be application dependent. Some workloads may not care at all. Some may be more sensitive.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(3) smoothness

It reflects the variation of a task's throttled dirty bandwidth. The fluctuation of dirty rate can degrade the possible read-write IO pipeline in the similar way as (1).

Quoted 1 line
Quoted 1 line
Quoted 1 line

(4) scalability

Being able to scale well to 1000+ dirtiers, and to large number of CPUs and disks.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation

The IO controller stuff. It seems there are only disparities on when and how to provide the features. (5) and priority based IO controller are the side product of the base bandwidth solution.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(9) backed by both theory and tests

The prerequisites for quality code.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(10) adapt pause time up on 100+ dirtiers

To reduce CPU overheads, requested by you :)

Quoted 1 line
Quoted 1 line
Quoted 1 line

(11) adapt pause time down on low dirty pages

This is necessary to avoid < 100% disk utilization on small memory systems.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(12) adapt to new dirty threshold/goal

This is to support dynamically lowering the number of dirty pages in order to avoid excessive page_out() during page reclaim.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(13) safeguard against dirty exceeding

This is a must have to prevent DoS situations. There have to be a hard dirty limit that force the dirtiers to loop inside balance_dirty_pages(). Because the regular throttling scheme in both Jan and my patches can at most throttle the dirtier at eg. 200ms per page. This is not enough to stop the dirty pages from growing high when there are many dirtiers writing to a slow USB stick.

Quoted 1 line
Quoted 1 line
Quoted 1 line

(14) safeguard against device queue underflow

(in JBOD case, maintain reasonable number of dirty pages in each disk queue)

This is necessary to avoid < 100% disk utilization on small memory systems. Note that (14) and (11) share the same goal, however need independent safeguards at two different places.

Quoted 21 lines
Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

This is my major concern - maintainability of the code. It's all well and good to evaluate the code based on it's current performance, but what about 2 or 3 years down the track when for some reason it's not working like it was intended - just like what happened with slow degradation in writeback performance between ~2.6.15 and ~2.6.30.

Fundamentally, the _only_ thing I want balance_dirty_pages() to do is _not issue IO_. Issuing IO in balance_dirty_pages() simply does not scale, especially for devices that have no inherent concurrency. I don't care if the solution is not perfectly fair or that there is some latency jitter between threads, I just want to avoid having the IO issue patterns change drastically when the system runs out of clean pages.

Quoted 4 lines

IMO, that's all we should be trying to acheive with IO-less write throttling right now. Get that algorithm and infrastructure right first, then we can work out how to build on that to do more fancy stuff.

You already got what you want in the base bandwidth patches v6 :) It has been tested extensively and is ready for more wide -mm exercises. Plus more for others that actually care.

As long as the implemented features/performance are

- desirable in long term
- cannot be done in fundamentally more simple/robust way

Then I see no point to drop the ready-to-work solution and take so much efforts to breed another one, perhaps taking 1-2 more release cycles only to reach the same level of performance _and_ complexity.

Quoted 19 lines
Quoted 8 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

I agree completely.

FWIW (and that may not be much), the IO-less write throttling that I wrote for Irix back in 2004 was very simple and very effective - input and output bandwidth estimation updated once per second, with a variable write syscall delay applied on each syscall also calculated once per second. The change to the delay was based on the difference between input and output rates and the number of write syscalls per second.

Quoted 5 lines

I tried all sorts of fancy stuff to improve it, but the corner cases in anything fancy led to substantial complexity of algorithms and code and workloads that just didn't work well. In the end, simple worked better than fancy and complex and was easier to understand, predict and tune....

I may be one of the biggest sufferers of the inherent writeback complexities, and would be more than pleased to have some simple scheme that deals with only simple requirements. However.. I feel obliged to treat smoothness as one requirement when everybody are complaining writeback responsiveness issues in bugzilla, mailing list as well as in LSF and kernel summit.

To help debug and evaluate the work, a bunch of test suites are created and visualized. I can tell from the graphs that the v6 patches are performing very good in all the test cases. It's achieved by 880 lines of code in page-writeback.c. It's good that Jan's v2 does it merely in 300 lines of code, however it's still missing the code for (10)-(14) and the performance gaps are simply too large in many of the cases. IMHO it would need some non-trivial revisions to become a real candidate.

Thanks,
Fengguang

#30 lore raw
In reply to Jan Kara

Hi Jan,

Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

OK.

Quoted 8 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Yeah, now both results are on the website. Let's see whether they are acceptable for others.

Quoted 19 lines
Quoted 15 lines
Quoted 9 lines

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

Quoted 5 lines

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

Quoted 4 lines

When there comes no IO completion in 1 second (normal in NFS), the tasks will all get stuck. It is fixable based on your v2 code base (detailed below), however will likely bring the same level of complexity as the base bandwidth solution.

Quoted 5 lines

I have some plans how to account for bumpy IO completion when we wait for
a long time and then get completion of much more IO than we actually need. But in case where processes use all the bandwidth and the latency of the device is high, sure they take the penalty and have to wait for a long time in balance_dirty_pages().

No, I don't think it's good to block for long time in balance_dirty_pages(). This seems to be our biggest branch point.

Quoted 9 lines
Quoted 5 lines

As for v2, there are still big gap to fill. NFS dirtiers are constantly doing 20-25 seconds long delays

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-1dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-31/balance_dirty_pages-pause.png
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-pause.png

Yeah, this is because they want lots of pages each
(3/2*MAX_WRITEBACK_PAGES). I'll try to change ratelimiting to make several shorter sleeps. But ultimately you have to wait this much. Just you can split those big sleeps in more of smaller ones.

Ideally I prefer less than 100ms sleep time for achieving smooth responsiveness and IO pipeline.

Quoted 6 lines
Quoted 3 lines

and the tasks are bumping forwards

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/jan-bdp-v2b/3G/nfs-10dd-1M-8p-2945M-20%25-2.6.38-rc8-jan-bdp+-2011-03-10-16-38/balance_dirty_pages-task-bw.png

Yeah, that's a result of bumpy NFS writeout and basically the consequence
of the above. Maybe it can be helped but I don't find this to be a problem on its own...

ditto.

Quoted 21 lines
Quoted 19 lines
Quoted 6 lines

Since last version I've implemented cleanups as suggested by Peter Zilstra. The patches undergone more throughout testing. So far I've tested different filesystems (ext2, ext3, ext4, xfs, nfs), also a combination of a local filesystem and nfs. The load was either various number of dd threads or fio with several threads each dirtying pages at different speed.

Quoted 12 lines

Results and test scripts can be found at
http://beta.suse.com/private/jack/balance_dirty_pages-v2/
See README file for some explanation of test framework, tests, and graphs. Except for ext3 in data=ordered mode, where kjournald creates high fluctuations in waiting time of throttled processes (and also high latencies), the results look OK. Parallel dd threads are being throttled in the same way (in a 2s window threads spend the same time waiting) and also latencies of individual waits seem OK - except for ext3 they fit in 100 ms for local filesystems. They are in 200-500 ms range for NFS, which isn't that nice but to fix that we'd have to modify current ratelimiting scheme to take into account on which bdi a page is dirtied. Then we could ratelimit slower BDIs more often thus reducing latencies in individual waits...

Quoted 2 lines

Yes the per-cpu rate limit is a problem, so I'm switching to per-task rate limit.

Quoted 7 lines

BTW: Have you considered per-bdi ratelimiting? Both per-task and per-bdi
make sense just they are going to have slightly different properties... Current per-cpu ratelimit counters tend to behave like per-task ratelimiting at least for fast dirtiers because once a task is blocked in balance_dirty_pages() another task runs on that cpu and uses the counter for itself. So I wouldn't expect big differences from per-task ratelimiting...

Good point. It should be enough to have per-bdi rate limiting threshold. However I still need to keep per-task nr_dirtied for doing per-task throttling bandwidth. The per-cpu bdp_ratelimits mix dirtied pages from different tasks and bdis, which is unacceptable for me.

Quoted 8 lines
Quoted 8 lines

The direct input from IO completion is another issue. It leaves the dirty tasks at the mercy of low layer (VFS/FS/bdev) fluctuations and latencies. So I'm introducing the base bandwidth as a buffer layer. You may employ the similar technique: to simulate a more smooth flow of IO completion events based on the average write bandwidth. Then it naturally introduce the problem of rate mismatch between simulated/real IO completions, and the need to do more elaborated position control.

Quoted 4 lines

Exacttly, that's why I don't want to base throttling on some computed
value (well, I also somehow estimate necessary sleep time but that's more a performance optimization) but rather leave tasks "at the mercy of lower layers" as you write ;) I don't think it's necessarily a bad thing.

Again, the same branch point :)

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

Quoted 6 lines
Quoted 4 lines

The base bandwidth based throttling can do better and provide almost perfect fairness, because all tasks writing to one bdi derive their own throttle bandwidth based on the same per-bdi base bandwidth. So the heavier dirtiers will converge to equal dirty rate and weight.

So what do you consider a perfect fairness in this case and are you sure
it is desirable? I was thinking about this and I'm not sure...

Perfect fairness could be 1, 2, 4, 8, N, N, N MB/s, where

        N = (write_bandwidth - 1 - 2 - 4 - 8) / 3.

I guess its usefulness is largely depending on the user space applications. Most of them should not be sensible to it.

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

author maintainer
#31 lore raw

Hello Fengguang,

Quoted 45 lines · Wu Fengguang
Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

OK.

Quoted 5 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Quoted 6 lines
Quoted 3 lines

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Yeah, now both results are on the website. Let's see whether they are acceptable for others.

Yes. BTW, I think we'll discuss this at LSF so it would be beneficial if
we both prepared a fairly short explanation of our algorithm and some summary of the measured results. I think it would be good to keep each of us below 5 minutes so that we don't bore the audience - people will ask for details where they are interested... What do you think?

I'll try to run also your patches on my setup to see how they work :) V6 from your website is the latest version, isn't it?

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 9 lines

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

Quoted 5 lines

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

When there comes no IO completion in 1 second (normal in NFS), the tasks will all get stuck. It is fixable based on your v2 code base (detailed below), however will likely bring the same level of complexity as the base bandwidth solution.

Quoted 8 lines
Quoted 5 lines

I have some plans how to account for bumpy IO completion when we wait for
a long time and then get completion of much more IO than we actually need. But in case where processes use all the bandwidth and the latency of the device is high, sure they take the penalty and have to wait for a long time in balance_dirty_pages().

No, I don't think it's good to block for long time in balance_dirty_pages(). This seems to be our biggest branch point.

I agree we should not block for several seconds under normal load but
when something insane like 1000 dds is running, I don't think it's a big problem :)

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

Quoted 6 lines
Quoted 4 lines

The base bandwidth based throttling can do better and provide almost perfect fairness, because all tasks writing to one bdi derive their own throttle bandwidth based on the same per-bdi base bandwidth. So the heavier dirtiers will converge to equal dirty rate and weight.

So what do you consider a perfect fairness in this case and are you sure
it is desirable? I was thinking about this and I'm not sure...

Quoted 6 lines

Perfect fairness could be 1, 2, 4, 8, N, N, N MB/s, where

        N = (write_bandwidth - 1 - 2 - 4 - 8) / 3.

I guess its usefulness is largely depending on the user space applications. Most of them should not be sensible to it.

I see, that makes some sense although it makes it advantageous to split
heavy dirtier task into two less heavy dirtiers which is a bit strange. But as you say, precise results here probably do not matter much.

Have a nice weekend

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#32 lore raw

Hi Jan,

Quoted 52 lines · Jan Kara

Hello Fengguang,

Quoted 49 lines · Wu Fengguang
Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

OK.

Quoted 8 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Quoted 7 lines
Quoted 2 lines

Yeah, now both results are on the website. Let's see whether they are acceptable for others.

Yes. BTW, I think we'll discuss this at LSF so it would be beneficial if
we both prepared a fairly short explanation of our algorithm and some summary of the measured results. I think it would be good to keep each of us below 5 minutes so that we don't bore the audience - people will ask for details where they are interested... What do you think?

That looks good, however I'm not able to attend LSF this year, would you help show my slides?

Quoted 2 lines

I'll try to run also your patches on my setup to see how they work :) V6 from your website is the latest version, isn't it?

Thank you. You can run
http://git.kernel.org/?p=linux/kernel/git/wfg/writeback.git;a=shortlog;h=refs/heads/dirty-throttling-v6
or
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/dirty-throttling-v6-2.6.38-rc6.patch
whatever convenient for you.

If you are ready with v3, I can also help test it out and do some comparison on the results.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 15 lines
Quoted 9 lines

The basic idea (implemented in the third patch) is that processes throttled in balance_dirty_pages() wait for enough IO to complete. The waiting is implemented as follows: Whenever we decide to throttle a task in balance_dirty_pages(), task adds itself to a list of tasks that are throttled against that bdi and goes to sleep waiting to receive specified amount of page IO completions. Once in a while (currently HZ/10, in patch 5 the interval is autotuned based on observed IO rate), accumulated page IO completions are distributed equally among waiting tasks.

Quoted 5 lines

This waiting scheme has been chosen so that waiting time in balance_dirty_pages() is proportional to
number_waited_pages * number_of_waiters.
In particular it does not depend on the total number of pages being waited for, thus providing possibly a fairer results.

Quoted 4 lines

When there comes no IO completion in 1 second (normal in NFS), the tasks will all get stuck. It is fixable based on your v2 code base (detailed below), however will likely bring the same level of complexity as the base bandwidth solution.

I have some plans how to account for bumpy IO completion when we wait for
a long time and then get completion of much more IO than we actually need. But in case where processes use all the bandwidth and the latency of the device is high, sure they take the penalty and have to wait for a long time in balance_dirty_pages().

Quoted 5 lines
Quoted 2 lines

No, I don't think it's good to block for long time in balance_dirty_pages(). This seems to be our biggest branch point.

I agree we should not block for several seconds under normal load but
when something insane like 1000 dds is running, I don't think it's a big problem :)

I don't think so. The client does not care whether the server is accepting files from 1000+ clients and its writeback algorithm does not scale well beyond that point; it will simply notice its upload goes slow and paused from time to time, which is rather annoying.

Quoted 4 lines

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Quoted 15 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

The results for different bandwidths fio load is interesting. There are 8 threads dirtying pages at 1,2,4,..,128 MB/s rate. Due to different task bdi dirty limits, what happens is that three most aggresive tasks get throttled so they end up at bandwidths 24, 26, and 30 MB/s and the lighter dirtiers run unthrottled.

Quoted 6 lines
Quoted 4 lines

The base bandwidth based throttling can do better and provide almost perfect fairness, because all tasks writing to one bdi derive their own throttle bandwidth based on the same per-bdi base bandwidth. So the heavier dirtiers will converge to equal dirty rate and weight.

So what do you consider a perfect fairness in this case and are you sure
it is desirable? I was thinking about this and I'm not sure...

Perfect fairness could be 1, 2, 4, 8, N, N, N MB/s, where

Quoted 7 lines
Quoted 4 lines
        N = (write_bandwidth - 1 - 2 - 4 - 8) / 3.

I guess its usefulness is largely depending on the user space applications. Most of them should not be sensible to it.

I see, that makes some sense although it makes it advantageous to split
heavy dirtier task into two less heavy dirtiers which is a bit strange. But as you say, precise results here probably do not matter much.

Right.

Thanks,
Fengguang

author maintainer
#33 lore raw
Quoted 57 lines · Wu Fengguang

Hi Jan,

Quoted 54 lines · Jan Kara

Hello Fengguang,

Quoted 51 lines · Wu Fengguang
Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

OK.

Quoted 8 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Yeah, now both results are on the website. Let's see whether they are acceptable for others.

Quoted 7 lines
Quoted 5 lines

Yes. BTW, I think we'll discuss this at LSF so it would be beneficial if
we both prepared a fairly short explanation of our algorithm and some summary of the measured results. I think it would be good to keep each of us below 5 minutes so that we don't bore the audience - people will ask for details where they are interested... What do you think?

That looks good, however I'm not able to attend LSF this year, would you help show my slides?

Ah, that's a pity :(. If you send me a few slides I can show them, that's
no problem. I'll also try to understand your patches in enough detail so that I can answer possible questinons but author is always the best to present his work :).

Quoted 11 lines
Quoted 2 lines

I'll try to run also your patches on my setup to see how they work :) V6 from your website is the latest version, isn't it?

Thank you. You can run
http://git.kernel.org/?p=linux/kernel/git/wfg/writeback.git;a=shortlog;h=refs/heads/dirty-throttling-v6
or
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/dirty-throttling-v6-2.6.38-rc6.patch
whatever convenient for you.

If you are ready with v3, I can also help test it out and do some comparison on the results.

I have done a couple of smaller fixes but I don't expect them to affect
performance in the loads we use. But I'll send you the patches when I implement some significant change (but for that I need to reproduce the latencies you sometimes see first...).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#34 lore raw
Quoted 63 lines · Jan Kara
Quoted 62 lines · Wu Fengguang

Hi Jan,

Quoted 59 lines · Jan Kara

Hello Fengguang,

Quoted 45 lines · Wu Fengguang
Quoted 31 lines · Jan Kara

Hello Fengguang,

Quoted 23 lines · Wu Fengguang
Quoted 6 lines · Jan Kara

Hello,

I'm posting second version of my IO-less balance_dirty_pages() patches. This
is alternative approach to Fengguang's patches - much simpler I believe (only 300 lines added) - but obviously I does not provide so sophisticated control.

Well, it may be too early to claim "simplicity" as an advantage, until you achieve the following performance/feature comparability (most of them are not optional ones). AFAICS this work is kind of heavy lifting that will consume a lot of time and attention. You'd better find some more fundamental needs before go on the reworking.

(1)  latency
(2)  fairness
(3)  smoothness
(4)  scalability
(5)  per-task IO controller
(6)  per-cgroup IO controller (TBD)
(7)  free combinations of per-task/per-cgroup and bandwidth/priority controllers
(8)  think time compensation
(9)  backed by both theory and tests
Quoted 5 lines

(10) adapt pause time up on 100+ dirtiers
(11) adapt pause time down on low dirty pages
(12) adapt to new dirty threshold/goal
(13) safeguard against dirty exceeding
(14) safeguard against device queue underflow

Quoted 5 lines

I think this is a misunderstanding of my goals ;). My main goal is to
explore, how far we can get with a relatively simple approach to IO-less balance_dirty_pages(). I guess what I have is better than the current balance_dirty_pages() but it sure does not even try to provide all the features you try to provide.

OK.

Quoted 5 lines

I'm thinking about tweaking ratelimiting logic to reduce latencies in some tests, possibly add compensation when we waited for too long in balance_dirty_pages() (e.g. because of bumpy IO completion) but that's about it...

Quoted 6 lines
Quoted 3 lines

Basically I do this so that we can compare and decide whether what my simple approach offers is OK or whether we want some more complex solution like your patches...

Yeah, now both results are on the website. Let's see whether they are acceptable for others.

Yes. BTW, I think we'll discuss this at LSF so it would be beneficial if
we both prepared a fairly short explanation of our algorithm and some summary of the measured results. I think it would be good to keep each of us below 5 minutes so that we don't bore the audience - people will ask for details where they are interested... What do you think?

Quoted 6 lines
Quoted 2 lines

That looks good, however I'm not able to attend LSF this year, would you help show my slides?

Ah, that's a pity :(. If you send me a few slides I can show them, that's
no problem. I'll also try to understand your patches in enough detail so that I can answer possible questinons but author is always the best to present his work :).

Thank you very much :)

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

I'll try to run also your patches on my setup to see how they work :) V6 from your website is the latest version, isn't it?

Thank you. You can run
http://git.kernel.org/?p=linux/kernel/git/wfg/writeback.git;a=shortlog;h=refs/heads/dirty-throttling-v6
or
http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/dirty-throttling-v6-2.6.38-rc6.patch
whatever convenient for you.

Quoted 6 lines
Quoted 2 lines

If you are ready with v3, I can also help test it out and do some comparison on the results.

I have done a couple of smaller fixes but I don't expect them to affect
performance in the loads we use. But I'll send you the patches when I implement some significant change (but for that I need to reproduce the latencies you sometimes see first...).

OK. I can conveniently test the single disk cases. For JBOD and RAID cases, I don't own the servers so normally have to wait for some time before being able to carry out the tests..

Thanks,
Fengguang

#35 lore raw
In reply to Wu Fengguang
Quoted 9 lines · Wu Fengguang
Quoted 4 lines · Jan Kara

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

Quoted 7 lines

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Which is _bad_.

Increasing the writeback chunk size simply causes dirty queue starvation issues when there are lots of dirty files and lots more memory than there is writeback bandwidth. Think of a machine with 1TB of RAM (that's a 200GB dirty limit) and 1GB/s of disk throughput. Thats 3 minutes worth of writeback and increasing the chunk size to ~1s worth of throughput means that the 200th dirty file won't get serviced for 3 minutes....

We used to have behaviour similar to this this (prior to 2.6.16, IIRC), and it caused all sorts of problems where people were losing 10-15 minute old data when the system crashed because writeback didn't process the dirty inode list fast enough in the presence of lots of large files....

A small writeback chunk size has no adverse impact on XFS as long as the elevator does it's job of merging IOs (which in 99.9% of cases it does) so I'm wondering what the reason for making this change is.

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  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:"[email protected]"> [email protected] </a>
#36 lore raw
Quoted 32 lines · Dave Chinner

-printable
Content-Length: 2034
Lines: 51

Quoted 9 lines · Wu Fengguang
Quoted 4 lines · Jan Kara

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

Quoted 7 lines

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Which is _bad_.

Increasing the writeback chunk size simply causes dirty queue starvation issues when there are lots of dirty files and lots more memory than there is writeback bandwidth. Think of a machine with 1TB of RAM (that's a 200GB dirty limit) and 1GB/s of disk throughput. Thats 3 minutes worth of writeback and increasing the chunk size to ~1s worth of throughput means that the 200th dirty file won't get serviced for 3 minutes....

Quoted 5 lines

We used to have behaviour similar to this this (prior to 2.6.16, IIRC), and it caused all sorts of problems where people were losing 10-15 minute old data when the system crashed because writeback didn't process the dirty inode list fast enough in the presence of lots of large files....

Yes it is a problem, and can be best solved by automatically lowering bdi dirty limit to (bdi->write_bandwidth * dirty_expire_interval/100). Then we reliably control the lost data size to < 30s by default.

Quoted 4 lines

A small writeback chunk size has no adverse impact on XFS as long as the elevator does it's job of merging IOs (which in 99.9% of cases it does) so I'm wondering what the reason for making this change is.

It's explained in this changelog (is the XFS paragraph still valid?)

        https://patchwork.kernel.org/patch/605151/

The larger write chunk size generally helps ext4 and RAID setups.

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

Reviewed-by Christoph Hellwig
#37 lore raw
Quoted 39 lines · Wu Fengguang
Quoted 32 lines · Dave Chinner

-printable
Content-Length: 2034
Lines: 51

Quoted 9 lines · Wu Fengguang
Quoted 4 lines · Jan Kara

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

Quoted 7 lines

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Which is _bad_.

Increasing the writeback chunk size simply causes dirty queue starvation issues when there are lots of dirty files and lots more memory than there is writeback bandwidth. Think of a machine with 1TB of RAM (that's a 200GB dirty limit) and 1GB/s of disk throughput. Thats 3 minutes worth of writeback and increasing the chunk size to ~1s worth of throughput means that the 200th dirty file won't get serviced for 3 minutes....

Quoted 5 lines

We used to have behaviour similar to this this (prior to 2.6.16, IIRC), and it caused all sorts of problems where people were losing 10-15 minute old data when the system crashed because writeback didn't process the dirty inode list fast enough in the presence of lots of large files....

Quoted 3 lines

Yes it is a problem, and can be best solved by automatically lowering bdi dirty limit to (bdi->write_bandwidth * dirty_expire_interval/100). Then we reliably control the lost data size to < 30s by default.

Perhaps, though I see problems with that also. e.g. write bandwidth is 100MB/s (dirty limit ~= 3GB), then someone runs a find on the same disk and write bandwidth drops to 10MB/s (dirty limit changes to ~300MB). Then we are 10x over the new dirty limit and the writing application will be completely throttled for the next 270s until the dirty pages drop below the new dirty limit or the find stops.

IOWs, it changing IO workloads will cause interesting corner cases to be discovered and hence further complexity to handle effectively. And trying to diagnose problems because of such changes in IO load will be nigh on impossible - how would you gather sufficient information to determine that application A stalled for a minute because application B read a bunch of stuff from disk at the wrong time? Then how would you prove that you'd fixed the problem without introducing some other regression triggered by different workload changes?

Quoted 8 lines
Quoted 4 lines

A small writeback chunk size has no adverse impact on XFS as long as the elevator does it's job of merging IOs (which in 99.9% of cases it does) so I'm wondering what the reason for making this change is.

It's explained in this changelog (is the XFS paragraph still valid?)

        https://patchwork.kernel.org/patch/605151/

You mean this paragraph?

"According to Christoph, the current writeback size is way too small, and XFS had a hack that bumped out nr_to_write to four times the value sent by the VM to be able to saturate medium-sized RAID arrays. This value was also problematic for ext4 as well, as it caused large files to be come interleaved on disk by in 8 megabyte chunks (we bumped up the nr_to_write by a factor of two)."

We _used_ to have such a hack. It was there from 2.6.30 through to 2.6.35 - from when we realised writeback had bitrotted into badness to when we fixed the last set of bugs that the nr_to_write windup was papering over. between 2.6.30 and 2.6.35 we changed to dedicated flusher threads, got rid of congestion backoff, fixed up a bunch of queueing issues and finally stopped nr_to_write from going and staying negative and getting stuck on single inodes until they had no more dirty pages left. That was when this was committed:

commit 254c8c2dbf0e06a560a5814eb90cb628adb2de66

Author: Dave Chinner <[email protected]>
Date:   Wed Jun 9 10:37:19 2010 +1000

xfs: remove nr_to_write writeback windup.

Now that the background flush code has been fixed, we shouldn't need to silently multiply the wbc->nr_to_write to get good writeback. Remove that code.

And writeback throughput is now as good as it ever was....

Quoted 1 line

The larger write chunk size generally helps ext4 and RAID setups.

Is this still true with ext4's new submit_bio()-based writeback IO submission path that was copied from the XFS? It's a lot more efficient so should be much better on RAID setups.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#38 lore raw
Quoted 52 lines · Dave Chinner
Quoted 39 lines · Wu Fengguang
Quoted 32 lines · Dave Chinner

-printable
Content-Length: 2034
Lines: 51

Quoted 9 lines · Wu Fengguang
Quoted 4 lines · Jan Kara

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

Quoted 7 lines

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Which is _bad_.

Increasing the writeback chunk size simply causes dirty queue starvation issues when there are lots of dirty files and lots more memory than there is writeback bandwidth. Think of a machine with 1TB of RAM (that's a 200GB dirty limit) and 1GB/s of disk throughput. Thats 3 minutes worth of writeback and increasing the chunk size to ~1s worth of throughput means that the 200th dirty file won't get serviced for 3 minutes....

Quoted 5 lines

We used to have behaviour similar to this this (prior to 2.6.16, IIRC), and it caused all sorts of problems where people were losing 10-15 minute old data when the system crashed because writeback didn't process the dirty inode list fast enough in the presence of lots of large files....

Quoted 3 lines

Yes it is a problem, and can be best solved by automatically lowering bdi dirty limit to (bdi->write_bandwidth * dirty_expire_interval/100). Then we reliably control the lost data size to < 30s by default.

Perhaps, though I see problems with that also. e.g. write bandwidth is 100MB/s (dirty limit ~= 3GB), then someone runs a find on the same disk and write bandwidth drops to 10MB/s (dirty limit changes to ~300MB). Then we are 10x over the new dirty limit and the writing application will be completely throttled for the next 270s until the dirty pages drop below the new dirty limit or the find stops.

Quoted 9 lines

IOWs, it changing IO workloads will cause interesting corner cases to be discovered and hence further complexity to handle effectively. And trying to diagnose problems because of such changes in IO load will be nigh on impossible - how would you gather sufficient information to determine that application A stalled for a minute because application B read a bunch of stuff from disk at the wrong time? Then how would you prove that you'd fixed the problem without introducing some other regression triggered by different workload changes?

Good point. The v6 dirty throttle patchset has taken this into account, by separating the concept of dirty goal and hard dirty limit. Sorry I should have use bdi dirty goal in the previous email.

When for whatever reason the bdi dirty goal becomes a lot more smaller than bdi dirty pages, the bdi dirtiers will be throttled at typically lower than balanced bandwidth, so that the bdi dirty pages can smoothly drop to the dirty goal.

In the below graph, the bdi dirty pages start from much higher from bdi dirty goal because we start dd's on a USB stick and a hard disk at the same time, and the USB stick manage to accumulate lots of dirty pages before the dirty throttling logic starts to work. So you can see two dropping red lines in the (40s, 120s) time range. The green "position bandwidth" line shows that in that range, the tasks are throttled a most 1/8 lower than the balanced throttle bandwidth and restored to normal after 140s.

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/1UKEY+1HDD-3G/xfs-1dd-1M-8p-2945M-20%25-2.6.38-rc5-dt6+-2011-02-22-09-21/balance_dirty_pages-pages.png

This is the corresponding pause times. They are perfectly under control (less than the configurable 200ms max pause time).

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/1UKEY+1HDD-3G/xfs-1dd-1M-8p-2945M-20%25-2.6.38-rc5-dt6+-2011-02-22-09-21/balance_dirty_pages-pause.png

Actually the patchset does not set hard limit for bdi dirty pages at all. It only maintains one hard limit for the global dirty pages. That global hard limit is introduced exactly to handle your mentioned case.

https://patchwork.kernel.org/patch/605201/

+ * The global dirty threshold is normally equal to global dirty limit, 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.

Here "global dirty threshold" is the one returned by current global_dirty_limits(), the "global dirty limit" is default_backing_dev_info.dirty_threshold in the above patch. Sorry the names are a bit confusing..

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

A small writeback chunk size has no adverse impact on XFS as long as the elevator does it's job of merging IOs (which in 99.9% of cases it does) so I'm wondering what the reason for making this change is.

It's explained in this changelog (is the XFS paragraph still valid?)

        https://patchwork.kernel.org/patch/605151/
Quoted 8 lines

You mean this paragraph?

"According to Christoph, the current writeback size is way too small, and XFS had a hack that bumped out nr_to_write to four times the value sent by the VM to be able to saturate medium-sized RAID arrays. This value was also problematic for ext4 as well, as it caused large files to be come interleaved on disk by in 8 megabyte chunks (we bumped up the nr_to_write by a factor of two)."

Yes.

Quoted 19 lines

We _used_ to have such a hack. It was there from 2.6.30 through to 2.6.35 - from when we realised writeback had bitrotted into badness to when we fixed the last set of bugs that the nr_to_write windup was papering over. between 2.6.30 and 2.6.35 we changed to dedicated flusher threads, got rid of congestion backoff, fixed up a bunch of queueing issues and finally stopped nr_to_write from going and staying negative and getting stuck on single inodes until they had no more dirty pages left. That was when this was committed:

commit 254c8c2dbf0e06a560a5814eb90cb628adb2de66

Author: Dave Chinner <[email protected]>
Date:   Wed Jun 9 10:37:19 2010 +1000

xfs: remove nr_to_write writeback windup.

Now that the background flush code has been fixed, we shouldn't need to silently multiply the wbc->nr_to_write to get good writeback. Remove that code.

Quoted 5 lines

And writeback throughput is now as good as it ever was....

Glad to know about the improvements :)

Quoted 5 lines
Quoted 1 line

The larger write chunk size generally helps ext4 and RAID setups.

Is this still true with ext4's new submit_bio()-based writeback IO submission path that was copied from the XFS? It's a lot more efficient so should be much better on RAID setups.

I believe >4MB write chunk size will still help.. Although I have no real data to back it up for now.

On the other hand, are there chances for XFS to be hurt by the larger write chunk size?

Thanks,
Fengguang

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>

#39 lore raw
Quoted 81 lines · Wu Fengguang
Quoted 52 lines · Dave Chinner
Quoted 39 lines · Wu Fengguang
Quoted 32 lines · Dave Chinner

-printable
Content-Length: 2034
Lines: 51

Quoted 9 lines · Wu Fengguang
Quoted 4 lines · Jan Kara

And actually the NFS traces you pointed to originally seem to be different problem, in fact not directly related to what balance_dirty_pages() does... And with local filesystem the results seem to be reasonable (although there are some longer sleeps in your JBOD measurements I don't understand yet).

Yeah the NFS case can be improved on the FS side (for now you may just reuse my NFS patches and focus on other generic improvements).

Quoted 7 lines

The JBOD issue is also beyond my understanding.

Note that XFS will also see one big IO completion per 0.5-1 seconds, when we are to increase the write chunk size from the current 4MB to near the bdi's write bandwidth. As illustrated by this graph:

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/4G/xfs-1dd-1M-8p-3927M-20%25-2.6.38-rc6-dt6+-2011-02-27-22-58/global_dirtied_written-500.png

Which is _bad_.

Increasing the writeback chunk size simply causes dirty queue starvation issues when there are lots of dirty files and lots more memory than there is writeback bandwidth. Think of a machine with 1TB of RAM (that's a 200GB dirty limit) and 1GB/s of disk throughput. Thats 3 minutes worth of writeback and increasing the chunk size to ~1s worth of throughput means that the 200th dirty file won't get serviced for 3 minutes....

Quoted 5 lines

We used to have behaviour similar to this this (prior to 2.6.16, IIRC), and it caused all sorts of problems where people were losing 10-15 minute old data when the system crashed because writeback didn't process the dirty inode list fast enough in the presence of lots of large files....

Quoted 3 lines

Yes it is a problem, and can be best solved by automatically lowering bdi dirty limit to (bdi->write_bandwidth * dirty_expire_interval/100). Then we reliably control the lost data size to < 30s by default.

Perhaps, though I see problems with that also. e.g. write bandwidth is 100MB/s (dirty limit ~= 3GB), then someone runs a find on the same disk and write bandwidth drops to 10MB/s (dirty limit changes to ~300MB). Then we are 10x over the new dirty limit and the writing application will be completely throttled for the next 270s until the dirty pages drop below the new dirty limit or the find stops.

Quoted 9 lines

IOWs, it changing IO workloads will cause interesting corner cases to be discovered and hence further complexity to handle effectively. And trying to diagnose problems because of such changes in IO load will be nigh on impossible - how would you gather sufficient information to determine that application A stalled for a minute because application B read a bunch of stuff from disk at the wrong time? Then how would you prove that you'd fixed the problem without introducing some other regression triggered by different workload changes?

Good point. The v6 dirty throttle patchset has taken this into account, by separating the concept of dirty goal and hard dirty limit. Sorry I should have use bdi dirty goal in the previous email.

When for whatever reason the bdi dirty goal becomes a lot more smaller than bdi dirty pages, the bdi dirtiers will be throttled at typically lower than balanced bandwidth, so that the bdi dirty pages can smoothly drop to the dirty goal.

In the below graph, the bdi dirty pages start from much higher from bdi dirty goal because we start dd's on a USB stick and a hard disk at the same time, and the USB stick manage to accumulate lots of dirty pages before the dirty throttling logic starts to work. So you can see two dropping red lines in the (40s, 120s) time range. The green "position bandwidth" line shows that in that range, the tasks are throttled a most 1/8 lower than the balanced throttle bandwidth and restored to normal after 140s.

Quoted 1 line

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/1UKEY+1HDD-3G/xfs-1dd-1M-8p-2945M-20%25-2.6.38-rc5-dt6+-2011-02-22-09-21/balance_dirty_pages-pages.png

This is the comment that explains how the above behavior is achieved in code.

https://patchwork.kernel.org/patch/605161/

* (4) global/bdi control lines
*
* dirty_throttle_bandwidth() applies 2 main and 3 regional control lines for
* scaling up/down the base bandwidth based on the position of dirty pages. *
* The two main control lines for the global/bdi control scopes do not end at
* thresh/bdi_thresh. They are centered at setpoint/bdi_setpoint and cover the
* whole [0, limit]. If the control line drops below 0 before reaching @limit,
* an auxiliary line will be setup to connect them. The below figure illustrates
* the main bdi control line with an auxiliary line extending it to @limit. *
* This allows smoothly throttling down bdi_dirty back to normal if it starts
* high in situations like
* - start writing to a slow SD card and a fast disk at the same time. The SD
* card's bdi_dirty may rush to 5 times higher than bdi_setpoint.
* - the global/bdi dirty thresh/goal may be knocked down suddenly either on
* user request or on increased memory consumption.
*
* o
* o
* o [o] main control line
* o [*] auxiliary control line
* o
* o
* o
* o
* o
* o

 *                       o--------------------- balance point, bw scale = 1
 *                       | o
 *                       |   o
 *                       |     o
 *                       |       o
 *                       |         o
 *                       |           o
 *                       |             o------- connect point, bw scale = 1/2
 *                       |               .*
 *                       |                 .   *
 *                       |                   .      *
 *                       |                     .         *
 *                       |                       .           *
 *                       |                         .              *
 *                       |                           .                 *

* [--------------------*-----------------------------.--------------------*]
* 0 bdi_setpoint bdi_origin limit

Suppose two dirty page numbers

A B

At point B, the dirtiers will be throttled at roughly 1/4 balanced bandwidth (dirty rate == disk write rate). So under the control of the above control line, the bdi dirty pages will slowly decrease to A while the task's throttle bandwidth slowly increase to the balanced bandwidth.

Thanks,
Fengguang

Quoted 21 lines

This is the corresponding pause times. They are perfectly under control (less than the configurable 200ms max pause time).

http://www.kernel.org/pub/linux/kernel/people/wfg/writeback/dirty-throttling-v6/1UKEY+1HDD-3G/xfs-1dd-1M-8p-2945M-20%25-2.6.38-rc5-dt6+-2011-02-22-09-21/balance_dirty_pages-pause.png

Actually the patchset does not set hard limit for bdi dirty pages at all. It only maintains one hard limit for the global dirty pages. That global hard limit is introduced exactly to handle your mentioned case.

https://patchwork.kernel.org/patch/605201/

+ * The global dirty threshold is normally equal to global dirty limit, 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.

Here "global dirty threshold" is the one returned by current global_dirty_limits(), the "global dirty limit" is default_backing_dev_info.dirty_threshold in the above patch. Sorry the names are a bit confusing..