From: "Xin Yin" <yinxin.x@bytedance.com>
To: "Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>
Cc: "Tejun Heo" <tj@kernel.org>, "Jens Axboe" <axboe@kernel.dk>,
<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Xin Yin" <yinxin.x@bytedance.com>
Subject: [PATCH v1 1/2] writeback: size foreign flushes by target wb dirty pages
Date: Tue, 8 Sep 2026 11:23:51 +0800 [thread overview]
Message-ID: <a889bf70370d17fec0731b60cf393d8cc7cf145d.1788836830.git.yinxin.x@bytedance.com> (raw)
In-Reply-To: <cover.1788836830.git.yinxin.x@bytedance.com>
Foreign dirty tracking records the bdi and wb memcg IDs of recently
dirtied foreign inodes. When the source memcg needs foreign writeback,
mem_cgroup_flush_foreign() queues WB_REASON_FOREIGN_FLUSH to the
recorded target bdi_writeback.
cgroup_writeback_by_id() currently sizes this best-effort work from the
target memcg's NR_FILE_DIRTY counter. The work is scoped to one target
wb, so a memcg-wide dirty count can over-size a single-bdi flush when
the target memcg has dirty pages on other devices. It can also under-size
the flush when the target wb has dirty pages charged to other memcgs.
Over-sizing keeps the target wb busy longer and can delay later
writeback work. Under-sizing can finish before enough pages are written
back for the source memcg.
Use the target wb's WB_RECLAIMABLE counter and keep the existing 25%
headroom. This keeps the budget aligned with the writeback object being
queued.
Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing")
Signed-off-by: Xin Yin <yinxin.x@bytedance.com>
---
fs/fs-writeback.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 7c75ed7e8979..7c2340a5dead 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1131,7 +1131,7 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id,
struct cgroup_subsys_state *memcg_css;
struct bdi_writeback *wb;
struct wb_writeback_work *work;
- unsigned long dirty;
+ long dirty;
int ret;
/* lookup bdi and memcg */
@@ -1160,16 +1160,13 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id,
}
/*
- * The caller is attempting to write out most of
- * the currently dirty pages. Let's take the current dirty page
- * count and inflate it by 25% which should be large enough to
- * flush out most dirty pages while avoiding getting livelocked by
- * concurrent dirtiers.
- *
- * BTW the memcg stats are flushed periodically and this is best-effort
- * estimation, so some potential error is ok.
+ * The caller is attempting to write out most of the target wb's
+ * currently dirty pages. Size the work from the wb's reclaimable pages
+ * and inflate the count by 25%, which should be large enough to flush
+ * out most dirty pages while avoiding getting livelocked by concurrent
+ * dirtiers.
*/
- dirty = memcg_page_state(mem_cgroup_from_css(memcg_css), NR_FILE_DIRTY);
+ dirty = wb_stat_sum(wb, WB_RECLAIMABLE);
dirty = dirty * 10 / 8;
/* issue the writeback work */
--
2.20.1
next prev parent reply other threads:[~2026-09-08 3:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 3:23 [PATCH v1 0/2] writeback: bound foreign dirty flushing Xin Yin
2026-09-08 3:23 ` Xin Yin [this message]
2026-09-08 10:44 ` [PATCH v1 1/2] writeback: size foreign flushes by target wb dirty pages Jan Kara
2026-09-08 19:47 ` Tejun Heo
2026-09-08 3:23 ` [PATCH v1 2/2] writeback: snapshot foreign flush pages Xin Yin
2026-09-08 11:01 ` Jan Kara
2026-09-09 2:08 ` 尹欣
2026-09-11 11:08 ` Jan Kara
2026-09-11 13:43 ` 尹欣
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a889bf70370d17fec0731b60cf393d8cc7cf145d.1788836830.git.yinxin.x@bytedance.com \
--to=yinxin.x@bytedance.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®