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 AA4F4C433DB for ; Thu, 4 Feb 2021 03:55:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 428E464F5F for ; Thu, 4 Feb 2021 03:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 428E464F5F 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 9B2AB6B006E; Wed, 3 Feb 2021 22:55:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93B066B007D; Wed, 3 Feb 2021 22:55:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DBD56B007E; Wed, 3 Feb 2021 22:55:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 686126B006E for ; Wed, 3 Feb 2021 22:55:33 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 37A8F180AD815 for ; Thu, 4 Feb 2021 03:55:33 +0000 (UTC) X-FDA: 77779220946.12.mass44_500ffff275d9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 0FF17180192F4 for ; Thu, 4 Feb 2021 03:55:33 +0000 (UTC) X-HE-Tag: mass44_500ffff275d9 X-Filterd-Recvd-Size: 5590 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 4 Feb 2021 03:55:32 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id s15so1026590plr.9 for ; Wed, 03 Feb 2021 19:55:32 -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=zwPSy3xaz2ygLc8F0EEvzUcUfzPRqv7+jHlrmdqCzjc=; b=v5kc7WwUbJ4SxZoErP44Ut/YnimhGLmSGr8Q0pMvjK5MyOeqBjchjsm0dHwo9qTxiL L6o92hOcgljhXYgPK7t24RMk26k8jSQAl6t0nHe4iuHxFQhkqed+9AGjRwOSYiBtkWta lWJgGumyexzq2I5hO4O8GVm9ptnIJfHGx37Vb9jlOKvWqgy8ZUQlug/dNU2UVlfX72v8 iNPfFEKzU4oPA4XIv/ckuMhQVgjqgzksq5w4MhnAGMpW8l8TvHOTfSVIQIVZD2d2nAvD MnL3T49dN822vH1juzrinW1+AMA0T5yeOrtJ8cjhYfM9Nwn9BDHlhwhToPundS0A0pGD V5Iw== 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=zwPSy3xaz2ygLc8F0EEvzUcUfzPRqv7+jHlrmdqCzjc=; b=UCW6J/HTlmkAz/sL6YLeKZatChwARLQ3CHH+xiadDy7ri3a3hocpsjg6aYL6Hnqdah vWGgx7jdjy5msKqvjSl9m3iibod3SxnNgEhertUJ2ks2uE4nNsY9V79uBkPrWMyBiTu0 cR9eraLJ9O8grzqZ32QRVrtUB46amzJnd9L0ZdTOdBPcHcz2RWu4ZNeHRZ3zY/ulOqH7 yTa4ad0E3ZUz2ZFDsWJVozzTfu/9597xCFhbGfe5XWElmQNOf34iKmInSGEgsbzUXRk7 tPn3vbohLyACHemlb+8yLxdJnIEb4o62q872WACBP2sw6eDBj6vvQe8EGRR0l6R3Dl/F PD5w== X-Gm-Message-State: AOAM533fpx8CMVapgq0RcBYKcqgiEqUom7yRw4rm/pr2hZlAUgU2stR2 vWfVoHvntceoPUHKqQ53BksaZw== X-Google-Smtp-Source: ABdhPJy4MLo6bnYUrOasPbRmFl1je+GxUk4n9GPPf9oQIxXGXHU1yRbe2z30qs735BvQJrsnJluAFQ== X-Received: by 2002:a17:90b:4004:: with SMTP id ie4mr6140969pjb.114.1612410931841; Wed, 03 Feb 2021 19:55:31 -0800 (PST) Received: from localhost.localdomain ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id 9sm3747466pfy.110.2021.02.03.19.55.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Feb 2021 19:55:31 -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 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 Subject: [PATCH v14 8/8] mm: hugetlb: optimize the code with the help of the compiler Date: Thu, 4 Feb 2021 11:50:43 +0800 Message-Id: <20210204035043.36609-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210204035043.36609-1-songmuchun@bytedance.com> References: <20210204035043.36609-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: 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 --- 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; =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 8efad9978821..068d0e0cebc8 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -211,6 +211,12 @@ early_param("hugetlb_free_vmemmap", early_hugetlb_fr= ee_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; } =20 @@ -280,6 +286,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 --=20 2.11.0