* [PATCH 0/2] mm: fix memcg_data reads during a THP split
@ 2026-11-04 9:59 Daejun Park via B4 Relay
2026-11-04 9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay
2026-11-06 8:57 ` [PATCH 0/2] mm: fix memcg_data reads during a THP split Tao Yi
0 siblings, 2 replies; 7+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-04 9:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin,
Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan,
Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache,
Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan,
Brendan Jackman, linux-mm, cgroups, linux-kernel, stable,
Daejun Park
Tao Yi reported an oops in page_cgroup_ino() while reading
/proc/kpagecgroup and traced it to the THP split in an RFC [1]. The
RFC skips frozen folios in the reader. Patch 1 moves the memcg_data
copy in the split instead. Patch 2 orders the same loads in
page_owner and needs patch 1.
Charged large kmalloc pages are frozen, so the RFC would report them
as uncharged. My review of the RFC [2] got no reply. Tested on x86_64
with KASAN, see patch 1.
[1] https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/
[2] https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/
---
Daejun Park (2):
mm/huge_memory: set memcg_data before a split page leaves the folio
mm/page_owner: also check PageTail before reading memcg_data
mm/huge_memory.c | 17 +++++++++++++----
mm/memcontrol.c | 9 ++++++++-
mm/page_owner.c | 7 +++++++
3 files changed, 28 insertions(+), 5 deletions(-)
---
base-commit: a13b500946e5dc467976838572b8ddd2fd777ca7
change-id: 20261028-kpagecgroup-split-8a749c6ee27e
Best regards,
--
Daejun Park <daejun7.park@samsung.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio 2026-11-04 9:59 [PATCH 0/2] mm: fix memcg_data reads during a THP split Daejun Park via B4 Relay @ 2026-11-04 9:59 ` Daejun Park via B4 Relay 2026-11-04 16:33 ` Zi Yan 2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch Andrew Morton 2026-11-06 8:57 ` [PATCH 0/2] mm: fix memcg_data reads during a THP split Tao Yi 1 sibling, 2 replies; 7+ messages in thread From: Daejun Park via B4 Relay @ 2026-11-04 9:59 UTC (permalink / raw) To: Andrew Morton Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan, Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan, Brendan Jackman, linux-mm, cgroups, linux-kernel, stable, Daejun Park From: Daejun Park <daejun7.park@samsung.com> __split_folio_to_order() copies memcg_data to a new folio after clear_compound_head(). Until then, memcg_data of the first tail page holds the folio's _nr_pages. page_cgroup_ino() can see that page as a folio in the window and take _nr_pages for an objcg pointer. Reading /proc/kpagecgroup as root then oopses while folios are split to order 0. Copy memcg_data before the smp_wmb(), as before commit fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()"). Add the paired smp_rmb() to page_cgroup_ino(). Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()") Reported-by: Tao Yi <escape@deepseek.com> Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ Cc: stable@vger.kernel.org Signed-off-by: Daejun Park <daejun7.park@samsung.com> --- Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an 8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64 THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6 of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had no oops. Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const pointers, so a stable backport needs "struct folio *folio" there. The hunk applies to those trees without a conflict, and the build then fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers). --- mm/huge_memory.c | 17 +++++++++++++---- mm/memcontrol.c | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 14599d0fff..adc5a47ee7 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order, if (folio_test_swapcache(folio)) new_folio->swap.val = folio->swap.val + i; - /* Page flags must be visible before we make the page non-compound. */ +#ifdef CONFIG_MEMCG + /* + * In the first tail page, memcg_data still holds + * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(), + * page_owner) read memcg_data once the page is not a tail. + */ + new_folio->memcg_data = folio->memcg_data; +#endif + + /* + * Page flags and memcg_data must be visible before we make the + * page non-compound. + */ smp_wmb(); /* @@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order, folio_set_young(new_folio); if (folio_test_idle(folio)) folio_set_idle(new_folio); -#ifdef CONFIG_MEMCG - new_folio->memcg_data = folio->memcg_data; -#endif folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 84f4a8fd4d..c244d56446 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo */ ino_t page_cgroup_ino(const struct page *page) { + const struct folio *folio; struct mem_cgroup *memcg; unsigned long ino = 0; rcu_read_lock(); /* page_folio() is racy here, but the entire function is racy anyway */ - memcg = folio_memcg_check(page_folio(page)); + folio = page_folio(page); + /* + * Order the memcg_data load after the compound_info load in + * page_folio(). Pairs with smp_wmb() in __split_folio_to_order(). + */ + smp_rmb(); + memcg = folio_memcg_check(folio); while (memcg && !css_is_online(&memcg->css)) memcg = parent_mem_cgroup(memcg); -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio 2026-11-04 9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay @ 2026-11-04 16:33 ` Zi Yan 2026-11-05 1:06 ` Daejun Park 2026-12-01 5:24 ` Andrew Morton 2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch Andrew Morton 1 sibling, 2 replies; 7+ messages in thread From: Zi Yan @ 2026-11-04 16:33 UTC (permalink / raw) To: daejun7.park, Andrew Morton Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, David Hildenbrand, Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan, Brendan Jackman, linux-mm, cgroups, linux-kernel, stable On Wed Nov 4, 2026 at 4:59 AM EST, Daejun Park via B4 Relay wrote: > From: Daejun Park <daejun7.park@samsung.com> > > __split_folio_to_order() copies memcg_data to a new folio after > clear_compound_head(). Until then, memcg_data of the first tail page > holds the folio's _nr_pages. page_cgroup_ino() can see that page as a > folio in the window and take _nr_pages for an objcg pointer. Reading > /proc/kpagecgroup as root then oopses while folios are split to > order 0. > > Copy memcg_data before the smp_wmb(), as before commit fa23a338de93 > ("mm: separate folio_split_memcg_refs() from split_page_memcg()"). Add > the paired smp_rmb() to page_cgroup_ino(). > > Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()") > Reported-by: Tao Yi <escape@deepseek.com> > Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ > Cc: stable@vger.kernel.org > Signed-off-by: Daejun Park <daejun7.park@samsung.com> > --- > Tested on x86_64 with KASAN (7.3-rc7 and mm-hotfixes-unstable) in an > 8-vCPU QEMU guest: six threads read /proc/kpagecgroup for page 1 of 64 > THPs that debugfs split_huge_pages splits to order 0. Base oopsed in 6 > of 6 runs, 4 of them within 1.5 s. With patch 1, 8 runs of 300 s had > no oops. > > Before 7.4, page_cgroup_ino() and folio_memcg_check() take non-const > pointers, so a stable backport needs "struct folio *folio" there. The > hunk applies to those trees without a conflict, and the build then > fails with CONFIG_WERROR=y (-Wdiscarded-qualifiers). > --- > mm/huge_memory.c | 17 +++++++++++++---- > mm/memcontrol.c | 9 ++++++++- > 2 files changed, 21 insertions(+), 5 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 14599d0fff..adc5a47ee7 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3768,7 +3768,19 @@ static void __split_folio_to_order(struct folio *folio, int old_order, > if (folio_test_swapcache(folio)) > new_folio->swap.val = folio->swap.val + i; > > - /* Page flags must be visible before we make the page non-compound. */ > +#ifdef CONFIG_MEMCG > + /* > + * In the first tail page, memcg_data still holds > + * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(), > + * page_owner) read memcg_data once the page is not a tail. > + */ How about? Because clear_compound_head() makes the new_folio be recognized as a folio by reference-free readers. Assign memcg data before clear_compound_head(), so lockless, reference-free readers get the right value instead of bogus data from the overlaid ->_nr_pages in the first tail page. > + new_folio->memcg_data = folio->memcg_data; > +#endif > + > + /* > + * Page flags and memcg_data must be visible before we make the > + * page non-compound. > + */ > smp_wmb(); > > /* > @@ -3803,9 +3815,6 @@ static void __split_folio_to_order(struct folio *folio, int old_order, > folio_set_young(new_folio); > if (folio_test_idle(folio)) > folio_set_idle(new_folio); > -#ifdef CONFIG_MEMCG > - new_folio->memcg_data = folio->memcg_data; > -#endif > > folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); > } > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 84f4a8fd4d..c244d56446 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -375,12 +375,19 @@ struct cgroup_subsys_state *get_mem_cgroup_css_from_folio(const struct folio *fo > */ > ino_t page_cgroup_ino(const struct page *page) > { > + const struct folio *folio; > struct mem_cgroup *memcg; > unsigned long ino = 0; > > rcu_read_lock(); > /* page_folio() is racy here, but the entire function is racy anyway */ > - memcg = folio_memcg_check(page_folio(page)); > + folio = page_folio(page); > + /* > + * Order the memcg_data load after the compound_info load in > + * page_folio(). Pairs with smp_wmb() in __split_folio_to_order(). > + */ > + smp_rmb(); > + memcg = folio_memcg_check(folio); > > while (memcg && !css_is_online(&memcg->css)) > memcg = parent_mem_cgroup(memcg); Otherwise, LGTM. Thanks. Reviewed-by: Zi Yan <ziy@nvidia.com> -- Best Regards, Yan, Zi ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE:(2) [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio 2026-11-04 16:33 ` Zi Yan @ 2026-11-05 1:06 ` Daejun Park 2026-12-01 5:24 ` Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Daejun Park @ 2026-11-05 1:06 UTC (permalink / raw) To: Zi Yan, Andrew Morton Cc: Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, David Hildenbrand, Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan, Brendan Jackman, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Daejun Park On Wed Nov 4, 2026 at 11:33 AM EST, Zi Yan wrote: > Assign memcg data before clear_compound_head(), so lockless, > reference-free readers get the right value instead of bogus data from > the overlaid ->_nr_pages in the first tail page. Thanks, agreed. Your wording says why the assignment has to come before clear_compound_head(), which my comment left implicit. Thanks, Daejun ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio 2026-11-04 16:33 ` Zi Yan 2026-11-05 1:06 ` Daejun Park @ 2026-12-01 5:24 ` Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Andrew Morton @ 2026-12-01 5:24 UTC (permalink / raw) To: Zi Yan Cc: daejun7.park, Tao Yi, Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, David Hildenbrand, Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan, Brendan Jackman, linux-mm, cgroups, linux-kernel, stable On Wed, 04 Nov 2026 11:33:17 -0500 "Zi Yan" <ziy@nvidia.com> wrote: > On Wed Nov 4, 2026 at 4:59 AM EST, Daejun Park via B4 Relay wrote: > > From: Daejun Park <daejun7.park@samsung.com> > > > > __split_folio_to_order() copies memcg_data to a new folio after > > clear_compound_head(). Until then, memcg_data of the first tail page > > holds the folio's _nr_pages. page_cgroup_ino() can see that page as a > > folio in the window and take _nr_pages for an objcg pointer. Reading > > /proc/kpagecgroup as root then oopses OK, so it's an oopser, normally requiring root to trigger it. > > +#ifdef CONFIG_MEMCG > > + /* > > + * In the first tail page, memcg_data still holds > > + * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(), > > + * page_owner) read memcg_data once the page is not a tail. > > + */ > > How about? Because clear_compound_head() makes the new_folio be > recognized as a folio by reference-free readers. > > Assign memcg data before clear_compound_head(), so lockless, > reference-free readers get the right value instead of bogus data from > the overlaid ->_nr_pages in the first tail page. Thanks both, I queued this -fix, Looks suitable? +++ a/mm/huge_memory.c @@ -3860,9 +3860,10 @@ static void __split_folio_to_order(struc #ifdef CONFIG_MEMCG /* - * In the first tail page, memcg_data still holds - * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(), - * page_owner) read memcg_data once the page is not a tail. + * clear_compound_head() makes new_folio visible as a folio to + * lockless, reference-free PFN walkers. In the first tail page, + * memcg_data overlays folio->_nr_pages. Set it before clearing + * compound_head so readers cannot mistake _nr_pages for an objcg. */ new_folio->memcg_data = folio->memcg_data; #endif _ ^ permalink raw reply [flat|nested] 7+ messages in thread
* + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch 2026-11-04 9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay 2026-11-04 16:33 ` Zi Yan @ 2026-12-01 5:25 ` Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Andrew Morton @ 2026-12-01 5:25 UTC (permalink / raw) To: mm-commits, ziy, willy, vbabka, usama.arif, surenb, stable, shakeel.butt, ryan.roberts, roman.gushchin, nico.pache, muchun.song, mhocko, liam, lance.yang, kas, hannes, escape, dev.jain, david, brendan.jackman, baolin.wang, baohua, daejun7.park, akpm The patch titled Subject: mm/huge_memory: set memcg_data before a split page leaves the folio has been added to the -mm mm-new branch. Its filename is mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Daejun Park <daejun7.park@samsung.com> Subject: mm/huge_memory: set memcg_data before a split page leaves the folio Date: Wed, 04 Nov 2026 18:59:08 +0900 Patch series "mm: fix memcg_data reads during a THP split". Tao Yi reported an oops in page_cgroup_ino() while reading /proc/kpagecgroup and traced it to the THP split in an RFC [1]. The RFC skips frozen folios in the reader. Patch 1 moves the memcg_data copy in the split instead. Patch 2 orders the same loads in page_owner and needs patch 1. Charged large kmalloc pages are frozen, so the RFC would report them as uncharged. My review of the RFC [2] got no reply. Tested on x86_64 with KASAN, see patch 1. This patch (of 2): __split_folio_to_order() copies memcg_data to a new folio after clear_compound_head(). Until then, memcg_data of the first tail page holds the folio's _nr_pages. page_cgroup_ino() can see that page as a folio in the window and take _nr_pages for an objcg pointer. Reading /proc/kpagecgroup as root then oopses while folios are split to order 0. Copy memcg_data before the smp_wmb(), as before commit fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()"). Add the paired smp_rmb() to page_cgroup_ino(). Link: https://lore.kernel.org/20261104-kpagecgroup-split-v1-0-f70e947fec85@samsung.com Link: https://patch.msgid.link/20261104-kpagecgroup-split-v1-1-f70e947fec85@samsung.com Link: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ [1] Link: https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/ [2] Fixes: fa23a338de93 ("mm: separate folio_split_memcg_refs() from split_page_memcg()") Signed-off-by: Daejun Park <daejun7.park@samsung.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reported-by: Tao Yi <escape@deepseek.com> Closes: https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ Reviewed-by: Zi Yan <ziy@nvidia.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Muchun Song <muchun.song@linux.dev> Cc: David Hildenbrand <david@kernel.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Liam R. Howlett <liam@infradead.org> Cc: Nico Pache <nico.pache@linux.dev> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Barry Song <baohua@kernel.org> Cc: Lance Yang <lance.yang@linux.dev> Cc: Usama Arif <usama.arif@linux.dev> Cc: Kiryl Shutsemau <kas@kernel.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Brendan Jackman <brendan.jackman@linux.dev> Cc: <stable@vger.kernel.org> mm/huge_memory.c | 17 +++++++++++++---- mm/memcontrol.c | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) --- a/mm/huge_memory.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio +++ a/mm/huge_memory.c @@ -3858,7 +3858,19 @@ static void __split_folio_to_order(struc if (folio_test_swapcache(folio)) new_folio->swap.val = folio->swap.val + i; - /* Page flags must be visible before we make the page non-compound. */ +#ifdef CONFIG_MEMCG + /* + * In the first tail page, memcg_data still holds + * folio->_nr_pages. Lockless PFN walkers (page_cgroup_ino(), + * page_owner) read memcg_data once the page is not a tail. + */ + new_folio->memcg_data = folio->memcg_data; +#endif + + /* + * Page flags and memcg_data must be visible before we make the + * page non-compound. + */ smp_wmb(); /* @@ -3889,9 +3901,6 @@ static void __split_folio_to_order(struc folio_set_young(new_folio); if (folio_test_idle(folio)) folio_set_idle(new_folio); -#ifdef CONFIG_MEMCG - new_folio->memcg_data = folio->memcg_data; -#endif folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); } --- a/mm/memcontrol.c~mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio +++ a/mm/memcontrol.c @@ -373,12 +373,19 @@ struct cgroup_subsys_state *get_mem_cgro */ ino_t page_cgroup_ino(const struct page *page) { + const struct folio *folio; struct mem_cgroup *memcg; unsigned long ino = 0; rcu_read_lock(); /* page_folio() is racy here, but the entire function is racy anyway */ - memcg = folio_memcg_check(page_folio(page)); + folio = page_folio(page); + /* + * Order the memcg_data load after the compound_info load in + * page_folio(). Pairs with smp_wmb() in __split_folio_to_order(). + */ + smp_rmb(); + memcg = folio_memcg_check(folio); while (memcg && !css_is_online(&memcg->css)) memcg = parent_mem_cgroup(memcg); _ Patches currently in -mm which might be from daejun7.park@samsung.com are mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch mm-page_owner-also-check-pagetail-before-reading-memcg_data.patch ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] mm: fix memcg_data reads during a THP split 2026-11-04 9:59 [PATCH 0/2] mm: fix memcg_data reads during a THP split Daejun Park via B4 Relay 2026-11-04 9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay @ 2026-11-06 8:57 ` Tao Yi 1 sibling, 0 replies; 7+ messages in thread From: Tao Yi @ 2026-11-06 8:57 UTC (permalink / raw) To: daejun7.park Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt, Muchun Song, David Hildenbrand, Zi Yan, Matthew Wilcox, Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Vlastimil Babka, Suren Baghdasaryan, Brendan Jackman, linux-mm, cgroups, linux-kernel, stable, Andrew Morton Hi Daejun, Sorry, I missed your email on the RFC thread. Thanks for following up and for taking care of the fix. 在 2026/11/4 17:59, Daejun Park via B4 Relay 写道: > Tao Yi reported an oops in page_cgroup_ino() while reading > /proc/kpagecgroup and traced it to the THP split in an RFC [1]. The > RFC skips frozen folios in the reader. Patch 1 moves the memcg_data > copy in the split instead. Patch 2 orders the same loads in > page_owner and needs patch 1. > > Charged large kmalloc pages are frozen, so the RFC would report them > as uncharged. My review of the RFC [2] got no reply. Tested on x86_64 > with KASAN, see patch 1. > > [1] https://lore.kernel.org/all/20260907124001.1544655-1-escape@deepseek.com/ > [2] https://lore.kernel.org/all/20261028040418epcms2p7ac0f584cdfdc6a0ea9b7f20eadeada3d@epcms2p7/ > > --- > Daejun Park (2): > mm/huge_memory: set memcg_data before a split page leaves the folio > mm/page_owner: also check PageTail before reading memcg_data > > mm/huge_memory.c | 17 +++++++++++++---- > mm/memcontrol.c | 9 ++++++++- > mm/page_owner.c | 7 +++++++ > 3 files changed, 28 insertions(+), 5 deletions(-) > --- > base-commit: a13b500946e5dc467976838572b8ddd2fd777ca7 > change-id: 20261028-kpagecgroup-split-8a749c6ee27e > > Best regards, ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-01 5:25 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-04 9:59 [PATCH 0/2] mm: fix memcg_data reads during a THP split Daejun Park via B4 Relay 2026-11-04 9:59 ` [PATCH 1/2] mm/huge_memory: set memcg_data before a split page leaves the folio Daejun Park via B4 Relay 2026-11-04 16:33 ` Zi Yan 2026-11-05 1:06 ` Daejun Park 2026-12-01 5:24 ` Andrew Morton 2026-12-01 5:25 ` + mm-huge_memory-set-memcg_data-before-a-split-page-leaves-the-folio.patch added to mm-new branch Andrew Morton 2026-11-06 8:57 ` [PATCH 0/2] mm: fix memcg_data reads during a THP split Tao Yi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox