Re: [PATCH 3/3] mm: optimize free_area_empty() check using per-migratetype counts

From: Hongru Zhang

Date: Tue Mar 03 2026 - 03:32:33 EST


> >
> > From: Hongru Zhang <zhanghongru@xxxxxxxxxx>
> >
> > Use per-migratetype counts instead of list_empty() helps reduce a
> > few cpu instructions.
> >
> > Signed-off-by: Hongru Zhang <zhanghongru@xxxxxxxxxx>
> > ---
> > 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.

Detailed data:
- https://gist.github.com/zhr250/4439523b7ca3c18f4a2d2c97b24c4965

Reference:
[1] https://lore.kernel.org/linux-mm/20260303080423.472534-1-zhanghongru@xxxxxxxxxx/