From: Johannes Weiner <hannes@cmpxchg.org>
To: Zi Yan <ziy@nvidia.com>
Cc: Sasha Levin <sashal@kernel.org>,
stable@vger.kernel.org,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Lorenzo Stoakes <ljs@kernel.org>, Barry Song <baohua@kernel.org>,
David Hildenbrand <david@kernel.org>, Dev Jain <dev.jain@arm.com>,
Lance Yang <lance.yang@linux.dev>,
"Liam R . Howlett" <liam@infradead.org>,
Matthew Wilcox <willy@infradead.org>,
Ryan Roberts <ryan.roberts@arm.com>,
William Kucharski <william.kucharski@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6.6.y] mm/huge_memory: use folio's memcg inside __folio_split()
Date: Thu, 10 Sep 2026 15:23:55 -0400 [thread overview]
Message-ID: <aqMDyxhGXZyhcm5H@cmpxchg.org> (raw)
In-Reply-To: <DL8LKM3Q9LGZ.DENNSVG6XK1C@nvidia.com>
On Sun, Sep 06, 2026 at 06:46:55PM -0400, Zi Yan wrote:
> On Sun Sep 6, 2026 at 9:33 AM EDT, Sasha Levin wrote:
> >> __GFP_ACCOUNT is needed for xarray node allocation accounting when
> >> XA_FLAGS_ACCOUNT is set. Commit 7b785645e8f13 ("mm: fix page cache
> >> convergence regression") fixed a workingset regression with it.
> >> xas_split_alloc() does not have it and needs to be fixed.
> >
> > Mainline's c299a2285d9d takes a reference on the folio's memcg with
> > get_mem_cgroup_from_folio() and holds it in current->active_memcg for the
> > duration of __folio_split() - rcu_read_lock()+css_tryget(), released with
> > mem_cgroup_put() afterwards. This 6.6.y version instead holds a bare
> > folio_memcg(folio) pointer across the same window, which includes a TLB
> > shootdown and several lock acquisitions - exactly the kind of window the
> > upstream refcount exists to close.
> >
> > 6.6 already has rcu_read_lock(), css_tryget() and mem_cgroup_put() available,
> > so nothing's missing to do this the same way upstream does. Could you resend a
> > v2 that takes and drops the reference (under CONFIG_MEMCG, as upstream does)?
>
> No, this is not needed. Before commit f1cf8d2f36dc3 ("mm: memcontrol:
> eliminate the problem of dying memory cgroup for LRU folios"), like
> v6.6, a charged folio take a ref on its memcg. During split, the folio
> is locked, so will not be uncharged. As a result, its memcg will not go
> away.
Yes. It's safe until that last unlock & free in
__split_huge_page(). We don't have allocations or indirect references
to current->active_memcg afterwards that I can see.
> According to Claude, adding a ref there might cause a deadlock when a
> to-be-split folio has a dying memcg, where css_tryget() keeps failing
> and folio_memcg() keeps returning the same memcg.
If the cgroup was rmdir'd, only css_tryget_online() would fail. The
page itself holds a reference, keeping the dying cgroup from being
freed. And css_tryget() would still work.
So it would be doable if you wanted to keep the backport closer to
what we have upstream. But yes, it's not strictly necessary.
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
next prev parent reply other threads:[~2026-09-10 19:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 10:46 FAILED: patch "[PATCH] mm/huge_memory: use folio's memcg inside __folio_split()" failed to apply to 6.6-stable tree gregkh
2026-09-04 2:26 ` [PATCH 6.6.y] mm/huge_memory: use folio's memcg inside __folio_split() Zi Yan
2026-09-06 13:33 ` Sasha Levin
2026-09-06 22:46 ` Zi Yan
2026-09-08 0:53 ` Sasha Levin
2026-09-10 19:23 ` Johannes Weiner [this message]
2026-09-12 15:26 ` Sasha Levin
2026-09-12 18:31 ` Zi Yan
2026-09-15 2:03 ` Sasha Levin
2026-09-04 2:36 ` Sasha Levin
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=aqMDyxhGXZyhcm5H@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=ljs@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=william.kucharski@oracle.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/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