Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp392716pxb; Thu, 25 Feb 2021 05:30:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwukKiB1G+hmdo12JK80EiPhDrb1Rbi7aJIL+TdRLypA9bruwVgVfGueVMHQqo6Kq0bjbrs X-Received: by 2002:a17:906:edd7:: with SMTP id sb23mr2661679ejb.189.1614259817739; Thu, 25 Feb 2021 05:30:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614259817; cv=none; d=google.com; s=arc-20160816; b=MRKIqDEHY2LtfU4GmR/qUo0iw+6QU2Fc66WCN6SkpOuxI3yo7P3i150gA/Lbo+ywa9 mpnLyoE5TuszIcsJGI7JdZOLUN1vpd/Yi0sbMsli6PqDTzRqiSBPIza1aSxC8mqYqBX7 9q7EwfItUfO5LaUkeqbYbFIIXTYwt4ygXvNo9G30+hPq2p8EKAQ4ochrnKWtbuqIihMg o5ILDTWNc5TXXP9tKyfBAHzWt5UemEEmYx59Q2vTFAHQ37J4amHj5pXc4nvRZ5ZWqn+h PzNPZba9E9KjwC2FxG/qUALgVYSbHZb5YRTxsjBvwnsPiLtindF2k4FMuIqbQjW/fAxz YVtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8ALjwDjgfUCiRRnXNhxLFUeqrygsVEGlc9yJ4oh1b9U=; b=Kbo5lwZSRIXNkP1jjBzZM0mqMCU3copUl4RehldfkfTUETGPsy79n24usg0gH+ZMzk D5buhLxSffRtYYI1+wNjdHCreXDiCRfBKvTB6+WAP7S63pbZP46iBrhnBAa5vdhfCB/s KcL1yFvXrLvBxmoZH6oHEp2PiptzKzACvHMIokwdfVV3Y30Y58kc2qQ5wreLMUEYL4R5 +YOzDWamiMarcQHdRMPObviKZAwA3350Hpdj6JwqKNF0xfFsKYXExe0Rjxhu9tsjqbkf M5Q4yyFe8O1QmnXRltPmETk/5iLYDEeSRXiGo09jIu+BtgfCM8gpgCngRG+Ev72HR0VP 6eVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=r7vMI9nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si3123774ejf.359.2021.02.25.05.29.55; Thu, 25 Feb 2021 05:30:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=r7vMI9nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232608AbhBYN3D (ORCPT + 99 others); Thu, 25 Feb 2021 08:29:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbhBYN0G (ORCPT ); Thu, 25 Feb 2021 08:26:06 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03A76C061794 for ; Thu, 25 Feb 2021 05:25:15 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id s23so3533361pji.1 for ; Thu, 25 Feb 2021 05:25:14 -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=8ALjwDjgfUCiRRnXNhxLFUeqrygsVEGlc9yJ4oh1b9U=; b=r7vMI9nuwloCcNdm4J58arhY9tNRTBqTiQSwQJBN59w7gi4btn70OWjmOooR0x6thC lZhEGaY9aNmJQZxZoxHZOGD/5p+pk9/pjZ72jo8ld/ETlJm5E+kC2LnLvFvaFXPaa3Wp xmADPF4HQynTcJwZ9lWHOB8ulgRkiBQDARs8rhVrkVEBHMHpazOEP2PHjcFDY5rtuxu2 Q0aIyo5WPKczq+9RJPndJLumrbzv6BD9p4wJfjIbvdGArSZ5n4k60QgERyD/gOSQacwM T8NcZlacEJrFiyXHItA+/S7jmjuO/bkegFQPahWMxQl+VMVmfIJQb44E2R6jP5qYWQ9x KdGQ== 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=8ALjwDjgfUCiRRnXNhxLFUeqrygsVEGlc9yJ4oh1b9U=; b=qorxCX4du9ZpzS33KHtGrF8dEAQ6tkdbW8cCdgECi7Wgv6NRg74zwfott+e7a5wvVJ HCvpEKaTM5L/JXP73q1gL4SAOCCRcDqd5ZOHG4pZjQ+MNntujrqfdPjtxPg8ARb0IF6p 3eeLuTfccQ0x/Ob0hPbTu4OOPZIc0D1/BbnRUTncsS2gj6/Cckc4jZOcOxnqlfQXLFmK +NSoNOrhVeXUlLCVrPuRhrQtGvGSDPkOy7hhrr0Yf4sGDhPluP01xvfH/+x7EAo+s4iF ukvVcGO+lyEMRUFBGuZOmNAeo08OWNcjNfUA/lFwV/3AbXaOU5gZv1BHBsC/SuokWpqL 6g9A== X-Gm-Message-State: AOAM532dGq0M1IkJS34bUu0Ahg6Li0AFTYA7pTLZWyMVLrLqvvc/QU7t GUEvYDAGJWlN7GhNLgcuti6a1g== X-Received: by 2002:a17:90a:4a8c:: with SMTP id f12mr3327933pjh.71.1614259514605; Thu, 25 Feb 2021 05:25:14 -0800 (PST) Received: from localhost.localdomain ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id x190sm6424676pfx.166.2021.02.25.05.25.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Feb 2021 05:25:14 -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 v17 9/9] mm: hugetlb: optimize the code with the help of the compiler Date: Thu, 25 Feb 2021 21:21:30 +0800 Message-Id: <20210225132130.26451-10-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210225132130.26451-1-songmuchun@bytedance.com> References: <20210225132130.26451-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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