From: "Lance Yang" <lance.yang@linux.dev>
To: "David Hildenbrand" <david@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>
Cc: mingzhe.yang@ly.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, "Lance Yang" <ioworker0@gmail.com>
Subject: Re: [RESEND PATCH v2 1/1] mm/rmap: add CONFIG_MM_ID guard for folio_test_large_maybe_mapped_shared()
Date: Mon, 21 Apr 2025 07:50:23 +0000 [thread overview]
Message-ID: <63cc131c78e6fe37755b3e39f90558469a0e80f4@linux.dev> (raw)
In-Reply-To: <d562572c-6b0d-443f-bcae-b862338fa7f7@redhat.com>
April 21, 2025 at 3:17 PM, "David Hildenbrand" <david@redhat.com> wrote:
>
> On 21.04.25 07:16, Lance Yang wrote:
>
> >
> > April 21, 2025 at 1:13 PM, "Lance Yang" <lance.yang@linux.dev> wrote:
> >
> > > >>
> >
> > >
> > > April 21, 2025 at 7:29 AM, "Andrew Morton" <akpm@linux-foundation.org> wrote:
> > >
> >
> > On Fri, 18 Apr 2025 23:22:28 +0800 Lance Yang <ioworker0@gmail.com> wrote:
> >
> > >>>
> >
> > >>>
> >
> > From: Lance Yang <lance.yang@linux.dev>
> >
> > >>>
> >
> > >>>
> >
> > >>>
> >
> > To prevent folio_test_large_maybe_mapped_shared() from being used without
> >
> > >>>
> >
> > CONFIG_MM_ID, we add a compile-time check rather than wrapping it in
> >
> > >>>
> >
> > '#ifdef', avoiding even more #ifdef in callers that already use
> >
> > >>>
> >
> > IS_ENABLED(CONFIG_MM_ID).
> >
> > >>>
> >
> > >>>
> >
> > >>>
> >
> > Also, we used plenty of IS_ENABLED() on purpose to keep the code free of
> >
> > >>>
> >
> > '#ifdef' mess.
> >
> > >>>
> >
> > >>>
> >
> > I dunno, this just seems really whacky.
> >
> > >
> > > I'd hope David could leave some comments on that.
> > >
> >
> > --- a/include/linux/page-flags.h
> >
> > >>>
> >
> > +++ b/include/linux/page-flags.h
> >
> > >>>
> >
> > @@ -1232,6 +1232,8 @@ static inline int folio_has_private(const struct folio *folio)
> >
> > >>>
> >
> > >>>
> >
> > >>>
> >
> > static inline bool folio_test_large_maybe_mapped_shared(const struct folio *folio)
> >
> > >>>
> >
> > {
> >
> > >>>
> >
> > + /* This function should never be called without CONFIG_MM_ID enabled. */
> >
> > >>>
> >
> > >>>
> >
> > A correcter comment would be "This function should never be compiled
> >
> > >>>
> >
> > without CONFIG_MM_ID enabled".
> >
> > >
> > > Yes, that is more exact ;)
> > >
> >
> > Which lets the cat out of the bag. Why the heck is it being compiled
> >
> > >>>
> >
> > with CONFIG_MM_ID=n?? We have tools to prevent that.
> >
> > >>>
> >
> > Can we just slap "#ifdef CONFIG_MM_ID" around the whole function? It
> >
> > >>>
> >
> > should have no callers, right? If the linker ends up complaining then
> >
> > >>>
> >
> > something went wrong.
> >
> > >
> > > The reason we can't simply add #ifdef CONFIG_MM_ID around folio_test_large_maybe_mapped_shared()
> > >
> > > is because its caller folio_maybe_mapped_shared() relies on IS_ENABLED(CONFIG_MM_ID).
> > >
> >
> > static inline bool folio_maybe_mapped_shared(struct folio *folio)
> >
> > {
> >
> > [...]
> >
> > if (!IS_ENABLED(CONFIG_MM_ID))
> >
> > return true;
> >
> > [...]
> >
> > return folio_test_large_maybe_mapped_shared(folio);
> >
> > }
> >
> > folio_maybe_mapped_shared() is always available - doesn't depend on
> >
> > CONFIG_MM_ID or CONFIG_TRANSPARENT_HUGEPAGE.
> >
>
> We could #ifdef in folio_maybe_mapped_shared(), which I find rather suboptimal ...
>
> or simply inline it into the 4 callers.
>
> That might be the best approach, given that only selected user should be using the low-level primitive and everybody else should be using folio_maybe_mapped_shared().
Yep, I tend to prefer the second approach as well, given there are only
four callers. Andrew, wdyt?
Thanks,
Lance
>
> -- Cheers,
>
> David / dhildenb
>
next prev parent reply other threads:[~2025-04-21 7:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 15:22 Lance Yang
2025-04-20 23:29 ` Andrew Morton
2025-04-21 5:13 ` Lance Yang
2025-04-21 5:16 ` Lance Yang
2025-04-21 7:17 ` David Hildenbrand
2025-04-21 7:50 ` Lance Yang [this message]
2025-04-21 19:22 ` Andrew Morton
2025-04-22 4:35 ` Lance Yang
2025-04-22 7:00 ` David Hildenbrand
2025-04-22 23:20 ` Andrew Morton
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=63cc131c78e6fe37755b3e39f90558469a0e80f4@linux.dev \
--to=lance.yang@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingzhe.yang@ly.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