Skip to contentSkip to conversation

mm/page-writeback: avoid unnecessary strictlimit background wakeups

PATCH Superseded Avi Weiss 3 participants 3 messages Oct 31 – Nov 5

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 mm/page-writeback: avoid unnecessary strictlimit background wakeups

balance_dirty_pages() includes pages under writeback in gdtc->wb_dirty when checking the per-wb background threshold for strictlimit BDIs. However, wb_over_bg_thresh() only considers reclaimable dirty pages when deciding whether to start more background writeback.

This can repeatedly wake the background worker even when there are too few dirty pages to write. In a 15-second FUSE writeback test, background wakeup requests dropped from 2657 to 682 (74% drop), while writeback_start events remained nearly unchanged at 99 and 98.

Check wb_over_bg_thresh() before starting background writeback through the strictlimit condition. Leave the global background threshold check and the wakeup required for dirty throttling unchanged.

Fixes 0437906841d0 ("mm: start background writeback based on per-wb threshold for strictlimit BDIs")
---
 mm/page-writeback.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page-writeback.c +2 -1
index 499a35473e4f..cb0c58715b93 100644
@@ -1826,7 +1826,8 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
 
 		if (!writeback_in_progress(wb) &&
 		    (nr_dirty > gdtc->bg_thresh ||
-		     (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh)))
+		     (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh &&
+		      wb_over_bg_thresh(wb))))
 			wb_start_background_writeback(wb);
 
 		/*

base-commit: 36aad21d50d1af3f6954bb0c988257a908202477

Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Avi Weiss

balance_dirty_pages() includes pages under writeback in gdtc->wb_dirty when checking the per-wb background threshold for strictlimit BDIs. However, wb_over_bg_thresh() only considers reclaimable dirty pages when deciding whether to start more background writeback.

This can repeatedly wake the background worker even when there are too few dirty pages to write. In a 15-second FUSE writeback test, background wakeup requests dropped from 2657 to 682 (74% drop), while writeback_start events remained nearly unchanged at 99 and 98.

Check wb_over_bg_thresh() before starting background writeback through the strictlimit condition. Leave the global background threshold check and the wakeup required for dirty throttling unchanged.

Fixes 0437906841d0 ("mm: start background writeback based on per-wb threshold for strictlimit BDIs")
---
 mm/page-writeback.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page-writeback.c +0 -0
index 499a35473e4f..cb0c58715b93 100644

mm/page-writeback.c static int balance_dirty_pages(struct bdi_writeback *wb, · line 1832

Quoted 8 lines
mm/page-writeback.c +2 -1
@@ -1826,7 +1826,8 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
 
                if (!writeback_in_progress(wb) &&
                    (nr_dirty > gdtc->bg_thresh ||
-                    (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh)))
+                    (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh &&
+                     wb_over_bg_thresh(wb))))
                        wb_start_background_writeback(wb);
 

Thanks for the fix. It looks right to me. I think an alternative way would be to save the wb_reclaimable value computed in wb_dirty_limits() in struct dirty_throttle_control and just check if "gdtc->wb_reclaimable > gdtc->wb_bg_thresh" which avoids the extra wb_over_bg_thresh() calculations (but is slightly less precise for the memcg case), but I don't think it matters much either way.

Thanks,
Joanne

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Avi Weiss
Quoted 6 lines · Avi Weiss

balance_dirty_pages() includes pages under writeback in gdtc->wb_dirty when checking the per-wb background threshold for strictlimit BDIs. However, wb_over_bg_thresh() only considers reclaimable dirty pages when deciding whether to start more background writeback.

Quoted 8 lines

This can repeatedly wake the background worker even when there are too few dirty pages to write. In a 15-second FUSE writeback test, background wakeup requests dropped from 2657 to 682 (74% drop), while writeback_start events remained nearly unchanged at 99 and 98.

Check wb_over_bg_thresh() before starting background writeback through the strictlimit condition. Leave the global background threshold check and the wakeup required for dirty throttling unchanged.

I assume you've left the gdtc->wb_dirty > gdtc->wb_bg_thresh check in to reduce times when wb_over_bg_thresh() is called (because it is relatively costly and this condition is evaluated relatively often)? Maybe it would be good to add there a comment with explanation like:

/*
* gdtc->wb_dirty includes pages under writeback so it serves only as a
* quick check and we use wb_over_bg_thresh() for exact evaluation whether
* a wakeup is needed
*/

Quoted 2 lines
Fixes 0437906841d0 ("mm: start background writeback based on per-wb threshold for strictlimit BDIs")

Otherwise the patch looks good so feel free to add:

Honza

Quoted 23 lines
---
 mm/page-writeback.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page-writeback.c +2 -1
index 499a35473e4f..cb0c58715b93 100644
@@ -1826,7 +1826,8 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
 
 		if (!writeback_in_progress(wb) &&
 		    (nr_dirty > gdtc->bg_thresh ||
-		     (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh)))
+		     (strictlimit && gdtc->wb_dirty > gdtc->wb_bg_thresh &&
+		      wb_over_bg_thresh(wb))))
 			wb_start_background_writeback(wb);
 
 		/*

base-commit: 36aad21d50d1af3f6954bb0c988257a908202477

Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR