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.8 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 B4012C433DB for ; Thu, 11 Mar 2021 07:34:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED29764FC0 for ; Thu, 11 Mar 2021 07:34:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED29764FC0 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 52C8A8D027B; Thu, 11 Mar 2021 02:34:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DC858D0250; Thu, 11 Mar 2021 02:34:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3563E8D027B; Thu, 11 Mar 2021 02:34:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id 158AE8D0250 for ; Thu, 11 Mar 2021 02:34:01 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CEA0C4DCF for ; Thu, 11 Mar 2021 07:34:00 +0000 (UTC) X-FDA: 77906779440.17.7DDFFB1 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 8EC0F6000102 for ; Thu, 11 Mar 2021 07:33:56 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id 16so6702464pgo.13 for ; Wed, 10 Mar 2021 23:33:58 -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=PRwM5iGLtwZBTnG8om/++s86+EBuCATUoQNKFoo4Vus=; b=CokBfhYF94Mz/PQxCgAws4A6RnAg0Rhfn9RMSb1BX25wrdmVgzZPCbYYIxXJsmHYTB 6BcvY6NwLwD/zR8WjrkD3uwQoFPwbW0tZstyoG2ypygIGqNezSd3TZDlyvtp3+41WOvb RCUT10zMp6cIjsMD7ae40s5aJBwKeeF9OoEtxpcEcGejDlUgFs2FldnIlJWtAd6FjlnV IZIoVrE5M+CqvBAxr1FFevb45gI6JqjyJB8C6qfxmMFb3ebPKuoVrdpQmUeW/4FrwHQd sdOgA4hUun59ScPunvN91nYpGcjbNf1hb57ZrFnSDtR6hccNAT76r99kAVbsAFlzFjFZ O09A== 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=PRwM5iGLtwZBTnG8om/++s86+EBuCATUoQNKFoo4Vus=; b=FbP9jB/ZYdppHZZ6D/5Rl1BHtKlPWEdHEFiNDOtvdQMw9uLqqUIv5SSOf1xHCDOD92 rK+slTeFGBCCMK2tT4ObHlriEEan9O8khAevcmYXIireP9xnFuRk8ITe3tI9/uMOOc6y XqhAwUNnMaqQLCYsshMP0y2VADt8cezEQryRLYJ5rgF5TDyO8V+nnAnMdF2cy1/ds3yp RiM0gIxRiJzO/+y8Yje0JvDvbk17KPbVigQ/x1ZpnaSnjpVrE2V0iajThre99Deo/rrY +JaTAeTZEwCzDNsNadCDVfBl+AxqJGxRx6RGvldYgvInw2+yrWR81QgFngkP2/Cx0xPN 2UHA== X-Gm-Message-State: AOAM530KUsPr0jDCgdKMe9L7UOjxY8+cQKj49tWgblRfxRMi2NYV0spC M07YvEOi/7vHmDu26wqGDYUDcZJqUbawtESbRq/XbA== X-Google-Smtp-Source: ABdhPJxI8OpzzjMHc+EojMt4EpAQ1I5fSlulun0k4KemCXO9upjJHTPuwi6LSd+hznDbn0zA0DfJtSI2TRcL1/7lLY4= X-Received: by 2002:a63:141e:: with SMTP id u30mr6322639pgl.31.1615448037407; Wed, 10 Mar 2021 23:33:57 -0800 (PST) MIME-Version: 1.0 References: <20210308102807.59745-1-songmuchun@bytedance.com> <20210308102807.59745-10-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Thu, 11 Mar 2021 15:33:20 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v18 9/9] mm: hugetlb: optimize the code with the help of the compiler To: Michal Hocko Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , Ingo Molnar , bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , Alexander Viro , 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 , Oscar Salvador , "Song Bao Hua (Barry Song)" , David Hildenbrand , =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Joao Martins , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel , Miaohe Lin , Chen Huang , Bodeddula Balasubramaniam Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: jjicwyeogxfje9rz85cdi1q1p5bfassw X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8EC0F6000102 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail-pg1-f178.google.com; client-ip=209.85.215.178 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615448036-417223 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 Wed, Mar 10, 2021 at 11:41 PM Michal Hocko wrote: > > On Mon 08-03-21 18:28:07, Muchun Song wrote: > > 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 am confused. Don't you check for this in early_hugetlb_free_vmemmap_param already? Right. > Why do we need any runtime checks? If the size of the struct page is not power of 2, compiler can think is_hugetlb_free_vmemmap_enabled() always return false. So the code snippet of this user can be optimized away. E.g. if (is_hugetlb_free_vmemmap_enabled()) /* do something */ The compiler can drop "/* do something */" directly, because it knows is_hugetlb_free_vmemmap_enabled() always returns false. Thanks. > > > Signed-off-by: Muchun Song > > Reviewed-by: Miaohe Lin > > Reviewed-by: Oscar Salvador > > Tested-by: Chen Huang > > Tested-by: Bodeddula Balasubramaniam > > --- > > include/linux/hugetlb.h | 3 ++- > > mm/hugetlb_vmemmap.c | 7 +++++++ > > mm/hugetlb_vmemmap.h | 6 ++++++ > > 3 files changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > > index c70421e26189..333dd0479fc2 100644 > > --- a/include/linux/hugetlb.h > > +++ b/include/linux/hugetlb.h > > @@ -880,7 +880,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 33e42678abe3..1ba1ef45c48c 100644 > > --- a/mm/hugetlb_vmemmap.c > > +++ b/mm/hugetlb_vmemmap.c > > @@ -265,6 +265,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; > > > > diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h > > index cb2bef8f9e73..29aaaf7b741e 100644 > > --- a/mm/hugetlb_vmemmap.h > > +++ b/mm/hugetlb_vmemmap.h > > @@ -21,6 +21,12 @@ void hugetlb_vmemmap_init(struct hstate *h); > > */ > > 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; > > } > > #else > > -- > > 2.11.0 > > > > -- > Michal Hocko > SUSE Labs