[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210208085013.89436-9-songmuchun@bytedance.com>
Date: Mon, 8 Feb 2021 16:50:13 +0800
From: Muchun Song <songmuchun@...edance.com>
To: corbet@....net, mike.kravetz@...cle.com, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, x86@...nel.org, hpa@...or.com,
dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
viro@...iv.linux.org.uk, akpm@...ux-foundation.org,
paulmck@...nel.org, mchehab+huawei@...nel.org,
pawan.kumar.gupta@...ux.intel.com, rdunlap@...radead.org,
oneukum@...e.com, anshuman.khandual@....com, jroedel@...e.de,
almasrymina@...gle.com, rientjes@...gle.com, willy@...radead.org,
osalvador@...e.de, mhocko@...e.com, song.bao.hua@...ilicon.com,
david@...hat.com, naoya.horiguchi@....com,
joao.m.martins@...cle.com
Cc: duanxiongchun@...edance.com, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org,
Muchun Song <songmuchun@...edance.com>,
Miaohe Lin <linmiaohe@...wei.com>
Subject: [PATCH v15 8/8] mm: hugetlb: optimize the code with the help of the compiler
When the "struct page size" crosses page boundaries we cannot
make use of this feature. Let free_vmemmap_pages_per_hpage()
return zero if that is the case, most of the functions can be
optimized away.
Signed-off-by: Muchun Song <songmuchun@...edance.com>
Reviewed-by: Miaohe Lin <linmiaohe@...wei.com>
Reviewed-by: Oscar Salvador <osalvador@...e.de>
---
include/linux/hugetlb.h | 3 ++-
mm/hugetlb_vmemmap.c | 13 +++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 822ab2f5542a..7bfb06e16298 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -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)
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index a67301a9d19a..2e7e1d6ee458 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -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;
--
2.11.0
Powered by blists - more mailing lists