From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Gregory Price (Meta)" <gourry@gourry.net>,
Chris Mason <mason@kernel.org>
Cc: hughd@google.com, baolin.wang@linux.alibaba.com,
akpm@linux-foundation.org, qi.zheng@linux.dev,
qinyuntan@linux.alibaba.com, shakeel.butt@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] mm/shmem: don't use the memcg of an uncharged folio
Date: Sat, 21 Nov 2026 14:00:59 +0100 [thread overview]
Message-ID: <960b4568-9d20-4eb0-b0e4-67e60f8274d4@kernel.org> (raw)
In-Reply-To: <179526598180.412063.14973682472309530978.b4-reply@b4>
On 11/21/26 13:59, Gregory Price (Meta) wrote:
> On 2026-11-20 14:50 -0500, Chris Mason wrote:
>> The shrinker for unused huge tmpfs folios can dereference a NULL memcg
>> if it races with the migration of the folio at the end of a file.
>>
>> folio_memcg_list_lru_alloc() assumes that folio_memcg() is never NULL.
>> But it is NULL until the folio is charged, and a migration target can be
>> in the page cache before charging.
>>
>> shmem_unused_huge_shrink() looks the folio up without the folio lock,
>> so we can race with migration:
>>
>> __migrate_folio() shmem_unused_huge_shrink()
>> ================= ==========================
>> __folio_migrate_mapping()
>> xas_store(newfolio)
>> filemap_get_entry()
>> returns newfolio
>> folio_trylock() fails
>> shmem_unused_huge_requeue()
>> folio_memcg_list_lru_alloc()
>> folio_memcg() is NULL
>> memcg->kmemcg_id
>> folio_migrate_flags()
>> mem_cgroup_migrate()
>> commit_charge(newfolio)
>>
>> Fix it by keeping the original objcg around while the inode is isolated.
>>
>> Fixes: 743e7d025d2f ("mm: shmem: make unused huge shrinker memcg aware")
>> Suggested-by: Qi Zheng <qi.zheng@linux.dev>
>> Signed-off-by: Chris Mason <mason@kernel.org>
>
> Reproduced and validated the fix. Changes look ok.
Thanks, I'll throw this into for-next-fixes right away and cc stable.
--
Cheers,
David
next prev parent reply other threads:[~2026-11-21 13:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 19:50 [PATCH v2 0/1] mm/shmem: don't use the memcg of an uncharged folio Chris Mason
2026-11-20 19:50 ` [PATCH v2 1/1] " Chris Mason
2026-11-21 10:50 ` Qi Zheng
2026-11-21 12:18 ` David Hildenbrand (Arm)
2026-11-21 12:59 ` Gregory Price (Meta)
2026-11-21 13:00 ` David Hildenbrand (Arm) [this message]
2026-11-21 13:01 ` David Hildenbrand (Arm)
2026-11-21 13:01 ` [PATCH v2 0/1] " David Hildenbrand
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=960b4568-9d20-4eb0-b0e4-67e60f8274d4@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=gourry@gourry.net \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=qinyuntan@linux.alibaba.com \
--cc=shakeel.butt@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.