linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	Hugh Dickins <hughd@google.com>,  Dev Jain <dev.jain@arm.com>,
	David Hildenbrand <david@redhat.com>,
	 Liam Howlett <liam.howlett@oracle.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	 Mariano Pache <npache@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	 Ryan Roberts <ryan.roberts@arm.com>, Zi Yan <ziy@nvidia.com>,
	linux-kernel@vger.kernel.org,  stable@vger.kernel.org
Subject: Re: [PATCH v2] mm/shmem: fix THP allocation and fallback loop
Date: Thu, 23 Oct 2025 19:05:09 +1300	[thread overview]
Message-ID: <CAGsJ_4yidWp9BqJbTa44uLWpJU-d5A+76r8QeErtL+Au+CEqZw@mail.gmail.com> (raw)
In-Reply-To: <CAMgjq7CdQK_k_oGfOwCtMm18uAXrGwfwUz93pt7kaN-S64G0Cg@mail.gmail.com>

On Thu, Oct 23, 2025 at 6:58 PM Kairui Song <ryncsn@gmail.com> wrote:
>
> On Thu, Oct 23, 2025 at 1:51 PM Barry Song <21cnbao@gmail.com> wrote:
> > > diff --git a/mm/shmem.c b/mm/shmem.c
> > > index b50ce7dbc84a..7559773ebb30 100644
> > > --- a/mm/shmem.c
> > > +++ b/mm/shmem.c
> > > @@ -1895,10 +1895,11 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf,
> > >                 order = highest_order(suitable_orders);
> > >                 while (suitable_orders) {
> > >                         pages = 1UL << order;
> > > -                       index = round_down(index, pages);
> > > -                       folio = shmem_alloc_folio(gfp, order, info, index);
> > > -                       if (folio)
> > > +                       folio = shmem_alloc_folio(gfp, order, info, round_down(index, pages));
> > > +                       if (folio) {
> > > +                               index = round_down(index, pages);
> > >                                 goto allocated;
> > > +                       }
> >
> > Could this be a temporary variable to store round_down(index, pages)?
>
> Right we can do that, but the generated code should be the same, the
> compiler is smart enough, I just checked the generated code with gcc /
> clang.
>
> Do you think the code will be cleaner with a temporary variable? I can
> send a V3 if anyone suggests, it's really a trivial change.

Personally, I think a temporary variable makes the code cleaner, but I don’t
have any strong preference.

The fix looks correct to me.

Thanks
Barry


      reply	other threads:[~2025-10-23  6:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-22 10:57 Kairui Song
2025-10-23  5:51 ` Barry Song
2025-10-23  5:57   ` Kairui Song
2025-10-23  6:05     ` Barry Song [this message]

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=CAGsJ_4yidWp9BqJbTa44uLWpJU-d5A+76r8QeErtL+Au+CEqZw@mail.gmail.com \
    --to=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=hughd@google.com \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=ryncsn@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    --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