From: Pranav Tyagi <pranav.tyagi03@gmail.com>
To: Peter Xu <peterx@redhat.com>
Cc: akpm@linux-foundation.org, shuah@kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH] selftests/mm: use __auto_type in swap() macro
Date: Tue, 26 Aug 2025 21:53:20 +0530 [thread overview]
Message-ID: <CAH4c4jLsFNzBEhCQVSCT43tZjbf5wp88xU_5BXnN+4t5CxU52A@mail.gmail.com> (raw)
In-Reply-To: <aJOG-IAmYhjoYVf-@x1.local>
On Wed, Aug 6, 2025 at 10:16 PM Peter Xu <peterx@redhat.com> wrote:
>
> On Wed, Aug 06, 2025 at 09:15:50PM +0530, Pranav Tyagi wrote:
> > On Wed, Jul 30, 2025 at 7:53 PM Pranav Tyagi <pranav.tyagi03@gmail.com> wrote:
> > >
> > > Replace typeof() with __auto_type in the swap() macro in uffd-stress.c.
> > > __auto_type was introduced in GCC 4.9 and reduces the compile time for
> > > all compilers. No functional changes intended.
> > >
> > > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> > > ---
> > > tools/testing/selftests/mm/uffd-stress.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
> > > index 40af7f67c407..c0f64df5085c 100644
> > > --- a/tools/testing/selftests/mm/uffd-stress.c
> > > +++ b/tools/testing/selftests/mm/uffd-stress.c
> > > @@ -51,7 +51,7 @@ static char *zeropage;
> > > pthread_attr_t attr;
> > >
> > > #define swap(a, b) \
> > > - do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
> > > + do { __auto_type __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
> > >
> > > const char *examples =
> > > "# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
> > > --
> > > 2.49.0
> > >
> >
> > Hi,
> >
> > Just a gentle follow-up on this cleanup patch. From what I could find,
> > this is the only use of
> > typeof() left in the mm selftests, so this should be the only instance
> > needing this change.
> >
> > Thanks for considering!
>
> Hi,
>
> Andrew should have queued this one in branch akpm/mm-nonmm-unstable (even
> though I'm not familiar with the branch).
>
> Said that, I'm also not familiar with __auto_type. Looks like it's more
> efficiently processed by the compiler in some special use cases, however
> it's also new so maybe some tools (sparse?) may not recognize it.
>
> Is it the plan that the whole Linux kernel is moving towards __auto_type?
> I still see quite a few of typeof() usages (not "a few", but 2966 instances).
>
> Thanks,
>
> --
> Peter Xu
>
Hi Peter,
Thank you for the feedback and I sincerely apologize for the delayed
response.
You’re right — this patch was initially queued under akpm/mm-nonmm-unstable
and it now lives in the mm-unstable branch.
The motivation behind switching to __auto_type is twofold: it reduces compile
time across compilers and improves readability. Support for __auto_type has
been available in GCC since 4.9 (quite some time back) and in sparse since
v0.6.2 (2020). To the best of my knowledge, it has since been widely adopted
by toolchains.
That said, I acknowledge there are still many uses of typeof() in the kernel,
as you pointed out. My intent with this patch (and a few related ones I’ve
submitted) is to encourage more consistent use of __auto_type, starting with
selftests where it is already in use in several places.
Thanks again for your review and for pointing out the current branch status.
Regards
Pranav Tyagi
next prev parent reply other threads:[~2025-08-26 16:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 14:23 Pranav Tyagi
2025-08-06 15:45 ` Pranav Tyagi
2025-08-06 16:46 ` Peter Xu
2025-08-26 16:23 ` Pranav Tyagi [this message]
2025-08-06 16:48 ` Joshua Hahn
2025-08-26 16:26 ` Pranav Tyagi
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=CAH4c4jLsFNzBEhCQVSCT43tZjbf5wp88xU_5BXnN+4t5CxU52A@mail.gmail.com \
--to=pranav.tyagi03@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
/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