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=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 DD048C433DB for ; Fri, 5 Feb 2021 09:16:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C86F64F87 for ; Fri, 5 Feb 2021 09:16:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C86F64F87 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C3B8A6B006E; Fri, 5 Feb 2021 04:16:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEE4D6B0071; Fri, 5 Feb 2021 04:16:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFFED6B0072; Fri, 5 Feb 2021 04:16:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 976186B006E for ; Fri, 5 Feb 2021 04:16:53 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 645BD180AD811 for ; Fri, 5 Feb 2021 09:16:53 +0000 (UTC) X-FDA: 77783659506.23.sheet32_0711086275e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 4904137608 for ; Fri, 5 Feb 2021 09:16:53 +0000 (UTC) X-HE-Tag: sheet32_0711086275e3 X-Filterd-Recvd-Size: 6535 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Feb 2021 09:16:52 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id x9so3251596plb.5 for ; Fri, 05 Feb 2021 01:16:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JKBbTXlpTBr2zkO3oY2VYzHBYqP1g9U9wb97XhjPk3c=; b=j7JyuYJPrQMqeqz2xvLh4JkheheodV0fbqZ+U5Nyi+WlHItSQ/S5FhNeMvX3ErJFo0 a/uKfBqkKYGqTHCIzbz3OIxi7IAwIL/dtcEPj0yabvtrpkv+ac86EWgnu9iWMwThbY/9 kkrEPfq+wxD2BEgUDga2Ap10+8GrkdtO8FEw4+ZOXdNiMGKXbCcKs7nKu7BbSHSMlSwW WSVqrtQfbeD1UOBLKhUXbi9V7gfRLUS9H/v5W/tixV7HKePviu+pHr5lINyLf8GwRVC4 gxUFexvRlUBrJsm87ZD+E7EbrSmvltyn5C2GCAgHlgIq78Y0gsThcpTFsa2q0k3MMa2y 3dwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JKBbTXlpTBr2zkO3oY2VYzHBYqP1g9U9wb97XhjPk3c=; b=EsWaznMvN14Jlf9Vt2U9U3MM93u7sXBE4r4XQEqQtlYkyi2q+biFOkmokAzzYJzrJN t/IhgZg9+tZAHfhgQFJrrxTEcvVWEBjFg7+fvcDbE4hNTqq12bZ2q/44T8AbXJEzJBEo K1kyLINSmoe9QQ/ULWs9X1XcGPFaouAo0CM20bojUgr6HBM8TtAb+phoA9AtujeGv+Hs TA3UpIyoe4nAybBDhTnwrYhnFT4Z4O7PRo7sdkZxdq+HBnzX4Os+Wra7pYz11TbwM9GF J0KbMVMcIh5Uf3FDxsZWarXh43DEZmEcpV6acbyEDWZN/l/4vwYIURceN5XF/GtC5vUK dXqQ== X-Gm-Message-State: AOAM531Ewt3oyvjDorZ6vA7Kw6LxKVXmpVXBXvBQJpvPFPQyp+CUxK4i Wyw5zmxsJDTlPHrK/UkGx+VrNjNYBWhAYeIo8Qla0g== X-Google-Smtp-Source: ABdhPJxZ6G6+qg2ZmOZzWsRNHh2l3AmLgDkONGW2As0+kb3WJmj4TRcnH8wewkq5uTSX/8vKKt1X+HLNb6wSWA/XJ6M= X-Received: by 2002:a17:90b:1096:: with SMTP id gj22mr3172401pjb.229.1612516611919; Fri, 05 Feb 2021 01:16:51 -0800 (PST) MIME-Version: 1.0 References: <20210204035043.36609-1-songmuchun@bytedance.com> <20210204035043.36609-9-songmuchun@bytedance.com> <20210205090924.GA14537@linux> In-Reply-To: <20210205090924.GA14537@linux> From: Muchun Song Date: Fri, 5 Feb 2021 17:16:14 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v14 8/8] mm: hugetlb: optimize the code with the help of the compiler To: Oscar Salvador Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Michal Hocko , "Song Bao Hua (Barry Song)" , David Hildenbrand , =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" 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 Fri, Feb 5, 2021 at 5:09 PM Oscar Salvador wrote: > > On Thu, Feb 04, 2021 at 11:50:43AM +0800, 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. > > "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." > > I think the above is more clear, but just a suggestion. OK. I will use it. Thanks for your suggestions. > > > > Signed-off-by: Muchun Song > > Reviewed-by: Oscar Salvador Thanks. > > > --- > > 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; > > > > -- > > 2.11.0 > > > > > > -- > Oscar Salvador > SUSE L3