From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>,
Zhenwen Liang <zhenwenliang@google.com>, Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>,
linux-mm@kvack.org
Subject: Re: [PATCH v2] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load
Date: Mon, 30 Nov 2026 16:36:35 +0100 [thread overview]
Message-ID: <1c5a7108-297e-4a1f-bece-c1c6be170077@kernel.org> (raw)
In-Reply-To: <aw2G5Tl82ZQ7bvL8@gremlin>
On 11/30/26 15:40, Lorenzo Stoakes (ARM) wrote:
> On Mon, Nov 30, 2026 at 01:23:44PM +0100, David Hildenbrand (Arm) wrote:
>> On 11/30/26 09:11, Baolin Wang wrote:
>>>
>>>
>>>
>>> Yes, this is possible. But ...
>>>
>
> I am not sure it really matter that much. The window is tiny, and the outcome is
> something has smaller folios, it's not a big deal.
>
> I definitely wouldn't cc: stable anyway.
>
>
> This whole thing is another byproduct of the mess that is the non-preallocated
> huge zero folio. How I hate it... Utterly cursed :)
>
> There was a significant bug with how all that was implemented that flummoxed
> many mm developers (because memory barriers always do that).
>
> I still feel like we should still default to that :) need to un-RFC my patch on
> that.
>
> Anyway I agree it's more cromulent to use an acquire test here. Thanks Baolin.
>
>
>
>>>
>>> Not a fan of adding a separate rmb() barrier. Why not use the acquire
>>> bit test? Something like:
>>>
>>> static inline bool mm_flags_test_acquire(int flag, const struct
>>> mm_struct *mm)
>>> {
>>> return test_bit_acquire(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
>>> }
>>
>> That looks better indeed. Micht still want to document the corresponding barrier.
>
> More than might please :) Any use of the arcane arts (memory barriers) must
> specify what it is paired with, otherwise it becomes something that people are
> afraid to touch.
>
> But I think you don't want that in the mm_flags_test_acquire() function you want
> it at the caller.
>
> So something like:
>
> < ... add mm_flags_test_acquire() to mm.h ... >
>
> struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)
> {
> + /* Paired with full barrier of mm_flags_test_and_set(). */
> - if (mm_flags_test(MMF_HUGE_ZERO_FOLIO, mm))
> + if (mm_flags_test_acquire(MMF_HUGE_ZERO_FOLIO, mm))
> return READ_ONCE(huge_zero_folio);
>
> if (!get_huge_zero_folio())
> return NULL;
>
> if (mm_flags_test_and_set(MMF_HUGE_ZERO_FOLIO, mm))
> put_huge_zero_folio();
>
> return READ_ONCE(huge_zero_folio);
> }
>
> That version LGTM so feel free to add:
>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Can you take a look at v3, if your tag applies there or whether you want some
changes?
Thanks!
--
Cheers,
David
next prev parent reply other threads:[~2026-11-30 15:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 12:52 [PATCH v2] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load Zhenwen Liang
2026-11-29 13:35 ` Zi Yan
2026-11-30 8:11 ` Baolin Wang
2026-11-30 12:23 ` David Hildenbrand (Arm)
2026-11-30 14:40 ` Lorenzo Stoakes (ARM)
2026-11-30 15:36 ` David Hildenbrand (Arm) [this message]
2026-11-30 16:02 ` Lorenzo Stoakes (ARM)
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=1c5a7108-297e-4a1f-bece-c1c6be170077@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=zhenwenliang@google.com \
--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