mm/page_alloc: count guard pages as free again when their buddy merges
Subsystems (3)
PATCH 1/1 mm/page_alloc: count guard pages as free again when their buddy merges
With debug_guardpage_minorder set, expand() turns the unused halves of a split into guard pages, which page_del_and_expand() leaves out of the free counts. Freeing the allocated half credits only that half, and __free_one_page() then merges the guard buddy with clear_page_guard(), which no longer touches the counters.
The merged block goes on a free list with the guard pages never counted, so NR_FREE_PAGES falls behind the free lists by every guard that merges. Before commit e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting"), __set_page_guard() and __clear_page_guard() adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit in expand().
Count the guard pages under the merged block's migratetype when the buddy is cleared. account_freepages() skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.
Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between /proc/vmstat and /proc/buddyinfo.
At three points (idle, after a read and file-creation load, after a second load), check the difference between nr_free_pages and the buddyinfo numbers in the normal zone, as a number of pages:
idle after load after second load
unpatched -130 79205 99121
patched -16 45 0
The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.
--- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
@@ -988,10 +988,12 @@ static inline void __free_one_page(struct page *page,* Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order. */ -if (page_is_guard (buddy)) +if (page_is_guard (buddy)) {clear_page_guard (zone, buddy, order); -else +account_freepages (zone,1 << order, migratetype); + }else {__del_page_from_free_list (buddy, zone, order, buddy_mt); + }if (unlikely (buddy_mt != migratetype)) {/*
Quoted 34 lines · Rik van Riel
With
debug_guardpage_minorderset,expand()turns the unused halves of a split into guard pages, whichpage_del_and_expand()leaves out of the free counts. Freeing the allocated half credits only that half, and__free_one_page()then merges the guard buddy withclear_page_guard(), which no longer touches the counters.The merged block goes on a free list with the guard pages never counted, so
NR_FREE_PAGESfalls behind the free lists by every guard that merges. Before commite0932b6c1f94("mm:page_alloc: consolidate free page accounting"),__set_page_guard()and__clear_page_guard()adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit inexpand().Count the guard pages under the merged block's migratetype when the buddy is cleared.
account_freepages()skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between
/proc/vmstatand/proc/buddyinfo.At three points (idle, after a read and file-creation load, after a second load), check the difference between
nr_free_pagesand the buddyinfo numbers in the normal zone, as a number of pages:idle after load after second load
unpatched -130 79205 99121
patched -16 45 0The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.
Quoted 7 lines
Fixes e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting")Assisted-by LLMSigned-off-by Rik van Riel <[email protected]>Reviewed-by Zi Yan <[email protected]>Reviewed-by Johannes Weiner <[email protected]>Reviewed-by Dev Jain <[email protected]>
Quoted 24 lines
--- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)mm/page_alloc.c +4
-2@@ -988,10 +988,12 @@ static inline void __free_one_page(struct page *page,* Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page, * merge with it and move up one order. */ -if (page_is_guard (buddy)) +if (page_is_guard (buddy)) {clear_page_guard (zone, buddy, order); -else +account_freepages (zone,1 << order, migratetype); + }else {__del_page_from_free_list (buddy, zone, order, buddy_mt); + }if (unlikely (buddy_mt != migratetype)) {/*