xen/mm: Reset PFN_ORDER for offlined buddy heads
v2 cover xen/mm: Reset PFN_ORDER for offlined buddy heads
This series fixes an inconsistency in the PFN_ORDER annotation for pages that are offlined when they are the head of a free buddy.
When reserve_offlined_page() splits a buddy and moves offlined sub-pages to the offlined lists, the former buddy head would be left annotated with its original order even though it is now a single page. While this does not cause functional regressions, it is misleading.
You can pull this series with the regression test environment to run it:
$ git pull [email protected]:bernhardkaindl/xen.git offline-head-order-v2 $ make -C tools/tests/native TARGETS=offline-head-order test
Bernhard Kaindl (2):
xen/mm: reset PFN_ORDER for offlined buddy heads tools/tests/native: Add test for offlined buddy head PFN_ORDER
tools/tests/native/offline-head-order.c | 74 +++++++++++++++++++++++++ xen/common/page_alloc.c | 6 ++ 2 files changed, 80 insertions(+) create mode 100644 tools/tests/native/offline-head-order.c
Signature · 1 line
2.39.5
PATCH v2 1/2 xen/mm: reset PFN_ORDER for offlined buddy heads
Ensure offlined buddy head pages are annotated as order-0 pages.
When a buddy containing pages marked for offlining is processed, reserve_offlined_page() rebuilds any surviving healthy buddies and moves the offlined subpages onto the offlined lists.
If the buddy head itself is offlined it was previously left annotated with the original buddy order even though it has been split into a single page.
This has no functional impact as the order of an offlined page is not used for any decision making and onlining, but it is misleading when inspecting the page's metadata.
Set PFN_ORDER(cur_head) to 0 for all pages moved to the lists of offlined and broken pages so the page's stored order reflects its actual size.
---
v2:
- Fix isolated from the new test and moved it ahead of the test.
- Unconditionally store 0 as the PFN_ORDER() of the offlined pages to make the code more robust against future changes.
--- xen/common/page_alloc.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/common/page_alloc.c +6 -0
@@ -1251,6 +1251,12 @@ static int reserve_offlined_page(struct page_info *head)ASSERT (total_avail_pages >0 ); total_avail_pages--; +/* +* All offlined pages are standalone pages: If this offlined page was +* the head of a higher-order buddy, we need to reset its order to 0: +*/ +PFN_ORDER (cur_head) =0 ; +page_list_add_tail (cur_head,test_bit (_PGC_broken, &cur_head->count_info) ? &page_broken_list : &page_offlined_list);
Signature · 1 line
2.39.5
PATCH v2 2/2 tools/tests/native: Add test for offlined buddy head PFN_ORDER
In reply to Bernhard KaindlAdd a regression test to check that the PFN_ORDER(pg) of buddy heads is reset to 0 when they become offline single pages which have been moved of the offlined page lists.
--- tools/tests/native/offline-head-order.c | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tools/tests/native/offline-head-order.c
tools/tests/native/offline-head-order.c new file +74 -0
@@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Tests using offline_page() to verify reserve_offlined_page() +* +* The workflow tested here is offlining a free page: +* +* 1. offline_page() calls mark_page_offlined() to mark the page. +* 2. It calls reserve_heap_page() to find the containing buddy. +* 3. It calls reserve_offlined_page() to reserve the marked pages within +* that buddy. +* +* reserve_offlined_page() then: +* +* 1. Removes the buddy, a 2^order group of pages, from the free list. +* 2. Finds size-aligned spans of healthy pages within it. +* 3. Rebuilds healthy buddies from those spans and +* adds them back to the free list via page_list_add_scrub(). +* 4. Moves offlined subpages to the offlined page lists. +* +* Copyright (C) 2026 Cloud Software Group +*/ +#define CONFIG_SYSCTL +#include "harness/native.h" + +static void test_offline_head_order (int start_mfn) +{ +struct page_info *page = frame_table + start_mfn; +uint32_t status =0 ; + +/* Seed a single order-1 buddy onto the heap. */ +test_page_list_add_buddy (page, order1); +ASSERT (PFN_ORDER (page) ==1 ); +/* Offline the head page. */ +ASSERT (offline_page (page_to_mfn (page),0 , &status) ==0 ); +ASSERT (status ==PG_OFFLINE_OFFLINED ); + +/* Check the order of the offlined head page. */ +ASSERT (PFN_ORDER (page) ==0 ); + +/* +* Allocate the successor page of the offlined page. This prevents +* the normal successor page merge when the page is re-onlined below. +*/ +struct page_info *pg =alloc_domheap_pages (dom1, order0,0 ); +ASSERT (pg == page +1 ); +ASSERT (FREE_PAGES ==0 ); + +/* Online the offlined former head page. */ +ASSERT (online_page (page_to_mfn (page), &status) ==0 ); +ASSERT (status &PG_ONLINE_ONLINED ); +ASSERT (FREE_PAGES ==1 ); + +/* +* Confirm the order of the onlined former head page is 0, independently +* of the order returned by PFN_ORDER() for the offlined page. This should +* always be successful because page_offlined_list only contains single +* pages and online_page() ignores PFN_ORDER(pg) of the page. It calls +* free_heap_pages() passing the order hardcoded to 0. This causes it to +* pass the given order 0 to page_list_add_scrub(). This causes it to set +* the order of the page to 0 before it adds the page to the free list. +*/ +ASSERT (PFN_ORDER (page) ==0 ); +} + +int main (int argc,char *argv[]) +{ +const char *topic ="Test offlined head page to be updated to PFN_ORDER 0" ; +if ( !parse_args (argc, argv, topic) ) +return EXIT_FAILURE ; + +init_page_alloc_tests (); +RUN_TESTCASE ("TOHP" , test_offline_head_order,2 ); +return test_complete (); +}
Signature · 1 line
2.39.5
Re: [PATCH v2 1/2] xen/mm: reset PFN_ORDER for offlined buddy heads
In reply to Bernhard KaindlQuoted 6 lines · Bernhard Kaindl
Ensure offlined buddy head pages are annotated as order-0 pages.
When a buddy containing pages marked for offlining is processed,
reserve_offlined_page()rebuilds any surviving healthy buddies and moves the offlined subpages onto the offlined lists.
Quoted 7 lines
If the buddy head itself is offlined it was previously left annotated with the original buddy order even though it has been split into a single page.
This has no functional impact as the order of an offlined page is not used for any decision making and onlining, but it is misleading when inspecting the page's metadata.
As per this, ...
xen/common/page_alloc.c static int reserve_offlined_page(struct page_info *head) · line 1256
Quoted 9 lines
xen/common/page_alloc.c +3
-0@@ -1251,6 +1251,12 @@ static int reserve_offlined_page(struct page_info *head)ASSERT (total_avail_pages >0 ); total_avail_pages--; +/* +* All offlined pages are standalone pages: If this offlined page was +* the head of a higher-order buddy, we need to reset its order to 0:
... is it really "need to"? I'd suggest simply dropping "we need to". Also unless there's really a good reason, comments better wouldn't end in colons. Can make adjustments while committing, as long as you agree.
Jan
RE: [PATCH v2 1/2] xen/mm: reset PFN_ORDER for offlined buddy heads
Quoted 3 lines
... is it really "need to"? I'd suggest simply dropping "we need to". Also unless there's really a good reason, comments better wouldn't end in colons. Can make adjustments while committing, as long as you agree.
Of course, correct!
Bernhard