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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9B68AC433DB for ; Fri, 19 Feb 2021 10:53:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 17D6464EF8 for ; Fri, 19 Feb 2021 10:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 17D6464EF8 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 7C4988D0019; Fri, 19 Feb 2021 05:53:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79A0C8D000A; Fri, 19 Feb 2021 05:53:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 689CB8D0019; Fri, 19 Feb 2021 05:53:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 4FEAC8D000A for ; Fri, 19 Feb 2021 05:53:46 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 16E3D181AF5C6 for ; Fri, 19 Feb 2021 10:53:46 +0000 (UTC) X-FDA: 77834706852.15.325B1CD Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 98AF0600249D for ; Fri, 19 Feb 2021 10:53:42 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id s16so3149505plr.9 for ; Fri, 19 Feb 2021 02:53:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yUS9qNpkZbJSnIup5wcCJPaYw6pSjle5WwxW0514c70=; b=lwq4w0mNryxcojF1AHwzPzs/dz5mdKgGkbf7trkVA1vm92+chl3bthuADEito25Ba3 y6A3UHQmXzxnCiLm4Dms8CVG1fD4zTmnVnTFkMsV0Ibon8eCOz+WrM5bdJg++DygMUv2 WIuEl4P59gqZ5+K/Lyw80O9nhHivuU14jAec6CTD480EPu/muFtYKuZ2yXSFDf1N0hE7 Hum2QFGypeRwjrcnvPe6fsu3EI8e3/D9k4cle1OfWr3wrJx+iISqtj/RdAbeao7eZD+v tIB5iU3v/K1FoNAWfKzPx5EPZYVxzhoi0oFXJTw/xO7VcBDn9r2wgeqrqDACsluSwoTc V2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yUS9qNpkZbJSnIup5wcCJPaYw6pSjle5WwxW0514c70=; b=mmOVsFDx9JFYPKJxdpYX7mGKV7MW+DSn0+cHMV1a5GeQRAto2fY1+uRlq81NFnGuyg n5CF5EuiEGw4KtKLRZcBb+1ZjD4UfXGCDVUGmjhwsmbuCQcKbsLSZbDEaPsKfy2zZAWR F4+QtIGkA4KWLN9OIWd2TZ77A3/LUX+RQLHWP39Wh1KMdwHM84g+YqLZu8Yo/XjKtxRu CI/yToNVPHdGOj6mbah04L2PdrO1mHLJrotpMgRcLdQnvjr/106xwMwPsuT1KvyBqyvr Gj0Uk+BSnAaCvLSEFAWwsYtJpHizNIsX3Ah3b/VoCHKrV8tcv4XZd2XSgYwTRGyIqz/u x3kA== X-Gm-Message-State: AOAM533OZr+8bmsdErB9q+RDL0IYWnXj1wN3Ps+uVpGx7wWMPtOTv/d8 U6KUFscLc56+i9bn7ApKZNxYJA== X-Google-Smtp-Source: ABdhPJyB5WZMeDWoyUkjPOMlachVxvvFod144fxl8bbB0lmthUAShtFzj3K5VoXcb0cR5XGI9WC6WQ== X-Received: by 2002:a17:902:e989:b029:e2:8c9d:78ba with SMTP id f9-20020a170902e989b02900e28c9d78bamr1281160plb.81.1613732022712; Fri, 19 Feb 2021 02:53:42 -0800 (PST) Received: from localhost.localdomain ([139.177.225.250]) by smtp.gmail.com with ESMTPSA id x1sm9662193pgj.37.2021.02.19.02.53.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Feb 2021 02:53:42 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com, david@redhat.com, naoya.horiguchi@nec.com, joao.m.martins@oracle.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song , Miaohe Lin Subject: [PATCH v16 9/9] mm: hugetlb: optimize the code with the help of the compiler Date: Fri, 19 Feb 2021 18:49:54 +0800 Message-Id: <20210219104954.67390-10-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210219104954.67390-1-songmuchun@bytedance.com> References: <20210219104954.67390-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 98AF0600249D X-Stat-Signature: goubddnsxtgsdrqqzfks55qtp7gryo9e Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=mail-pl1-f172.google.com; client-ip=209.85.214.172 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613732022-907158 Content-Transfer-Encoding: quoted-printable 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: 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 Reviewed-by: Miaohe Lin Reviewed-by: Oscar Salvador --- 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 caeef778526a..8d684edc3bf9 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -882,7 +882,8 @@ extern bool hugetlb_free_vmemmap_enabled; =20 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 >=3D RESERVE_VMEMMAP_SIZE / sizeof(struct page)); =20 + /* + * 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; =20 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 --=20 2.11.0