v6 2026-08-02

KHO 下巨型页分配修复 · v6

KHO v6 系列引入扩展 scratch area,通过遍历 radix tree 发现空闲内存以修复 gigantic 巨页分配问题,并调整 radix 树 API 等。

原始补丁链接

子 Patch(22)

1/22
kho: generalize radix tree APIs
将 KHO radix tree API 从页跟踪中解耦,改为直接传入 key,编码移到调用方,并重命名 kho_radix_add_key/del_key 与回调参数。
2/22
kho: make radix max key width more obvious
用 KHO_RADIX_KEY_WIDTH 取代晦涩的 KHO_ORDER_0_LOG2,明确最大 key 宽度为 PFN 52 位加 order 1 位,并优化编解码注释。
3/22
kho: disallow wide keys in radix tree
在 kho_radix_add_key() 中校验 key 宽度,超限返回错误;不为尚无需求的大 key 增加树深度或内存开销。
4/22
kho: return virtual address of mem_map from kho_get_mem_map()
kho_get_mem_map_phys() 改名为 kho_get_mem_map() 并返回虚拟地址;kho_populate() 只需判空,后续调用者需要 VA。
5/22
kho: store incoming radix tree in kho_in
将传入的 radix tree 根保存到 kho_in,并复用 kho_get_mem_map_phys() 获取 FDT 中的根节点,避免重复代码。
6/22
kho: move all memory retrieval logic to kho_mem_retrieve()
把 kho_memory_init() 中的内存检索逻辑全部移到 kho_mem_retrieve(),统一处理 scratch 初始化和错误清理。
7/22
kho: add a struct for radix callbacks
为 KHO radix tree 回调引入 struct 封装,为后续增加更多回调做准备,并相应调整现有回调调用方式。
8/22
kho: add callback for table pages
新增 table page 回调,遍历 radix tree 时返回每个表页的物理地址,用于发现无保留页内存块及外部用户保留页。
9/22
kho: add data argument to radix walk callback
From: “Pratyush Yadav (Google)” pratyush@kernel.org Add an opaque data pointer argument to kho_radix_walk_cb_t. This can be used by callers to pass extra information to the callback. Reviewed-by:
10/22
kho: allow early-boot usage of the KHO radix tree
From: “Pratyush Yadav (Google)” pratyush@kernel.org The KHO radix tree allocates memory for table pages from the buddy allocator using get_zeroed_page(). This is not available in early boot when me
11/22
kho: allow destroying KHO radix tree
From: “Pratyush Yadav (Google)” pratyush@kernel.org Add kho_radix_destroy_tree() which allows destroying the radix tree and freeing all its pages. This is will be used by the upcoming scratch exte
12/22
kho: add kho_radix_init_tree()
From: “Pratyush Yadav (Google)” pratyush@kernel.org Move the initialization logic of the radix tree into kho_radix_init_tree() instead of having users open-code it. Makes the boundaries cleaner and
13/22
kho: expose kho_scratch_overlap() to kexec_handover.h
导出 kho_scratch_overlap() 供 memblock 使用,调试检查改用 IS_ENABLED 门控,并删除已空的 kexec_handover_debug.c。
14/22
kho: initialize kho_scratch pointer earlier in boot
From: “Pratyush Yadav (Google)” pratyush@kernel.org In a future patch, mm init will use kho_scratch_overlap() for deciding the migrate type of pageblocks it initializes. The earliest user currently
15/22
kho: initialize preserved memory map radix tree earlier
From: “Pratyush Yadav (Google)” pratyush@kernel.org Currently the preserved memory radix tree is initialized from kho_memory_init(), which happens relatively late in MM init. In a coming patch, the
16/22
mm/mm_init: simplify deferred_free_pages() migratetype init
From: Muchun Song songmuchun@bytedance.com deferred_free_pages() open-codes two loops to initialize the pageblock migratetype for a range of pages. Replace them with pageblock_migratetype_init_ran
17/22
mm/mm_init: don't rely on memblock to get KHO scratch migratetype
From: “Pratyush Yadav (Google)” pratyush@kernel.org Currently struct page init via memmap_init() or deferred_init_memmap() only queries the migrate type from KHO for each discrete memory range. Tha
18/22
kho: extend scratch
From: “Pratyush Yadav (Google)” pratyush@kernel.org Motivation ========== The scratch space is allocated by the first kernel in the KHO chain, and is reused by all subsequent kernels. The size of
19/22
memblock: always include KHO headers
From: “Pratyush Yadav (Google)” pratyush@kernel.org In a coming commit, memblock will start using kho_scratch_overlap() without a compile guard. The compile guard for the function is in kexec_hando
20/22
memblock: make HugeTLB bootmem allocation work with KHO
From: “Pratyush Yadav (Google)” pratyush@kernel.org Gigantic huge page allocation is somewhat broken currently when KHO is used. Firstly, they break KHO scratch size accounting. RSRV_KERN is used
21/22
memblock: add memblock_reserved_hugetlb_size()
From: “Pratyush Yadav (Google)” pratyush@kernel.org Similar to memblock_reserved_kern_size(), but calculates only the memory reserved for hugetlb pages. This is needed in an upcoming commit that su
22/22
kho: exclude hugetlb memory from scratch size calculation
From: “Pratyush Yadav (Google)” pratyush@kernel.org HugeTLB pages can be preserved memory. So they are never allocated from scratch. Instead, they are allocated from the memory blocks with no prese