Foreign dirty flushing handles cases where a dirtied folio's memcg and the memcg owning its inode wb differ. wbc_detach_inode() notes that "concurrent write sharing of an inode is expected to be very rare". This expectation does not hold for bdev inodes. A bdev inode and mapping are shared by buffered users of the block device, while the inode has a single wb owner. On ext4, buffer-cache folios used by metadata and journal I/O can therefore be charged to different memcgs while sharing the same mapping. Normal bdev activity can thus produce frequent folio/wb ownership mismatches. This was reproduced on cgroup v2 with the memory and I/O controllers enabled, using ext4 on a loop device. jbd2 repeatedly generated track_foreign_dirty events for bdev folios charged to unrelated memcgs. When one of those memcgs entered dirty throttling, the resulting record led to a flush_foreign event and queued writeback with reason=foreign_flush for the bdev inode's root wb. Skip foreign dirty tracking when the folio mapping's host inode is on the blockdev pseudo superblock. This prevents bdev-originated records from triggering later foreign flushes. The tradeoff is that dirty throttling in the folio's memcg no longer uses bdev dirtiness to queue writeback on the bdev inode's owner wb. Those folios remain subject to normal writeback. This is preferable because a single bdev wb owner does not identify which cgroup is responsible for a mapping shared by buffered bdev users. Flushing it can write back data unrelated to the throttled memcg. Dirty accounting, normal writeback, and foreign dirty tracking for non-bdev inodes remain unchanged. Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Julian Sun --- mm/memcontrol.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1271d390b617..5d7320f76c06 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3898,6 +3898,11 @@ void mem_cgroup_track_foreign_dirty_slowpath(struct folio *folio, u64 oldest_at = now; int oldest = -1; int i; + struct address_space *mapping = folio_mapping(folio); + struct inode *bdev_inode = mapping ? mapping->host : NULL; + + if (bdev_inode && sb_is_blkdev_sb(bdev_inode->i_sb)) + return; trace_track_foreign_dirty(folio, wb); -- 2.39.5