mm/hugetlb_cma: support percentage-based hugetlb_cma reservation
Subsystems (3)
PATCH v5 1/1 mm/hugetlb_cma: support percentage-based hugetlb_cma reservation
Currently, hugetlb_cma reservation only supports absolute sizes (e.g., hugetlb_cma=2G or hugetlb_cma=0:1G,1:1G). This can be restrictive in heterogeneous environments or when deploying common kernel command lines across machines with different memory capacities.
Add support for percentage-based hugetlb_cma reservation (e.g., hugetlb_cma=20% or hugetlb_cma=0:20%,1:10%).
The percentage is calculated against the total memory (for global settings) or against the node-specific memory (for node-specific settings) using memblock APIs during early boot.
---
v5:
- Document in kernel-parameters.txt that percentage-derived sizes are rounded down to a multiple of the gigantic hugepage size and may become zero (Usama Arif).
- Add Acked-by: Usama Arif <[email protected]>.
v4:
- Clear global hugetlb_cma_percent and hugetlb_cma_size when node-specific parameters are parsed so the last command line configuration wins (Usama Arif).
- Warn when ALIGN_DOWN rounds down a non-zero percentage-derived reservation size to 0 MiB (Usama Arif).
v3:
- Enhance pr_info logs to explicitly show percentage-derived sizes per Andrew Morton's suggestions.
- Explicitly align percentage-derived sizes down to the gigantic page size to prevent allocation failures (Usama Arif).
.../admin-guide/kernel-parameters.txt | 10 +- mm/hugetlb_cma.c | 141 +++++++++++++++++- 2 files changed, 141 insertions(+), 10 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +8 -2
@@ -2064,8 +2064,14 @@ Kernel parameters hugetlb_cma= [HW,CMA,EARLY] The size of a CMA area used for allocation of gigantic hugepages. Or using node format, the size of a CMA area per node can be specified. - Format: nn[KMGTPE] or (node format) - <node>:nn[KMGTPE][,<node>:nn[KMGTPE]] + The size can be an absolute value (e.g., 2G) or a + percentage of the total memory or node memory (e.g., 20%). + Percentage-derived sizes are rounded down to a multiple of + the architecture's gigantic hugepage size and may become + zero. + Format: nn[KMGTPE] or nn% or (node format) + <node>:nn[KMGTPE][,<node>:nn[KMGTPE]] or + <node>:nn%[,<node>:nn%] Reserve a CMA area of given size and allocate gigantic hugepages using the CMA allocator. If enabled, the
mm/hugetlb_cma.c +133 -8
196 lines not on this page · raw message
Signature · 1 line
2.55.0.679.g6767b8d81c-goog