Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Zi Yan <ziy@nvidia.com>
Cc: Zhenwen Liang <zhenwenliang@google.com>,
	 David Hildenbrand <david@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	"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,  Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>
Subject: Re: [PATCH v3] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load
Date: Mon, 30 Nov 2026 16:46:06 +0000	[thread overview]
Message-ID: <aw2oDwsfM-WL4nPz@gremlin> (raw)
In-Reply-To: <2C5ADC6A-7530-4A27-BFB4-F1F10C30707B@nvidia.com>

On Mon, Nov 30, 2026 at 11:22:14AM -0500, Zi Yan wrote:
> >>  static inline bool mm_flags_test_and_set(int flag, struct mm_struct *mm)
> >>  {
> >>  	return test_and_set_bit(flag, ACCESS_PRIVATE(&mm->flags, __mm_flags));
> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> >> index d065b26a94df..139471a861ed 100644
> >> --- a/mm/huge_memory.c
> >> +++ b/mm/huge_memory.c
> >> @@ -395,7 +395,11 @@ static void __init huge_zero_shrinker_exit(void)
> >>
> >>  struct folio *mm_get_huge_zero_folio(struct mm_struct *mm)
> >>  {
> >> -	if (mm_flags_test(MMF_HUGE_ZERO_FOLIO, mm))
> >> +	/*
> >> +	 * Paired with the full barrier of mm_flags_test_and_set().
> >> +	 * The flag implies huge_zero_folio is visible.
> >
> > This line seems redundant. But not the end of the world given it's taken
> > already...
>
> I suggested it because when I looked at v2, it is not straightforward
> to me why pairing smp_rmb() with mm_flags_test_and_set() would work
> until I read get_huge_zero_folio(). Then I wonder why not atomically
> read huge_zero_refcount to achieve the same effect, but that is
> a costly global read. I just want to save another round of reasoning
> when I see the code next time. :)

Ack, yeah. I did wonder about saying something in general about _why_, maybe I
stared at this long enough to get the context and felt it was 'obvious'.

But what you just describe is literally why real life experience trumps
assumptions like that :)

So fair enough as-is!

--
Cheers, Lorenzo


  reply	other threads:[~2026-11-30 16:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 12:53 [PATCH v3] mm/huge_memory: order the MMF_HUGE_ZERO_FOLIO test before the huge_zero_folio load Zhenwen Liang
2026-11-30 15:11 ` Zi Yan
2026-11-30 15:33 ` David Hildenbrand (Arm)
2026-11-30 15:34 ` David Hildenbrand
2026-11-30 16:06 ` Lorenzo Stoakes (ARM)
2026-11-30 16:22   ` Zi Yan
2026-11-30 16:46     ` Lorenzo Stoakes (ARM) [this message]
2026-11-30 16:32   ` Zhenwen Liang
2026-11-30 16:46     ` Lorenzo Stoakes (ARM)
2026-11-30 16:48   ` David Hildenbrand (Arm)
2026-11-30 16:50     ` Lorenzo Stoakes (ARM)
2026-11-30 16:51       ` Lorenzo Stoakes (ARM)
2026-11-30 16:56       ` David Hildenbrand (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=aw2oDwsfM-WL4nPz@gremlin \
    --to=ljs@kernel.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=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --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