@@ -878,7 +878,8 @@ extern bool hugetlb_free_vmemmap_enabled;
static inline bool is_hugetlb_free_vmemmap_enabled(void)
{
- return hugetlb_free_vmemmap_enabled;
+ return hugetlb_free_vmemmap_enabled &&
+ is_power_of_2(sizeof(struct page));
}
#else
static inline bool is_hugetlb_free_vmemmap_enabled(void)
@@ -211,6 +211,12 @@ early_param("hugetlb_free_vmemmap", early_hugetlb_free_vmemmap_param);
*/
static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h)
{
+ /*
+ * This check aims to let the compiler help us optimize the code as
+ * much as possible.
+ */
+ if (!is_power_of_2(sizeof(struct page)))
+ return 0;
return h->nr_free_vmemmap_pages;
}
@@ -280,6 +286,13 @@ void __init hugetlb_vmemmap_init(struct hstate *h)
BUILD_BUG_ON(NR_USED_SUBPAGE >=
RESERVE_VMEMMAP_SIZE / sizeof(struct page));
+ /*
+ * The compiler can help us to optimize this function to null
+ * when the size of the struct page is not power of 2.
+ */
+ if (!is_power_of_2(sizeof(struct page)))
+ return;
+
if (!hugetlb_free_vmemmap_enabled)
return;