linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <baohua@kernel.org>
To: Hongru Zhang <zhanghongru06@gmail.com>
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
	 axelrasmussen@google.com, david@kernel.org, hannes@cmpxchg.org,
	 jackmanb@google.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org,  lorenzo.stoakes@oracle.com, mhocko@suse.com,
	rppt@kernel.org,  surenb@google.com, vbabka@suse.cz,
	weixugc@google.com, yuanchu@google.com,  zhanghongru@xiaomi.com,
	ziy@nvidia.com
Subject: Re: [PATCH 3/3] mm: optimize free_area_empty() check using per-migratetype counts
Date: Thu, 2 Apr 2026 15:28:42 +0800	[thread overview]
Message-ID: <CAGsJ_4z_2ytLf8cHZ62-k5D=mKteJBrZjjuOVSqkr9+ugK+uxw@mail.gmail.com> (raw)
In-Reply-To: <20260303082952.477277-1-zhanghongru@xiaomi.com>

On Tue, Mar 3, 2026 at 4:32 PM Hongru Zhang <zhanghongru06@gmail.com> wrote:
>
> > >
> > > From: Hongru Zhang <zhanghongru@xiaomi.com>
> > >
> > > Use per-migratetype counts instead of list_empty() helps reduce a
> > > few cpu instructions.
> > >
> > > Signed-off-by: Hongru Zhang <zhanghongru@xiaomi.com>
> > > ---
> > >  mm/internal.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/mm/internal.h b/mm/internal.h
> > > index 1561fc2ff5b8..7759f8fdf445 100644
> > > --- a/mm/internal.h
> > > +++ b/mm/internal.h
> > > @@ -954,7 +954,7 @@ int find_suitable_fallback(struct free_area *area, unsigned int order,
> > >
> > >  static inline bool free_area_empty(struct free_area *area, int migratetype)
> > >  {
> > > -       return list_empty(&area->free_list[migratetype]);
> > > +       return !READ_ONCE(area->mt_nr_free[migratetype]);
> >
> > I'm not quite sure about this. Since the counter is written and read more
> > frequently, cache coherence traffic may actually be higher than for the list
> > head.
> >
> > I'd prefer to drop this unless there is real data showing it performs better.
>
> Under the model described in email [1], with this patch (3/3), memory allocation
> performance is 0.36% better than without it.

I'm fine with the data, though my actual suggestion was to place each
mt_free_area in a separate cacheline to avoid false sharing. That one
could be separated if you see an obvious performance improvement.

For this patchset, I feel the main issue is convincing people of the value
of increasing counters in the alloc/free hotpath. As Johannes commented [1],
the new counters should provide more use cases than pagetypeinfo, or as Zi
Yan commented [2], clearly demonstrate the value that userspace derives from
pagetypeinfo.

Right now, pagetypeinfo is considered a debug interface, so its implementation
is quite poor.

[1] https://lore.kernel.org/all/20251128130823.GA222920@cmpxchg.org/
[2] https://lore.kernel.org/all/760FBDE3-2724-44A6-A874-BD87F0191C57@nvidia.com/

>
> Detailed data:
> - https://gist.github.com/zhr250/4439523b7ca3c18f4a2d2c97b24c4965
>
> Reference:
> [1] https://lore.kernel.org/linux-mm/20260303080423.472534-1-zhanghongru@xiaomi.com/

Thanks
Barry


  reply	other threads:[~2026-04-02  7:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28  3:10 [PATCH 0/3] mm: add per-migratetype counts to buddy allocator and optimize pagetypeinfo access Hongru Zhang
2025-11-28  3:11 ` [PATCH 1/3] mm/page_alloc: add per-migratetype counts to buddy allocator Hongru Zhang
2025-11-29  0:34   ` Barry Song
2025-11-28  3:12 ` [PATCH 2/3] mm/vmstat: get fragmentation statistics from per-migragetype count Hongru Zhang
2025-11-28 12:03   ` zhongjinji
2025-11-29  0:00     ` Barry Song
2025-11-29  7:55       ` Barry Song
2025-12-01 12:29       ` Hongru Zhang
2025-12-01 18:54         ` Barry Song
2025-11-28  3:12 ` [PATCH 3/3] mm: optimize free_area_empty() check using per-migratetype counts Hongru Zhang
2025-11-29  0:04   ` Barry Song
2025-11-29  9:24     ` Barry Song
2026-03-03  8:04       ` Hongru Zhang
2026-03-03  8:29     ` Hongru Zhang
2026-04-02  7:28       ` Barry Song [this message]
2025-11-28  7:49 ` [PATCH 0/3] mm: add per-migratetype counts to buddy allocator and optimize pagetypeinfo access Lorenzo Stoakes
2025-11-28  8:34   ` Hongru Zhang
2025-11-28  8:40     ` Lorenzo Stoakes
2025-11-28  9:24 ` Vlastimil Babka
2025-11-28 13:08   ` Johannes Weiner
2025-12-01  2:36   ` Hongru Zhang
2025-12-01 17:01     ` Zi Yan
2025-12-02  2:42       ` Hongru Zhang
2026-04-02  7:18 ` Barry Song
2026-04-05  9:32   ` Hongru Zhang

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_4z_2ytLf8cHZ62-k5D=mKteJBrZjjuOVSqkr9+ugK+uxw@mail.gmail.com' \
    --to=baohua@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=zhanghongru06@gmail.com \
    --cc=zhanghongru@xiaomi.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