[PATCH v2 18/69] mm/hugetlb: Remove unused bootmem cma field

From: Muchun Song

Date: Wed May 13 2026 - 09:28:45 EST


struct huge_bootmem_page no longer needs to keep the CMA pointer. The
bootmem path only needs to remember whether a huge page came from CMA,
which is already encoded in the flags field.

Set HUGE_BOOTMEM_CMA when the page is allocated and drop the unused cma
field together with the redundant assignments.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
include/linux/hugetlb.h | 1 -
mm/hugetlb.c | 5 +----
mm/hugetlb_cma.c | 27 ++++++++++-----------------
3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index ece4e6a4a4c6..fd901bb3630c 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -694,7 +694,6 @@ struct huge_bootmem_page {
struct list_head list;
struct hstate *hstate;
unsigned long flags;
- struct cma *cma;
};

#define HUGE_BOOTMEM_HVO 0x0001
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index dcf8e09ec6be..1f0a0e31d624 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3093,10 +3093,7 @@ static bool __init alloc_bootmem_huge_page(struct hstate *h, int nid)
*/
INIT_LIST_HEAD(&m->list);
m->hstate = h;
- if (!hugetlb_early_cma(h)) {
- m->cma = NULL;
- m->flags = 0;
- }
+ m->flags = hugetlb_early_cma(h) ? HUGE_BOOTMEM_CMA : 0;

/* CMA pages: zone-crossing is validated in hugetlb_cma_reserve(). */
if (!hugetlb_early_cma(h) &&
diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c
index 6b5c2aec4449..fbe5ed7ffaa7 100644
--- a/mm/hugetlb_cma.c
+++ b/mm/hugetlb_cma.c
@@ -65,26 +65,19 @@ hugetlb_cma_alloc_bootmem(struct hstate *h, int nid, bool node_exact)

cma = hugetlb_cma[nid];
m = cma_reserve_early(cma, huge_page_size(h));
- if (!m) {
- if (node_exact)
- return NULL;
+ if (m || node_exact)
+ return m;

- for_each_node_mask(node, hugetlb_bootmem_nodes) {
- cma = hugetlb_cma[node];
- if (!cma || node == nid)
- continue;
- m = cma_reserve_early(cma, huge_page_size(h));
- if (m)
- break;
- }
- }
-
- if (m) {
- m->flags = HUGE_BOOTMEM_CMA;
- m->cma = cma;
+ for_each_node_mask(node, hugetlb_bootmem_nodes) {
+ cma = hugetlb_cma[node];
+ if (!cma || node == nid)
+ continue;
+ m = cma_reserve_early(cma, huge_page_size(h));
+ if (m)
+ return m;
}

- return m;
+ return NULL;
}

static int __init cmdline_parse_hugetlb_cma(char *p)
--
2.54.0