summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorYu Kuai <yukuai@fygo.io>2026-06-08 11:42:48 +0800
committerJens Axboe <axboe@kernel.dk>2026-06-24 06:42:31 -0600
commitf928145cbcb52544203808f159461d0a25543df7 (patch)
tree0201c905471e68e84e7f2242bd236ba194c3d336 /mm
parent4cfd7c1cff8f4c863b99d420cdbe0563802a9e80 (diff)
downloadlinux-f928145cbcb52544203808f159461d0a25543df7.tar.gz
linux-f928145cbcb52544203808f159461d0a25543df7.zip
mm/page_io: don't nest queue_lock under rcu in bio_associate_blkg_from_page()
Take a css reference under RCU, drop RCU, and then associate the bio with the blkg. This avoids nesting queue_lock under RCU and prepares to protect blkcg with blkcg_mutex instead of queue_lock. Use css_tryget() instead of css_tryget_online() so swap writeback for pages charged to a dying memcg still passes the dying css to bio_associate_blkg_from_css(). That preserves the existing closest-live ancestor fallback instead of charging those bios to the root blkg. Signed-off-by: Yu Kuai <yukuai@fygo.io> Link: https://patch.msgid.link/c910d2c39d3ec97f67de68af636a52394342d55f.1780621988.git.yukuai@fygo.io Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'mm')
-rw-r--r--mm/page_io.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/mm/page_io.c b/mm/page_io.c
index a59b73f8bdd9..c96d3e4cf872 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -317,8 +317,13 @@ static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio)
rcu_read_lock();
memcg = folio_memcg(folio);
css = cgroup_e_css(memcg->css.cgroup, &io_cgrp_subsys);
- bio_associate_blkg_from_css(bio, css);
+ if (!css || !css_tryget(css))
+ css = NULL;
rcu_read_unlock();
+
+ bio_associate_blkg_from_css(bio, css);
+ if (css)
+ css_put(css);
}
#else
#define bio_associate_blkg_from_page(bio, folio) do { } while (0)