Whether vmemmap optimization is supported depends on both the configuration and struct page having a power-of-two size. Open-coding this condition in several places makes the support contract easy to duplicate. Express this contract once in vmemmap_optimization_supported(). Make the existing checks use it. No functional change intended. Signed-off-by: Muchun Song Reviewed-by: Lance Yang --- v2: - Collect Reviewed-by from Lance Yang --- include/linux/page-flags.h | 10 ++++++---- include/linux/vmemmap-optimization.h | 14 +++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index b0ddc652e76c..6133966ba292 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -193,6 +193,11 @@ enum pageflags { #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) #ifndef __GENERATING_BOUNDS_H +static __always_inline bool vmemmap_optimization_supported(void) +{ + return IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION) && + is_power_of_2(sizeof(struct page)); +} /* * For tail pages, if the size of struct page is power-of-2 ->compound_info @@ -210,10 +215,7 @@ static __always_inline bool compound_info_has_mask(void) * but it requires validating that struct pages are naturally aligned * for all orders up to the MAX_FOLIO_ORDER, which can be tricky. */ - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - return is_power_of_2(sizeof(struct page)); + return vmemmap_optimization_supported(); } static __always_inline unsigned long _compound_head(const struct page *page) diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h index 985a37dfcab7..0ae8a96a0874 100644 --- a/include/linux/vmemmap-optimization.h +++ b/include/linux/vmemmap-optimization.h @@ -21,9 +21,7 @@ * HVO which is only active if the size of struct page is a power of 2. */ #define MAX_FOLIO_VMEMMAP_ALIGN \ - (IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION) && \ - is_power_of_2(sizeof(struct page)) ? \ - MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0) + (vmemmap_optimization_supported() ? MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0) /* The number of retained vmemmap pages with HVO enabled. */ #define VMEMMAP_OPTIMIZATION_PAGES 1 @@ -33,10 +31,7 @@ static inline bool vmemmap_optimizable_order(unsigned int order) { - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - if (!is_power_of_2(sizeof(struct page))) + if (!vmemmap_optimization_supported()) return false; return order >= VMEMMAP_OPTIMIZATION_MIN_ORDER; @@ -115,10 +110,7 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order { const unsigned long nr_pages = 1UL << order; - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - if (!is_power_of_2(sizeof(struct page))) + if (!vmemmap_optimization_supported()) return false; return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; -- 2.54.0