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,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 39BEDC4361B for ; Sun, 13 Dec 2020 15:47:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AEE2223137 for ; Sun, 13 Dec 2020 15:47:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEE2223137 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 498656B005D; Sun, 13 Dec 2020 10:47:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 449686B0074; Sun, 13 Dec 2020 10:47:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 337676B0075; Sun, 13 Dec 2020 10:47:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 1D3446B005D for ; Sun, 13 Dec 2020 10:47:56 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E1B378249980 for ; Sun, 13 Dec 2020 15:47:55 +0000 (UTC) X-FDA: 77588689710.24.earth60_530683d27413 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id C7B7B1A4A0 for ; Sun, 13 Dec 2020 15:47:55 +0000 (UTC) X-HE-Tag: earth60_530683d27413 X-Filterd-Recvd-Size: 7993 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Sun, 13 Dec 2020 15:47:55 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id bj5so7288871plb.4 for ; Sun, 13 Dec 2020 07:47:55 -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=UoePNyFzH81/Y50VNftfnwrNjalzBPSKlZ0P7dMLO04=; b=1AFD/oCkXSNirCm2p+m1rpWm9khOCZCufBu5Tgmajurx7K4I6b6BCsqvL8xc77/fzI kat3IN3qqNJLwR5zlWxCcHC9H7EK30fIxvRibG0MljEmYIctFLgBm3jXkiiANLngQbra sM9VHAalxMBkHdOi9UkjZO9JUmxlxMe4zyBNC/mDTEa6L1kQrKtcZcdk8s4cG72A4Vu1 3QVIGXoR5/8YOLoLPm3BReuLDqVZG8Zpd8Jb5908r6Gfp2O+tL24XF0X91A5r7vV9VdE mEY7cDuI5NsCsbTQx9IkCk3ixalom1VzliZpNElCCACXDQ+QvpuQtcvdFNb2XaVxq0Is IctQ== 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=UoePNyFzH81/Y50VNftfnwrNjalzBPSKlZ0P7dMLO04=; b=ZNr03hQU67Hi62PcUmlCQZj96XfeHW/Xe0n83uK5fon/ZZm8Fafxqcq4d0yrSGHehw cyKslmuFAaReMmlpIwL7lZ3i/HHorvOhTJUWKddoxyp9YZwQg5RM6kgMswrSevcyeY/S gGCgIhhsyU6QdxlGuHTNpT3cptP0BHDZFJn7g5vxWmGRaOReUKDEBBKVT+/zwBHG32eT vOILldb2e99Z2eo/tZQDvXJQRMnfC1OG1lkgmDAukNyg1OxOdSAHu3iCOLJLA4p+GMmh WJYhEAHxNzQm/Y2gPBp3yICFcQCfLGcHYVrVogWZmi93143JuU9wN5LhvBS4x77CdN1W UT2Q== X-Gm-Message-State: AOAM531uEafahKv0KhABk4WvuuW2bvvkG8lrs9hT0lrPeQ5M86A9bxMC c/5xtm3uEiTcOH7mJnJUIRl18g== X-Google-Smtp-Source: ABdhPJyR6EfcfvwbKvCNayYwEIKpv0lDCQTOqO5hOY0ffty4yveTg5ZvseKOhu8KgsQdcCyOeKc9Xw== X-Received: by 2002:a17:902:d34a:b029:da:861e:ecd8 with SMTP id l10-20020a170902d34ab02900da861eecd8mr18872343plk.45.1607874474534; Sun, 13 Dec 2020 07:47:54 -0800 (PST) Received: from localhost.bytedance.net ([103.136.221.66]) by smtp.gmail.com with ESMTPSA id e24sm13113753pjt.16.2020.12.13.07.47.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Dec 2020 07:47:54 -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 v9 09/11] mm/hugetlb: Introduce nr_free_vmemmap_pages in the struct hstate Date: Sun, 13 Dec 2020 23:45:32 +0800 Message-Id: <20201213154534.54826-10-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201213154534.54826-1-songmuchun@bytedance.com> References: <20201213154534.54826-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: All the infrastructure is ready, so we introduce nr_free_vmemmap_pages field in the hstate to indicate how many vmemmap pages associated with a HugeTLB page that we can free to buddy allocator. And initialize it in the hugetlb_vmemmap_init(). This patch is actual enablement of the feature. Signed-off-by: Muchun Song Acked-by: Mike Kravetz --- include/linux/hugetlb.h | 3 +++ mm/hugetlb.c | 1 + mm/hugetlb_vmemmap.c | 29 +++++++++++++++++++++++++++++ mm/hugetlb_vmemmap.h | 10 ++++++---- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 7f47f0eeca3b..66d82ae7b712 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -492,6 +492,9 @@ struct hstate { unsigned int nr_huge_pages_node[MAX_NUMNODES]; unsigned int free_huge_pages_node[MAX_NUMNODES]; unsigned int surplus_huge_pages_node[MAX_NUMNODES]; +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP + unsigned int nr_free_vmemmap_pages; +#endif #ifdef CONFIG_CGROUP_HUGETLB /* cgroup control files */ struct cftype cgroup_files_dfl[7]; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b0847b2ce01d..2b45235a70e9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3323,6 +3323,7 @@ void __init hugetlb_add_hstate(unsigned int order) h->next_nid_to_free =3D first_memory_node; snprintf(h->name, HSTATE_NAME_LEN, "hugepages-%lukB", huge_page_size(h)/1024); + hugetlb_vmemmap_init(h); =20 parsed_hstate =3D h; } diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 64ad929cac61..d3b4c39f67c0 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -184,6 +184,10 @@ bool hugetlb_free_vmemmap_enabled; =20 static int __init early_hugetlb_free_vmemmap_param(char *buf) { + /* We cannot optimize if a "struct page" crosses page boundaries. */ + if (!is_power_of_2(sizeof(struct page))) + return 0; + if (!buf) return -EINVAL; =20 @@ -222,3 +226,28 @@ void free_huge_page_vmemmap(struct hstate *h, struct= page *head) vmemmap_remap_reuse(vmemmap_addr + RESERVE_VMEMMAP_SIZE, free_vmemmap_pages_size_per_hpage(h)); } + +void __init hugetlb_vmemmap_init(struct hstate *h) +{ + unsigned int nr_pages =3D pages_per_huge_page(h); + unsigned int vmemmap_pages; + + if (!hugetlb_free_vmemmap_enabled) + return; + + vmemmap_pages =3D (nr_pages * sizeof(struct page)) >> PAGE_SHIFT; + /* + * The head page and the first tail page are not to be freed to buddy + * system, the others page will map to the first tail page. So there + * are the remaining pages that can be freed. + * + * Could RESERVE_VMEMMAP_NR be greater than @vmemmap_pages? It is true + * on some architectures (e.g. aarch64). See Documentation/arm64/ + * hugetlbpage.rst for more details. + */ + if (likely(vmemmap_pages > RESERVE_VMEMMAP_NR)) + h->nr_free_vmemmap_pages =3D vmemmap_pages - RESERVE_VMEMMAP_NR; + + pr_info("can free %d vmemmap pages for %s\n", h->nr_free_vmemmap_pages, + h->name); +} diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index b2c8d2f11d48..8fd9ae113dbd 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -13,17 +13,15 @@ #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP void alloc_huge_page_vmemmap(struct hstate *h, struct page *head); void free_huge_page_vmemmap(struct hstate *h, struct page *head); +void hugetlb_vmemmap_init(struct hstate *h); =20 /* * How many vmemmap pages associated with a HugeTLB page that can be fre= ed * to the buddy allocator. - * - * Todo: Returns zero for now, which means the feature is disabled. We w= ill - * enable it once all the infrastructure is there. */ static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h= ) { - return 0; + return h->nr_free_vmemmap_pages; } #else static inline void alloc_huge_page_vmemmap(struct hstate *h, struct page= *head) @@ -38,5 +36,9 @@ static inline unsigned int free_vmemmap_pages_per_hpage= (struct hstate *h) { return 0; } + +static inline void hugetlb_vmemmap_init(struct hstate *h) +{ +} #endif /* CONFIG_HUGETLB_PAGE_FREE_VMEMMAP */ #endif /* _LINUX_HUGETLB_VMEMMAP_H */ --=20 2.11.0