From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26057C433DB for ; Thu, 4 Feb 2021 06:34:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A2F3F64F4D for ; Thu, 4 Feb 2021 06:33:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2F3F64F4D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C30CF6B006C; Thu, 4 Feb 2021 01:33:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB9336B006E; Thu, 4 Feb 2021 01:33:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A31D36B0070; Thu, 4 Feb 2021 01:33:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id 88E6B6B006C for ; Thu, 4 Feb 2021 01:33:58 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 534123621 for ; Thu, 4 Feb 2021 06:33:58 +0000 (UTC) X-FDA: 77779620156.29.scarf04_2611491275da Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 3BB8918086CBE for ; Thu, 4 Feb 2021 06:33:58 +0000 (UTC) X-HE-Tag: scarf04_2611491275da X-Filterd-Recvd-Size: 4211 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 06:33:57 +0000 (UTC) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DWTHk4Fwjz1638H; Thu, 4 Feb 2021 14:32:34 +0800 (CST) Received: from [10.174.179.241] (10.174.179.241) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Thu, 4 Feb 2021 14:33:43 +0800 Subject: Re: [PATCH v14 8/8] mm: hugetlb: optimize the code with the help of the compiler To: Muchun Song CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20210204035043.36609-1-songmuchun@bytedance.com> <20210204035043.36609-9-songmuchun@bytedance.com> From: Miaohe Lin Message-ID: <657ef0d7-8c68-a0f2-de16-d524f0eb4cc7@huawei.com> Date: Thu, 4 Feb 2021 14:33:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210204035043.36609-9-songmuchun@bytedance.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.241] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021/2/4 11:50, Muchun Song wrote: > We cannot optimize if a "struct page" crosses page boundaries. If > it is true, we can optimize the code with the help of a compiler. > When free_vmemmap_pages_per_hpage() returns zero, most functions are > optimized by the compiler. > > Signed-off-by: Muchun Song I like it. Thanks. Reviewed-by: Miaohe Lin > --- > 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 8efad9978821..068d0e0cebc8 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; > >