mm/hugetlb: allow crashkernel to reuse hugetlb CMA memory
Subsystems (6)
PATCH 1/1 mm/hugetlb: allow crashkernel to reuse hugetlb CMA memory
crashkernel=size,cma reserves a separate CMA pool. On systems that already reserve several gigabytes with hugetlb_cma= (which is common in the Meta fleet), the crash kernel cannot use that existing memory as part of its working set. With hugetlb_cma=6G, requesting another 2G with crashkernel=2G,cma brings the total CMA reservation to 8G, none of which can serve unmovable kernel allocations.
Allow crashkernel=size,hugetlb_cma to reuse existing hugetlb CMA memory. For example:
hugetlb_cma=6G crashkernel=256M crashkernel=2G,hugetlb_cma
The full 6G remains available to HugeTLB and movable allocations during normal operation. After a crash, the capture kernel can use 2G of it as additional working memory. The conventional reservation is still required to hold the kernel image and initrd.
Use a separate suffix to make the exclusion of existing HugeTLB allocations from the vmcore an explicit choice. The capture kernel can overwrite the selected ranges, including allocated HugeTLB pages. The dump completeness and pending DMA risks of crashkernel=size,cma apply here as well.
Register the physical ranges in crashk_cma_ranges[] from an early initcall, after dedicated crash CMA reservations and before CMA activation. Use the existing crashkernel CMA code for the capture kernel's memory map, vmcore exclusion and DMA delay.
Use the remaining slots within the four-range limit, clip the final range to the page-aligned request and report any shortfall. Reject sizes that would overflow page rounding.
--- .../ABI/testing/sysfs-kernel-kexec-kdump | 3 ++ Documentation/admin-guide/kdump/kdump.rst | 21 ++++++++ .../admin-guide/kernel-parameters.txt | 25 ++++++++++ include/linux/hugetlb.h | 12 +++++ kernel/crash_reserve.c | 49 +++++++++++++++++- mm/hugetlb_cma.c | 50 +++++++++++++++++++ 6 files changed, 158 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-kernel-kexec-kdump +3 -0
@@ -58,4 +58,7 @@ Description: read only the Contiguous Memory Allocator (CMA) area that are allocated to the crash (kdump) kernel. It lists the start and end physical addresses of CMA regions assigned for crashkernel use. + This includes existing HugeTLB CMA memory selected with + crashkernel=size,hugetlb_cma. These ranges remain usable + by the running kernel and are excluded from the vmcore. User: kdump service
Documentation/admin-guide/kdump/kdump.rst +21 -0
@@ -332,6 +332,27 @@ crashkernel syntax less reliable and possibly incomplete kdump is preferable to no kdump at all. +5) crashkernel=size,hugetlb_cma + + Reuse existing HugeTLB CMA memory as additional crash kernel memory after + a crash. For example, to reuse 2G of a 6G HugeTLB CMA reservation:: + + hugetlb_cma=6G crashkernel=256M crashkernel=2G,hugetlb_cma + + A standard crashkernel reservation is still required for the kernel image + and initrd. The selected ranges remain available to HugeTLB and movable + allocations during normal operation. After a crash, the capture kernel + can overwrite their contents, including allocated HugeTLB pages, and the + ranges are excluded from the vmcore. The dump completeness and DMA risks + described for crashkernel=size,cma apply here too. + + The kernel selects up to the requested size from the existing hugetlb CMA + areas. Both CMA options use the same limit of four physical ranges, with + crashkernel=size,cma ranges added first. If there is insufficient memory + or too few range slots, the kernel reports the shortfall and reuses the + available ranges. Unused pages in contributing CMA areas remain reserved + if CMA activation fails. + Boot into System Kernel ----------------------- 1) Update the boot loader (such as grub, yaboot, or lilo) configuration
Documentation/admin-guide/kernel-parameters.txt +25 -0
@@ -1121,6 +1121,31 @@ Kernel parameters possibly incomplete kdump is preferable to no kdump at all. + crashkernel=size[KMG],hugetlb_cma + [KNL, X86, ARM64, RISCV, PPC] Use up to the specified + amount of existing hugetlb_cma memory as additional crash + kernel memory. Requires hugetlb_cma= and a standard + crashkernel reservation for the kernel image and initrd. + For example: + hugetlb_cma=6G crashkernel=256M crashkernel=2G,hugetlb_cma + + The selected memory remains available to HugeTLB and + movable allocations during normal operation. After a + crash, the capture kernel can overwrite these pages, + including allocated HugeTLB pages. The selected ranges + are excluded from the vmcore. The dump completeness + and DMA risks described for crashkernel=size,cma also + apply to this option. + + Both CMA options use the same limit of four physical + ranges, with crashkernel=size,cma ranges added first. + If the available hugetlb CMA memory or range slots + cannot cover the requested size, the kernel reuses + what is available and reports the shortfall. Additional + CMA memory is not reserved by this option. Unused pages + in contributing CMA areas remain reserved if activation + fails. + cryptomgr.notests [KNL] Disable crypto self-tests
include/linux/hugetlb.h +12 -0
@@ -1349,12 +1349,24 @@ static inline spinlock_t *huge_pte_lock(struct hstate *h,return ptl; } +struct range ; +#if defined(CONFIG_HUGETLB_PAGE ) && defined(CONFIG_CMA )extern void __init hugetlb_cma_reserve (void ); +unsigned long long __init +hugetlb_cma_add_crashkernel_ranges (unsigned long long size,struct range *ranges, +int *nr_ranges,int max_ranges);#else static inline __init void hugetlb_cma_reserve (void ) { } + +static inline unsigned long long +hugetlb_cma_add_crashkernel_ranges (unsigned long long size,struct range *ranges, +int *nr_ranges,int max_ranges) +{ +return 0 ; +}#endif #ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
kernel/crash_reserve.c +47 -2
77 lines not on this page · raw message
mm/hugetlb_cma.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.53.0-Meta
Quoted 2 lines · Usama Arif
Use a separate suffix to make the exclusion of existing HugeTLB allocations from the vmcore an explicit choice.
The crashkernel=size,cma documentation already says that pages allocated from the range are not in the vmcore and that it should not be used if dumping of userspace memory is intended. HugeTLB pages are userspace memory. I don't see what a new suffix makes explicit that ",cma" does not already.
Why not let crashkernel=size,cma take hugetlb CMA first and reserve a dedicated area only for what hugetlb CMA does not cover? With hugetlb_cma=6G crashkernel=2G,cma there would be no extra CMA at all. With hugetlb_cma=2G crashkernel=4G,cma the crash kernel would reuse the 2G and a dedicated 2G area would be reserved for the rest. Either way, nobody has to learn a new option.
The catch is ordering. reserve_crashkernel_cma() runs from setup_arch(), but hugetlb_cma_reserve() runs later, from mm_core_init_early(). The arch code could record the size and leave the reservation to generic code right after hugetlb_cma_reserve(). That is still memblock time, so the remainder can be declared there. An early_initcall is too late for that.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
David Hildenbrand (Arm)
reviewerQuoted 10 lines · Kiryl Shutsemau
Quoted 2 lines · Usama Arif
Use a separate suffix to make the exclusion of existing HugeTLB allocations from the vmcore an explicit choice.
The crashkernel=size,cma documentation already says that pages allocated from the range are not in the vmcore and that it should not be used if dumping of userspace memory is intended. HugeTLB pages are userspace memory. I don't see what a new suffix makes explicit that ",cma" does not already.
Quoted 3 lines
Why not let crashkernel=size,cma take hugetlb CMA first and reserve a dedicated area only for what hugetlb CMA does not cover? With hugetlb_cma=6G crashkernel=2G,cma there would be no extra CMA at all.
Hiding that complexity from the user would indeed be nice.
Signature · 3 lines
Cheers, David
Quoted 17 lines · Kiryl Shutsemau
Quoted 2 lines · Usama Arif
Use a separate suffix to make the exclusion of existing HugeTLB allocations from the vmcore an explicit choice.
The crashkernel=size,cma documentation already says that pages allocated from the range are not in the vmcore and that it should not be used if dumping of userspace memory is intended. HugeTLB pages are userspace memory. I don't see what a new suffix makes explicit that ",cma" does not already.
Why not let crashkernel=size,cma take hugetlb CMA first and reserve a dedicated area only for what hugetlb CMA does not cover? With hugetlb_cma=6G crashkernel=2G,cma there would be no extra CMA at all. With hugetlb_cma=2G crashkernel=4G,cma the crash kernel would reuse the 2G and a dedicated 2G area would be reserved for the rest. Either way, nobody has to learn a new option.
Quoted 6 lines
The catch is ordering.
reserve_crashkernel_cma()runs fromsetup_arch(), buthugetlb_cma_reserve()runs later, frommm_core_init_early(). The arch code could record the size and leave the reservation to generic code right afterhugetlb_cma_reserve(). That is still memblock time, so the remainder can be declared there. Anearly_initcallis too late for that.
Makes sense to me, I will rewrite it in the above way and send v2.
Thanks for the review!
Usama