diff mbox series

[04/10] writeback use [global/wb]_domain_dirty_avail helper in cgwb_calc_thresh

Message ID 20240429034738.138609-5-shikemeng@huaweicloud.com (mailing list archive)
State New
Headers show
Series Add helper functions to remove repeated code and | expand

Commit Message

Kemeng Shi April 29, 2024, 3:47 a.m. UTC
Use [global/wb]_domain_dirty_avail helper in cgwb_calc_thresh to remove
repeated code.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 mm/page-writeback.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

Comments

Tejun Heo May 1, 2024, 4:56 p.m. UTC | #1
Hello,

On Mon, Apr 29, 2024 at 11:47:32AM +0800, Kemeng Shi wrote:
> Use [global/wb]_domain_dirty_avail helper in cgwb_calc_thresh to remove
> repeated code.

Maybe fold this into the patch to factor out domain_dirty_avail()?

> +	global_domain_dirty_avail(&gdtc, false);
> +	wb_domain_dirty_avail(&mdtc, false);

I'd just use domain_dirty_avail(). The compiler should be able to figure out
the branches and eliminate them and it removes an unnecessary source of
error.

Thanks.
Kemeng Shi May 6, 2024, 1:36 a.m. UTC | #2
on 5/2/2024 12:56 AM, Tejun Heo wrote:
> Hello,
> 
> On Mon, Apr 29, 2024 at 11:47:32AM +0800, Kemeng Shi wrote:
>> Use [global/wb]_domain_dirty_avail helper in cgwb_calc_thresh to remove
>> repeated code.
> 
> Maybe fold this into the patch to factor out domain_dirty_avail()?
> 
>> +	global_domain_dirty_avail(&gdtc, false);
>> +	wb_domain_dirty_avail(&mdtc, false);
> 
> I'd just use domain_dirty_avail(). The compiler should be able to figure out
> the branches and eliminate them and it removes an unnecessary source of
> error.
Sure, will this do this in next version.

Thanks.
> 
> Thanks.
>
diff mbox series

Patch

diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 28a29180fc9f..a1d48e8387ed 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -934,16 +934,9 @@  unsigned long cgwb_calc_thresh(struct bdi_writeback *wb)
 {
 	struct dirty_throttle_control gdtc = { GDTC_INIT_NO_WB };
 	struct dirty_throttle_control mdtc = { MDTC_INIT(wb, &gdtc) };
-	unsigned long filepages = 0, headroom = 0, writeback = 0;
-
-	gdtc.avail = global_dirtyable_memory();
-	gdtc.dirty = global_node_page_state(NR_FILE_DIRTY) +
-		     global_node_page_state(NR_WRITEBACK);
 
-	mem_cgroup_wb_stats(wb, &filepages, &headroom,
-			    &mdtc.dirty, &writeback);
-	mdtc.dirty += writeback;
-	mdtc_calc_avail(&mdtc, filepages, headroom);
+	global_domain_dirty_avail(&gdtc, false);
+	wb_domain_dirty_avail(&mdtc, false);
 	domain_dirty_limits(&mdtc);
 
 	return __wb_calc_thresh(&mdtc, mdtc.thresh);