Make hugetlb_vmemmap_optimizable() reuse the generic order_vmemmap_optimizable() logic, and switch hugetlb boolean call sites to use the dedicated helper directly.
This keeps HugeTLB-specific optimizable checks aligned with the generic vmemmap optimization rules and avoids open-coding the size-based test. Signed-off-by: Muchun Song <[email protected]> --- include/linux/hugetlb.h | 2 +- mm/hugetlb.c | 4 ++-- mm/hugetlb_vmemmap.h | 43 ++++++++++++++++++++--------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 82dbb9ebead8..2383adb22ce1 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -778,7 +778,7 @@ static inline unsigned long huge_page_mask(struct hstate *h) return h->mask; } -static inline unsigned int huge_page_order(struct hstate *h) +static inline unsigned int huge_page_order(const struct hstate *h) { return h->order; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 54ef7d12c585..bd136fc6aec0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3351,7 +3351,7 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, &node_states[N_MEMORY], NULL); if (!folio && !list_empty(&folio_list) && - hugetlb_vmemmap_optimizable_size(h)) { + hugetlb_vmemmap_optimizable(h)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, @@ -3420,7 +3420,7 @@ static void __init hugetlb_pages_alloc_boot_node(unsigned long start, unsigned l for (i = 0; i < num; ++i) { struct folio *folio; - if (hugetlb_vmemmap_optimizable_size(h) && + if (hugetlb_vmemmap_optimizable(h) && (si_mem_available() == 0) && !list_empty(&folio_list)) { prep_and_add_allocated_folios(h, &folio_list); INIT_LIST_HEAD(&folio_list); diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index dfd48be6b231..1765f8274220 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -18,22 +18,6 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h, void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio); void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list); void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m); - -static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h) -{ - return pages_per_huge_page(h) * sizeof(struct page); -} - -/* - * Return how many vmemmap size associated with a HugeTLB page that can be - * optimized and can be freed to the buddy allocator. - */ -static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) -{ - int size = hugetlb_vmemmap_size(h) - OPTIMIZED_FOLIO_VMEMMAP_SIZE; - - return size > 0 ? size : 0; -} #else static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio) { @@ -56,11 +40,6 @@ static inline void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list { } -static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) -{ - return 0; -} - static inline void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m) { } @@ -68,6 +47,26 @@ static inline void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_pag static inline bool hugetlb_vmemmap_optimizable(const struct hstate *h) { - return hugetlb_vmemmap_optimizable_size(h) != 0; + if (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP)) + return false; + + return order_vmemmap_optimizable(huge_page_order(h)); +} + +static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h) +{ + return pages_per_huge_page(h) * sizeof(struct page); +} + +/* + * Return the size of the vmemmap area associated with a HugeTLB page + * that can be optimized. + */ +static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h) +{ + if (!hugetlb_vmemmap_optimizable(h)) + return 0; + + return hugetlb_vmemmap_size(h) - OPTIMIZED_FOLIO_VMEMMAP_SIZE; } #endif /* _LINUX_HUGETLB_VMEMMAP_H */ -- 2.54.0
