From: Julian Sun <sunjunchao@bytedance.com>
To: linux-block@vger.kernel.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org
Cc: axboe@kernel.dk, hannes@cmpxchg.org, mhocko@kernel.org,
roman.gushchin@linux.dev, shakeel.butt@linux.dev,
muchun.song@linux.dev, willy@infradead.org, jack@suse.cz,
tj@kernel.org, akpm@linux-foundation.org
Subject: [PATCH v7 3/3] writeback: record bdev targets in foreign writeback tracepoints
Date: Mon, 21 Sep 2026 20:06:58 +0800 [thread overview]
Message-ID: <20260921120658.1627992-4-sunjunchao@bytedance.com> (raw)
In-Reply-To: <20260921120658.1627992-1-sunjunchao@bytedance.com>
Add dev to track_foreign_dirty and flush_foreign so traces can
distinguish foreign-wb tracking from the bdev-only path. Append the
field to each event and print it as major:minor; zero denotes the
normal foreign-wb path.
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
include/trace/events/writeback.h | 22 ++++++++++++++--------
mm/memcontrol.c | 7 +++++--
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index 13ee076ccd16..ffd1b8df4231 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -273,9 +273,9 @@ TRACE_EVENT(inode_switch_wbs,
TRACE_EVENT(track_foreign_dirty,
- TP_PROTO(struct folio *folio, struct bdi_writeback *wb),
+ TP_PROTO(struct folio *folio, struct bdi_writeback *wb, dev_t dev),
- TP_ARGS(folio, wb),
+ TP_ARGS(folio, wb, dev),
TP_STRUCT__entry(
__array(char, name, 32)
@@ -284,6 +284,7 @@ TRACE_EVENT(track_foreign_dirty,
__field(u64, cgroup_ino)
__field(u64, page_cgroup_ino)
__field(unsigned int, memcg_id)
+ __field(dev_t, dev)
),
TP_fast_assign(
@@ -295,34 +296,37 @@ TRACE_EVENT(track_foreign_dirty,
__entry->ino = inode ? inode->i_ino : 0;
__entry->memcg_id = wb->memcg_css->id;
__entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
+ __entry->dev = dev;
rcu_read_lock();
__entry->page_cgroup_ino = cgroup_ino(folio_memcg(folio)->css.cgroup);
rcu_read_unlock();
),
- TP_printk("bdi %s[%llu]: ino=%llu memcg_id=%u cgroup_ino=%llu page_cgroup_ino=%llu",
+ TP_printk("bdi %s[%llu]: ino=%llu memcg_id=%u cgroup_ino=%llu page_cgroup_ino=%llu dev=%u:%u",
__entry->name,
__entry->bdi_id,
__entry->ino,
__entry->memcg_id,
__entry->cgroup_ino,
- __entry->page_cgroup_ino
+ __entry->page_cgroup_ino,
+ MAJOR(__entry->dev), MINOR(__entry->dev)
)
);
TRACE_EVENT(flush_foreign,
TP_PROTO(struct bdi_writeback *wb, unsigned int frn_bdi_id,
- unsigned int frn_memcg_id),
+ unsigned int frn_memcg_id, dev_t dev),
- TP_ARGS(wb, frn_bdi_id, frn_memcg_id),
+ TP_ARGS(wb, frn_bdi_id, frn_memcg_id, dev),
TP_STRUCT__entry(
__array(char, name, 32)
__field(u64, cgroup_ino)
__field(unsigned int, frn_bdi_id)
__field(unsigned int, frn_memcg_id)
+ __field(dev_t, dev)
),
TP_fast_assign(
@@ -330,13 +334,15 @@ TRACE_EVENT(flush_foreign,
__entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
__entry->frn_bdi_id = frn_bdi_id;
__entry->frn_memcg_id = frn_memcg_id;
+ __entry->dev = dev;
),
- TP_printk("bdi %s: cgroup_ino=%llu frn_bdi_id=%u frn_memcg_id=%u",
+ TP_printk("bdi %s: cgroup_ino=%llu frn_bdi_id=%u frn_memcg_id=%u dev=%u:%u",
__entry->name,
__entry->cgroup_ino,
__entry->frn_bdi_id,
- __entry->frn_memcg_id
+ __entry->frn_memcg_id,
+ MAJOR(__entry->dev), MINOR(__entry->dev)
)
);
#endif
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 494540cf6278..6c3083fcc063 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3959,11 +3959,12 @@ void mem_cgroup_track_foreign_dirty_slowpath(struct folio *folio,
if (memcg_bdev_frn_wq && bdev_inode &&
sb_is_blkdev_sb(bdev_inode->i_sb)) {
+ trace_track_foreign_dirty(folio, wb, bdev_inode->i_rdev);
mem_cgroup_track_foreign_bdev(memcg, bdev_inode->i_rdev);
return;
}
- trace_track_foreign_dirty(folio, wb);
+ trace_track_foreign_dirty(folio, wb, 0);
/*
* Pick the slot to use. If there is already a slot for @wb, keep
@@ -4029,6 +4030,7 @@ void mem_cgroup_flush_foreign(struct bdi_writeback *wb)
if (memcg_bdev_frn_wq && time_after64(ctx->at, now - intv) &&
atomic_cmpxchg(&ctx->inflight, 0, 1) == 0) {
ctx->at = 0;
+ trace_flush_foreign(wb, 0, 0, ctx->dev);
queue_work(memcg_bdev_frn_wq, &ctx->work);
}
}
@@ -4045,7 +4047,8 @@ void mem_cgroup_flush_foreign(struct bdi_writeback *wb)
if (time_after64(frn->at, now - intv) &&
atomic_read(&frn->done.cnt) == 1) {
frn->at = 0;
- trace_flush_foreign(wb, frn->bdi_id, frn->memcg_id);
+ trace_flush_foreign(wb, frn->bdi_id, frn->memcg_id,
+ 0);
cgroup_writeback_by_id(frn->bdi_id, frn->memcg_id,
WB_REASON_FOREIGN_FLUSH,
&frn->done);
--
2.39.5
prev parent reply other threads:[~2026-09-21 12:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 12:06 [PATCH v7 0/3] memcg,writeback: flush foreign bdev mappings separately Julian Sun
2026-09-21 12:06 ` [PATCH v7 1/3] block: introduce bdev_flush_by_dev() Julian Sun
2026-09-21 12:06 ` [PATCH v7 2/3] memcg,writeback: flush foreign bdev mappings separately from owner wbs Julian Sun
2026-09-21 17:55 ` Tejun Heo
2026-09-22 9:52 ` Julian Sun
2026-09-21 12:06 ` Julian Sun [this message]
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=20260921120658.1627992-4-sunjunchao@bytedance.com \
--to=sunjunchao@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=willy@infradead.org \
/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