From 819bdc71dc521a34185696c18cd3eaf7c82d5f32 Mon Sep 17 00:00:00 2001 From: Johannes Weiner Date: Wed, 27 Mar 2024 15:01:11 -0400 Subject: [PATCH] BACKPORT: mm: page_alloc: batch vmstat updates in expand() expand() currently updates vmstat for every subpage. This is unnecessary, since they're all of the same zone and migratetype. Count added pages locally, then do a single vmstat update. Link: https://lkml.kernel.org/r/20240327190111.GC7597@cmpxchg.org Change-Id: I3373bb60d30f9a631a246d33e275a73229696726 Signed-off-by: Johannes Weiner Suggested-by: Vlastimil Babka Signed-off-by: Andrew Morton (cherry picked from commit 883dd161e9a83e188487debc562b1928917a4b39) [ Fix trivial conflict in expand() - Kalesh Singh] Signed-off-by: Kalesh Singh --- mm/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b65525513753..9e4b36e6e6b4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1519,6 +1519,7 @@ static inline void expand(struct zone *zone, struct page *page, int low, int high, int migratetype) { unsigned long size = 1 << high; + unsigned long nr_added = 0; while (high > low) { high--; @@ -1535,9 +1536,10 @@ static inline void expand(struct zone *zone, struct page *page, continue; __add_to_free_list(&page[size], zone, high, migratetype, false); - account_freepages(zone, 1 << high, migratetype); set_buddy_order(&page[size], high); + nr_added += size; } + account_freepages(zone, nr_added, migratetype); } static void check_new_page_bad(struct page *page)