From patchwork Thu Dec 10 03:55:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11963249 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,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 31D20C4361B for ; Thu, 10 Dec 2020 03:59:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA8A423BC7 for ; Thu, 10 Dec 2020 03:59:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA8A423BC7 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 6B81D6B0036; Wed, 9 Dec 2020 22:59:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 667366B0070; Wed, 9 Dec 2020 22:59:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 509976B0072; Wed, 9 Dec 2020 22:59:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 3C4F76B0070 for ; Wed, 9 Dec 2020 22:59:31 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 08EA3180AD815 for ; Thu, 10 Dec 2020 03:59:31 +0000 (UTC) X-FDA: 77576018142.25.lift26_5d06740273f5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id DE32D1804E3A0 for ; Thu, 10 Dec 2020 03:59:30 +0000 (UTC) X-HE-Tag: lift26_5d06740273f5 X-Filterd-Recvd-Size: 5514 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Dec 2020 03:59:30 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id p4so2803288pfg.0 for ; Wed, 09 Dec 2020 19:59:30 -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=t1l4xMSE0KQnA71H//bDmskGduWipXvDa6Vox+ZjNms=; b=hMRBPFb96XJumXLHyGTTwBklAUnIrxY7ck3bVW6zB94E5E1bc8M4k6wRlkORblzegV U5lvw2LfOIBvWm70vSuLDEgphWueRmLtAcavEysLQ5ehechfmSU3Ipi0TQWhQxUh3fHU enQTfmCl5wcAOp4vSyEMwEiXSHozesuQAfXUZ6fBkXFMzThmMoahvOptGtxCChZaB4XP 20mAdPoysLnFwGnxcQGOb5pWjsSUWLErW/qIG10Grlgi3RBcVRbvDii7ytREaV09QuxP 79KAVZ1RimWNnqGRmifxuj5st5dcIkCJG/ehffyI5jMdPmllwYixCXtBDTnsPx3b4BOl kbLg== 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=t1l4xMSE0KQnA71H//bDmskGduWipXvDa6Vox+ZjNms=; b=dqbcaYpLx7iw/SIw6TkQ4dq8DgziwCkVcK9VFxlCe8CRGBl/aMaE/WbCMPQ6t52MRn GrX1FeK8Pl69gqJ3aDuzrOv8Ycqdy/7RedQu5tn96T/zcAt4HJt2W+M/VXZh9UgWA9mK H3MGM8z0G9jYemm96FiL1wqSiz6Tp4y8oBI1oRj0OtYpSaaSU9uxcdYkRcVVuP3qjTjT /Zjo7cFI6eyBb5Dtwg130UwXStI3wnCYo0i4NXcrKETaCqGdmuGwZRj1e/thl+vJJDHG BsMTIOoFYd8zE0DQ8GCGgFgvDexfvhq+I8JRHou9chyg2GyLdqFwjGassAsiW0b23d3U NcjQ== X-Gm-Message-State: AOAM531Vp4nl7XhehSVYdzrxOlZbSyhqJihv5uWzc8dVPhi6fEnSVGKz Ff8pfYROoAkLCnJKKg7CjQ+iTw== X-Google-Smtp-Source: ABdhPJydwdYQo79U6PP08VNvTBIzTtWxejp8DNMvx8xTTULpe736PdBuGNl589ah44qPUz1qAf8ZKw== X-Received: by 2002:a17:90a:c306:: with SMTP id g6mr5511722pjt.104.1607572769408; Wed, 09 Dec 2020 19:59:29 -0800 (PST) Received: from localhost.localdomain ([103.136.220.85]) by smtp.gmail.com with ESMTPSA id f33sm4266535pgl.83.2020.12.09.19.59.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 19:59:28 -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 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 v8 12/12] mm/hugetlb: Optimize the code with the help of the compiler Date: Thu, 10 Dec 2020 11:55:26 +0800 Message-Id: <20201210035526.38938-13-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201210035526.38938-1-songmuchun@bytedance.com> References: <20201210035526.38938-1-songmuchun@bytedance.com> MIME-Version: 1.0 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 | 3 +++ mm/hugetlb_vmemmap.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 7295f6b3d55e..adc17765e0e9 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -791,7 +791,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 7f0b9e002be4..819ab9bb9298 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -208,6 +208,9 @@ bool hugetlb_free_vmemmap_enabled; static int __init early_hugetlb_free_vmemmap_param(char *buf) { + if (!is_power_of_2(sizeof(struct page))) + return 0; + if (!buf) return -EINVAL; diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index 0a1c0d33a316..5f5e90c81cd2 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -21,7 +21,7 @@ void free_huge_page_vmemmap(struct hstate *h, struct page *head); */ static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h) { - return h->nr_free_vmemmap_pages; + return h->nr_free_vmemmap_pages && is_power_of_2(sizeof(struct page)); } #else static inline void hugetlb_vmemmap_init(struct hstate *h)