Skip to contentSkip to conversation

mm: stop balance_dirty_pages doing too much work

RFC PATCH In review Richard Kennedy 6 participants 22 messages Jun 24, 2009 – Aug 7, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 mm: stop balance_dirty_pages doing too much work

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

---
balance_dirty_pages can overreact and move all of the dirty pages to writeback unnecessarily.

balance_dirty_pages makes its decision to throttle based on the number of dirty plus writeback pages that are over the calculated limit,so it will continue to move pages even when there are plenty of pages in writeback and less than the threshold still dirty.

This allows it to overshoot its limits and move all the dirty pages to writeback while waiting for the drives to catch up and empty the writeback list.

A simple fio test easily demonstrates this problem.

fio --name=f1 --directory=/disk1 --size=2G -rw=write

	--name=f2 --directory=/disk2 --size=1G --rw=write 		--startdelay=10

The attached graph before.png shows how all pages are moved to writeback as the second write starts and the throttling kicks in.

after.png is the same test with the patch applied, which clearly shows that it keeps dirty_background_ratio dirty pages in the buffer. The values and timings of the graphs are only approximate but are good enough to show the behaviour.

This is the simplest fix I could find, but I'm not entirely sure that it alone will be enough for all cases. But it certainly is an improvement on my desktop machine writing to 2 disks.

Do we need something more for machines with large arrays where bdi_threshold * number_of_drives is greater than the dirty_ratio ?

regards
Richard

This patch against 2.6.30 git latest, built and tested on x86_64.

mm/page-writeback.c +4 -1
index 7b0dcea..7687879 100644
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * filesystems (i.e. NFS) in which data may have been
 		 * written to the server's write cache, but has not yet
 		 * been flushed to permanent storage.
+		 * Only move pages to writeback if this bdi is over its
+		 * threshold otherwise wait until the disk writes catch
+		 * up.
 		 */
-		if (bdi_nr_reclaimable) {
+		if (bdi_nr_reclaimable > bdi_thresh) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,
maintainer
#1 lore raw
Quoted 33 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

---
balance_dirty_pages can overreact and move all of the dirty pages to writeback unnecessarily.

balance_dirty_pages makes its decision to throttle based on the number of dirty plus writeback pages that are over the calculated limit,so it will continue to move pages even when there are plenty of pages in writeback and less than the threshold still dirty.

This allows it to overshoot its limits and move all the dirty pages to writeback while waiting for the drives to catch up and empty the writeback list.

A simple fio test easily demonstrates this problem.

fio --name=f1 --directory=/disk1 --size=2G -rw=write

	--name=f2 --directory=/disk2 --size=1G --rw=write 		--startdelay=10

The attached graph before.png shows how all pages are moved to writeback as the second write starts and the throttling kicks in.

after.png is the same test with the patch applied, which clearly shows that it keeps dirty_background_ratio dirty pages in the buffer. The values and timings of the graphs are only approximate but are good enough to show the behaviour.

Quoted 7 lines

This is the simplest fix I could find, but I'm not entirely sure that it alone will be enough for all cases. But it certainly is an improvement on my desktop machine writing to 2 disks.

Do we need something more for machines with large arrays where bdi_threshold * number_of_drives is greater than the dirty_ratio ?

um. Interesting find. Jens, was any of your performance testing using multiple devices? If so, it looks like the results just got invalidated :)

Quoted 8 lines
mm/page-writeback.c +0 -0
index 7b0dcea..7687879 100644
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * filesystems (i.e. NFS) in which data may have been
 		 * written to the server's write cache, but has not yet

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

Quoted 10 lines
mm/page-writeback.c +4 -1
 		 * been flushed to permanent storage.
+		 * Only move pages to writeback if this bdi is over its
+		 * threshold otherwise wait until the disk writes catch
+		 * up.
 		 */
-		if (bdi_nr_reclaimable) {
+		if (bdi_nr_reclaimable > bdi_thresh) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

yup, we need to think about the effect with zillions of disks. Peter, could you please take a look?

Also... get_dirty_limits() is rather hard to grok. The callers of get_dirty_limits() treat its three return values as "thresholds", but they're not named as thresholds within get_dirty_limits() itself, which is a bit confusing. And the meaning of each of those return values is pretty obscure from the code - could we document them please?

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 40 lines · Andrew Morton
Quoted 37 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

---
balance_dirty_pages can overreact and move all of the dirty pages to writeback unnecessarily.

balance_dirty_pages makes its decision to throttle based on the number of dirty plus writeback pages that are over the calculated limit,so it will continue to move pages even when there are plenty of pages in writeback and less than the threshold still dirty.

This allows it to overshoot its limits and move all the dirty pages to writeback while waiting for the drives to catch up and empty the writeback list.

A simple fio test easily demonstrates this problem.

fio --name=f1 --directory=/disk1 --size=2G -rw=write

	--name=f2 --directory=/disk2 --size=1G --rw=write 		--startdelay=10

The attached graph before.png shows how all pages are moved to writeback as the second write starts and the throttling kicks in.

after.png is the same test with the patch applied, which clearly shows that it keeps dirty_background_ratio dirty pages in the buffer. The values and timings of the graphs are only approximate but are good enough to show the behaviour.

This is the simplest fix I could find, but I'm not entirely sure that it alone will be enough for all cases. But it certainly is an improvement on my desktop machine writing to 2 disks.

Quoted 6 lines
Quoted 3 lines

Do we need something more for machines with large arrays where bdi_threshold * number_of_drives is greater than the dirty_ratio ?

um. Interesting find. Jens, was any of your performance testing using multiple devices? If so, it looks like the results just got invalidated :)

"invalidated" is a bit too much I think, skewed is more like it. But most of my testing has been on a single spindle, only the very first patches used 10 disks as a test base.

Quoted 21 lines
Quoted 7 lines
mm/page-writeback.c +0 -0
index 7b0dcea..7687879 100644
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * filesystems (i.e. NFS) in which data may have been
 		 * written to the server's write cache, but has not yet

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

Quoted 10 lines
mm/page-writeback.c +4 -1
 		 * been flushed to permanent storage.
+		 * Only move pages to writeback if this bdi is over its
+		 * threshold otherwise wait until the disk writes catch
+		 * up.
 		 */
-		if (bdi_nr_reclaimable) {
+		if (bdi_nr_reclaimable > bdi_thresh) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

yup, we need to think about the effect with zillions of disks. Peter, could you please take a look?

Quoted 5 lines

Also... get_dirty_limits() is rather hard to grok. The callers of get_dirty_limits() treat its three return values as "thresholds", but they're not named as thresholds within get_dirty_limits() itself, which is a bit confusing. And the meaning of each of those return values is pretty obscure from the code - could we document them please?

This is indeed a pretty interesting find!

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
In reply to Andrew Morton
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

---

[ moved explanation below ]

Quoted 13 lines
Quoted 13 lines
mm/page-writeback.c +3 -0
index 7b0dcea..7687879 100644
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * filesystems (i.e. NFS) in which data may have been
 		 * written to the server's write cache, but has not yet
 		 * been flushed to permanent storage.
+		 * Only move pages to writeback if this bdi is over its
+		 * threshold otherwise wait until the disk writes catch
+		 * up.
 		 */
Quoted 8 lines

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

Quoted 5 lines
mm/page-writeback.c +1 -1
-		if (bdi_nr_reclaimable) {
+		if (bdi_nr_reclaimable > bdi_thresh) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

yup, we need to think about the effect with zillions of disks. Peter, could you please take a look?

Looks to have been in that form forever (immediate git history).

When reading the code I read it like:

		if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh)
			break;

		if (nr_reclaimable + nr_writeback <
				(background_thresh + dirty_thresh) / 2)
			break;

		if (bdi_nr_reclaimable) {
			writeback_inodes(&wbc);

Which to me reads:

- if there's not enough to do, drop out
- see if background write-out can catch up, drop out
- is there anything to do, yay! work.

/me goes read the changelog, maybe there's a clue in there :-)

Quoted 11 lines
Quoted 11 lines

balance_dirty_pages can overreact and move all of the dirty pages to writeback unnecessarily.

balance_dirty_pages makes its decision to throttle based on the number of dirty plus writeback pages that are over the calculated limit,so it will continue to move pages even when there are plenty of pages in writeback and less than the threshold still dirty.

This allows it to overshoot its limits and move all the dirty pages to writeback while waiting for the drives to catch up and empty the writeback list.

Ahhh, indeed, how silly of me not to notice that before!

Quoted 3 lines
Quoted 3 lines

This is the simplest fix I could find, but I'm not entirely sure that it alone will be enough for all cases. But it certainly is an improvement on my desktop machine writing to 2 disks.

Seems good to me.

Quoted 2 lines
Quoted 2 lines

Do we need something more for machines with large arrays where bdi_threshold * number_of_drives is greater than the dirty_ratio ?

[ I assumed s/dirty_ratio/dirty_thresh/, since dirty_ratio is a ratio
and bdi_threshold is an actual value, therefore the inequality above doesn't make sense ]

That cannot actually happen (aside from small numerical glitches).

bdi_threshold = P_i * dirty_thresh, where \Sum P_i = 1

The proportion is relative to the recent writeout speed of the device.

Quoted 5 lines · Andrew Morton

Also... get_dirty_limits() is rather hard to grok. The callers of get_dirty_limits() treat its three return values as "thresholds", but they're not named as thresholds within get_dirty_limits() itself, which is a bit confusing. And the meaning of each of those return values is pretty obscure from the code - could we document them please?

Does something like this help?

mm/page-writeback.c +7 -0
index 7b0dcea..dc2cee1 100644
@@ -426,6 +426,13 @@ unsigned long determine_dirtyable_memory(void)
 	return x + 1;	/* Ensure that we never return 0 */
 }
 
+/*
+ * get_dirty_limits() - compute the various dirty limits
+ *
+ * @pbackground - dirty limit at which we want to start background write-out
+ * @pdirty	- total dirty limit, we should not have more dirty than this
+ * @pdbi_dirty	- the share of @pdirty available to @bdi
+ */
 void
 get_dirty_limits(unsigned long *pbackground, unsigned long *pdirty,
 		 unsigned long *pbdi_dirty, struct backing_dev_info *bdi)

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
Quoted 35 lines · Jens Axboe
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Results for writeback without the bdi_thresh patch

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

wb-bdi_thresh   211MB/sec       22.71%  53.30%   4050   91.19%
wb-bdi_thresh   212MB/sec       22.78%  53.55%   4809   91.51%
wb-bdi_thresh   212MB/sec       22.99%  54.23%   4715   93.10%

Not a lot of difference there, without more than three runs it's hard to say what is significant. Could be a small decrease in throughput, if the 208MB/sec results from above is an outlier (I think it is, ~215MB/sec is usually the most consistent result).

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
Quoted 49 lines · Jens Axboe
Quoted 35 lines · Jens Axboe
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton

On Wed, 24 Jun 2009 11:38:24 +0100

Quoted 6 lines · Richard Kennedy

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Results for writeback without the bdi_thresh patch

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

Quoted 8 lines
wb-bdi_thresh   211MB/sec       22.71%  53.30%   4050   91.19%
wb-bdi_thresh   212MB/sec       22.78%  53.55%   4809   91.51%
wb-bdi_thresh   212MB/sec       22.99%  54.23%   4715   93.10%

Not a lot of difference there, without more than three runs it's hard to say what is significant. Could be a small decrease in throughput, if the 208MB/sec results from above is an outlier (I think it is, ~215MB/sec is usually the most consistent result).

What's the iowait on these runs?

Thanks!

--
Al

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 54 lines · Al Boldi
Quoted 53 lines · Jens Axboe
Quoted 35 lines · Jens Axboe
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton

On Wed, 24 Jun 2009 11:38:24 +0100

Quoted 6 lines · Richard Kennedy

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Results for writeback without the bdi_thresh patch

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

wb-bdi_thresh   211MB/sec       22.71%  53.30%   4050   91.19%
wb-bdi_thresh   212MB/sec       22.78%  53.55%   4809   91.51%
wb-bdi_thresh   212MB/sec       22.99%  54.23%   4715   93.10%
Quoted 6 lines
Quoted 4 lines

Not a lot of difference there, without more than three runs it's hard to say what is significant. Could be a small decrease in throughput, if the 208MB/sec results from above is an outlier (I think it is, ~215MB/sec is usually the most consistent result).

What's the iowait on these runs?

Not sure, I didn't check. Why do you ask?

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw
Quoted 56 lines · Jens Axboe
Quoted 55 lines · Al Boldi
Quoted 54 lines · Jens Axboe
Quoted 36 lines · Jens Axboe
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Andrew Morton

On Wed, 24 Jun 2009 11:38:24 +0100

Quoted 7 lines · Richard Kennedy

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Results for writeback without the bdi_thresh patch

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

wb-bdi_thresh   211MB/sec       22.71%  53.30%   4050   91.19%
wb-bdi_thresh   212MB/sec       22.78%  53.55%   4809   91.51%
wb-bdi_thresh   212MB/sec       22.99%  54.23%   4715   93.10%
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Not a lot of difference there, without more than three runs it's hard to say what is significant. Could be a small decrease in throughput, if the 208MB/sec results from above is an outlier (I think it is, ~215MB/sec is usually the most consistent result).

What's the iowait on these runs?

Not sure, I didn't check. Why do you ask?

iowait gives you an indication of seekactivity.

Thanks!

--
Al

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw
Quoted 62 lines · Al Boldi
Quoted 61 lines · Jens Axboe
Quoted 60 lines · Al Boldi
Quoted 58 lines · Jens Axboe
Quoted 36 lines · Jens Axboe
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Andrew Morton

On Wed, 24 Jun 2009 11:38:24 +0100

Quoted 7 lines · Richard Kennedy

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Results for writeback without the bdi_thresh patch

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

wb-bdi_thresh   211MB/sec       22.71%  53.30%   4050   91.19%
wb-bdi_thresh   212MB/sec       22.78%  53.55%   4809   91.51%
wb-bdi_thresh   212MB/sec       22.99%  54.23%   4715   93.10%

Not a lot of difference there, without more than three runs it's hard to say what is significant. Could be a small decrease in throughput, if the 208MB/sec results from above is an outlier (I think it is, ~215MB/sec is usually the most consistent result).

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

What's the iowait on these runs?

Not sure, I didn't check. Why do you ask?

iowait gives you an indication of seekactivity.

The test case is random mmap writes to files that have been laid out sequentially. So it's all seeks. The target drive is an SSD disk though, so it doesn't matter a whole lot (it's a good SSD).

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw
Quoted 3 lines · Jens Axboe

The test case is random mmap writes to files that have been laid out sequentially. So it's all seeks. The target drive is an SSD disk though, so it doesn't matter a whole lot (it's a good SSD).

Oh, SSD. What numbers do you get for normal disks?

Thanks!

--
Al

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
Quoted 6 lines · Al Boldi
Quoted 3 lines · Jens Axboe

The test case is random mmap writes to files that have been laid out sequentially. So it's all seeks. The target drive is an SSD disk though, so it doesn't matter a whole lot (it's a good SSD).

Oh, SSD. What numbers do you get for normal disks?

I haven't run this particular test on rotating storage. The type of drive should not matter a lot, I'm mostly interested in comparing vanilla and the writeback patches on identical workloads and storage.

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw
Quoted 11 lines · Jens Axboe
Quoted 6 lines · Al Boldi
Quoted 3 lines · Jens Axboe

The test case is random mmap writes to files that have been laid out sequentially. So it's all seeks. The target drive is an SSD disk though, so it doesn't matter a whole lot (it's a good SSD).

Oh, SSD. What numbers do you get for normal disks?

I haven't run this particular test on rotating storage. The type of drive should not matter a lot, I'm mostly interested in comparing vanilla and the writeback patches on identical workloads and storage.

I think drive type matters a lot. Access strategy on drives with high seek delays differs from those with no seek delays. So it would probably be of interest to see this test run on rotating storage, unless the writeback patches are only meant for SSD?

Thanks!

--
Al

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
Quoted 9 lines · Al Boldi
Quoted 8 lines · Jens Axboe
Quoted 6 lines · Al Boldi
Quoted 3 lines · Jens Axboe

The test case is random mmap writes to files that have been laid out sequentially. So it's all seeks. The target drive is an SSD disk though, so it doesn't matter a whole lot (it's a good SSD).

Oh, SSD. What numbers do you get for normal disks?

Quoted 8 lines
Quoted 3 lines

I haven't run this particular test on rotating storage. The type of drive should not matter a lot, I'm mostly interested in comparing vanilla and the writeback patches on identical workloads and storage.

I think drive type matters a lot. Access strategy on drives with high seek delays differs from those with no seek delays. So it would probably be of interest to see this test run on rotating storage, unless the writeback patches are only meant for SSD?

Don't get me wrong, I've tested a lot on rotating drives too. The changelog for one of the patches even mentions results and vmstat for a 10 disk setup, all rotating disks.

What I'm saying is that this particular test is tailored for SSD's and writeback. The patchset is not for SSD's in particular, it applies equally across the board (even for non-block IO, like NFS).

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#14 lore raw
In reply to Jens Axboe
Quoted 35 lines · Jens Axboe
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Intriguing numbers. It would tell us a lot if we could find out why vanilla + patch is slower than vanilla. I'll run some tests using mmap and see if I can find anything.
What block size are you using ?

I see that the last test of each group is the slowest. I wonder if this is showing a slowdown over time or just noise? Any chance you could run more tests in each group?

regards
Richard

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw
Quoted 45 lines · Richard Kennedy
Quoted 35 lines · Jens Axboe
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 24 Jun 2009 11:38:24 +0100 Richard Kennedy <[email protected]>…

When writing to 2 (or more) devices at the same time, stop balance_dirty_pages moving dirty pages to writeback when it has reached the bdi threshold. This prevents balance_dirty_pages overshooting its limits and moving all dirty pages to writeback.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

---

After doing some integration and update work on the writeback branch, I threw 2.6.31-rc1, 2.6.31-rc1+patch, 2.6.31-rc1+writeback into the test mix. The writeback series include this patch as a prep patch. Results for the mmap write test case:

Kernel Throughput usr sys ctx util
--------------------------------------------------------------

vanilla         184MB/sec       19.51%  50.49%  12995   82.88%
vanilla         184MB/sec       19.60%  50.77%  12846   83.47%
vanilla         182MB/sec       19.25%  51.18%  14692   82.76%
vanilla+patch   169MB/sec       18.08%  43.61%   9507   76.38%
vanilla+patch   170MB/sec       18.37%  43.46%  10275   76.62%
vanilla+patch   165MB/sec       17.59%  42.06%  10165   74.39%
writeback       215MB/sec       22.69%  53.23%   4085   92.32%
writeback       214MB/sec       24.31%  52.90%   4495   92.40%
writeback       208MB/sec       23.14%  52.12%   4067   91.68%

To be perfectly clear:

Quoted 8 lines
vanilla         2.6.31-rc1 stock
vanilla+patch   2.6.31-rc1 + bdi_thresh patch
writeback       2.6.31-rc1 + bdi_thresh patch + writeback series

This is just a single spindle w/ext4, nothing fancy. I'll do a 3-series run with the writeback and this patch backed out, to see if it makes a difference here. I didn't do that initially, since the results were in the range that I expected.

Quoted 4 lines

Intriguing numbers. It would tell us a lot if we could find out why vanilla + patch is slower than vanilla. I'll run some tests using mmap and see if I can find anything.
What block size are you using ?

It's using 4kb block size.

Quoted 3 lines

I see that the last test of each group is the slowest. I wonder if this is showing a slowdown over time or just noise? Any chance you could run more tests in each group?

The runs are actually inverted, so the last entry is the first run. It's a bit confusing. So the first run is usually the odd one out, after that they are stable.

Signature · 7 lines
Jens Axboe

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw
In reply to Richard Kennedy
Quoted 43 lines · Richard Kennedy

---
balance_dirty_pages can overreact and move all of the dirty pages to writeback unnecessarily.

balance_dirty_pages makes its decision to throttle based on the number of dirty plus writeback pages that are over the calculated limit,so it will continue to move pages even when there are plenty of pages in writeback and less than the threshold still dirty.

This allows it to overshoot its limits and move all the dirty pages to writeback while waiting for the drives to catch up and empty the writeback list.

A simple fio test easily demonstrates this problem.

fio --name=f1 --directory=/disk1 --size=2G -rw=write

	--name=f2 --directory=/disk2 --size=1G --rw=write 		--startdelay=10

The attached graph before.png shows how all pages are moved to writeback as the second write starts and the throttling kicks in.

after.png is the same test with the patch applied, which clearly shows that it keeps dirty_background_ratio dirty pages in the buffer. The values and timings of the graphs are only approximate but are good enough to show the behaviour.

This is the simplest fix I could find, but I'm not entirely sure that it alone will be enough for all cases. But it certainly is an improvement on my desktop machine writing to 2 disks.

Do we need something more for machines with large arrays where bdi_threshold * number_of_drives is greater than the dirty_ratio ?

mm/page-writeback.c +0 -0
index 7b0dcea..7687879 100644
@@ -541,8 +541,11 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * filesystems (i.e. NFS) in which data may have been
 		 * written to the server's write cache, but has not yet

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

Quoted 10 lines
mm/page-writeback.c +4 -1
 		 * been flushed to permanent storage.
+		 * Only move pages to writeback if this bdi is over its
+		 * threshold otherwise wait until the disk writes catch
+		 * up.
 		 */
-		if (bdi_nr_reclaimable) {
+		if (bdi_nr_reclaimable > bdi_thresh) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page-writeback.c +1 -1
index 81627eb..92f42d6 100644
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw
Quoted 1 line · Peter Zijlstra

On Wed, 2009-06-24 at 11:38 +0100, Richard Kennedy wrote:

...

Quoted 28 lines

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index 81627eb..92f42d6 100644

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

Quoted 8 lines
mm/page-writeback.c +1 -1
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

I'll run some tests and let you know :)

But what if someone has changed the vm settings? Maybe something like
(bdi_thresh * dirty_background_ratio / dirty_ratio)
might be better ?

Chris, what sort of workload are you having problems with?

regards
Richard

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw
Quoted 41 lines · Richard Kennedy
Quoted 1 line · Peter Zijlstra

On Wed, 2009-06-24 at 11:38 +0100, Richard Kennedy wrote:

....

Quoted 28 lines

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page-writeback.c +0 -0
index 81627eb..92f42d6 100644

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

Quoted 8 lines
mm/page-writeback.c +1 -1
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,

I'll run some tests and let you know :)

Quoted 4 lines

But what if someone has changed the vm settings? Maybe something like
(bdi_thresh * dirty_background_ratio / dirty_ratio)
might be better ?

Yeah, but that's a mult and a div extra, all that really matters is being able to generate plenty of IO. I think the 1/2 approximation should suffice, but we'll see.

Thanks for testing.

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw
In reply to Richard Kennedy
Quoted 24 lines · Richard Kennedy
Quoted 1 line · Peter Zijlstra

On Wed, 2009-06-24 at 11:38 +0100, Richard Kennedy wrote:

...

Quoted 21 lines

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines

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

Quoted 10 lines
mm/page-writeback.c +1 -1
index 81627eb..92f42d6 100644
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {

My patch had two extra spaces ;)

Quoted 5 lines

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

Quoted 5 lines
mm/page-writeback.c +0 -0
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,
Quoted 8 lines

I'll run some tests and let you know :)

But what if someone has changed the vm settings? Maybe something like
(bdi_thresh * dirty_background_ratio / dirty_ratio)
might be better ?

Chris, what sort of workload are you having problems with?

So, buffered writeback in general has a bunch of interesting features right now, and to be honest I'm having a hard time untangling all of it. It doesn't help that each of our filesystems is reacting differently.

Btrfs and XFS both use helper threads to process IO completion. This means that we tend to collect more writeback pages than the other filesystems do.

The end result of this is that O_DIRECT is dramatically faster than buffered on every streaming write workload I've tried. I'm still trying to sort out exactly where buffered IO is going wrong.

-chris

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw
Quoted 60 lines · Chris Mason
Quoted 24 lines · Richard Kennedy
Quoted 1 line · Peter Zijlstra

On Wed, 2009-06-24 at 11:38 +0100, Richard Kennedy wrote:

...

Quoted 21 lines

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines

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

Quoted 10 lines
mm/page-writeback.c +1 -1
index 81627eb..92f42d6 100644
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {

My patch had two extra spaces ;)

Quoted 5 lines

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

Quoted 5 lines
mm/page-writeback.c +0 -0
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,
Quoted 8 lines

I'll run some tests and let you know :)

But what if someone has changed the vm settings? Maybe something like
(bdi_thresh * dirty_background_ratio / dirty_ratio)
might be better ?

Chris, what sort of workload are you having problems with?

So, buffered writeback in general has a bunch of interesting features right now, and to be honest I'm having a hard time untangling all of it. It doesn't help that each of our filesystems is reacting differently.

Btrfs and XFS both use helper threads to process IO completion. This means that we tend to collect more writeback pages than the other filesystems do.

Quoted 6 lines

The end result of this is that O_DIRECT is dramatically faster than buffered on every streaming write workload I've tried. I'm still trying to sort out exactly where buffered IO is going wrong.

-chris

Yes, it's all pretty complex.
With a large number of pages in writeback do you think that the total dirty pages goes over the threshold ?
I do wonder how long we get stuck in congestion_wait, it may be interesting to see if reducing its timeout has any effect.

I've been experimenting with rewriting balance_dirty_pages to reduce the number of calls to global_page_state. Those counters share a cacheline and are fairly hot. So far it's looking good & improving simple write performance particularly when the write size is just over the dirty threshold.

regard
Richard

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw
Quoted 65 lines · Richard Kennedy
Quoted 64 lines · Chris Mason
Quoted 24 lines · Richard Kennedy
Quoted 1 line · Peter Zijlstra

On Wed, 2009-06-24 at 11:38 +0100, Richard Kennedy wrote:

...

Quoted 21 lines

OK, so Chris ran into this bit yesterday, complaining that he'd only get very few write requests and couldn't saturate his IO channel.

Now, since writing out everything once there's something to do sucks for Richard, but only writing out stuff when we're over the limit sucks for Chris (since we can only be over the limit a little), the best thing would be to only write out when we're over the background limit. Since that is the low watermark we use for throttling it makes sense that we try to write out when above that.

However, since there's a lack of bdi_background_thresh, and I don't think introducing one just for this is really justified. How about the below?

Chris how did this work for you? Richard, does this make things suck for you again?

---
 mm/page-writeback.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines

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

Quoted 10 lines
mm/page-writeback.c +1 -1
index 81627eb..92f42d6 100644
@@ -545,7 +545,7 @@ static void balance_dirty_pages(struct address_space *mapping)
 		 * threshold otherwise wait until the disk writes catch
 		 * up.
 		 */
-		if (bdi_nr_reclaimable > bdi_thresh) {
+		if (bdi_nr_reclaimable > bdi_thresh/2) {

My patch had two extra spaces ;)

Quoted 5 lines

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

Quoted 5 lines
mm/page-writeback.c +0 -0
 			writeback_inodes(&wbc);
 			pages_written += write_chunk - wbc.nr_to_write;
 			get_dirty_limits(&background_thresh, &dirty_thresh,
Quoted 8 lines

I'll run some tests and let you know :)

But what if someone has changed the vm settings? Maybe something like
(bdi_thresh * dirty_background_ratio / dirty_ratio)
might be better ?

Chris, what sort of workload are you having problems with?

So, buffered writeback in general has a bunch of interesting features right now, and to be honest I'm having a hard time untangling all of it. It doesn't help that each of our filesystems is reacting differently.

Btrfs and XFS both use helper threads to process IO completion. This means that we tend to collect more writeback pages than the other filesystems do.

The end result of this is that O_DIRECT is dramatically faster than buffered on every streaming write workload I've tried. I'm still trying to sort out exactly where buffered IO is going wrong.

Quoted 7 lines
Quoted 2 lines

-chris

Yes, it's all pretty complex.
With a large number of pages in writeback do you think that the total dirty pages goes over the threshold ?
I do wonder how long we get stuck in congestion_wait, it may be interesting to see if reducing its timeout has any effect.

I've done a few more tests here, and running with Peter's patch doesn't really change the results for either XFS or Btrfs. The real reason his patch was helping me at first was because it was forcing the btrfs code into writepages more often.

I also did a run with congestion_wait(1) instead of HZ/10, and it also didn't make much difference at all.

The only way I've been able to get buffered writeback closer to to O_DIRECT writeback is just by increasing the number of pages that get written (wbc.nr_to_write).

On Btrfs I'm testing with a patch that extends nr_to_write to cover the full extent if delalloc is done (up to a limit of 32MB), which is another way of saying it is covering a larger range of pages the FS knows to be contiguous on disk.

-chris

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>