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=-10.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 432CDC4363D for ; Thu, 1 Oct 2020 02:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E696121D7D for ; Thu, 1 Oct 2020 02:58:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="zgOeDmpJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730357AbgJAC6P (ORCPT ); Wed, 30 Sep 2020 22:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJAC6P (ORCPT ); Wed, 30 Sep 2020 22:58:15 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32594C061755 for ; Wed, 30 Sep 2020 19:58:15 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id l126so3049601pfd.5 for ; Wed, 30 Sep 2020 19:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mwzDXzGzheFaLtfSgxu27esE2z5Zeui3HFQefTnFb8g=; b=zgOeDmpJuU6J+m/pXdHtw3CZdp3/+XRjOtE4QzOo5btYMi5CLEyMdYXP4kSuNLz0eJ TFwUKsIYwfUQUmtI+2qMLoVZYgC7w7vkFssPY0ClvBK10qm7/mmR+KOvvl74hI+k/bB/ 1Fn6MN/yuQdtO3KDGy+7pAlMNut7JupiZLTCM25c9gbmkHd3h5qXV1x4slS9nd7QdC72 Dse4DbSqwOSlALxNQ+/L/J27u5yzgeCl4uE/08Z0Z8ByPYub7ETutOqST4m2+qsy60+j uD8cO44bxV1JAX4MTkAqxwFpazo/MUwoaL01/QQ/iBZy7NVW7x5qhZin16ywUexEwRsu CdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mwzDXzGzheFaLtfSgxu27esE2z5Zeui3HFQefTnFb8g=; b=lKaD73Ngq4LI4CdYeMuWnexl36ENIyij/FcJbhR5zpuf/buDMuaiCreEnDgrzAI/26 NeSBLdb52Dk72dqtm4vp6YthwWt7J8S1TBhsR4SBE80i+MeSEOMhqkcdPlr8hJ84qvpL uhIEMAeiTGbI+5Lz2ykXkR3YijuAjSHz41KkzsDUSVhHKiL1d4bBy0xEE9jSnktpE1H3 odl/8nQ2/hrjZe9Nvrgs06hKr0MXxMDYXMM6RoauKe3p3QqpTr5/E9bWUvpBdNzdW7D6 lDQrgkPLEOYnoibACjq1rmVatnXKp8ntNMqTOLbKA+3WXsOaUBMIkpw3tsHQ7aAetoBi gSIg== X-Gm-Message-State: AOAM530BESuIYRgbWOp9cNQp7cVXEK3PCd8MBrIAyMOr5nTj1mJZ1y7Z 2izbWZbpHo6LLZs/gOPcIa41SZX2P5q2bXnSlPEv/Q== X-Google-Smtp-Source: ABdhPJw54fMhnUTblVABuAoszldUwSDkq8h8waLyxfnj4UMJiylKdptjrq1mXx8p4IpIh0PDd6kd4W1ynwcS/DGmTZU= X-Received: by 2002:aa7:8287:0:b029:142:2501:39ec with SMTP id s7-20020aa782870000b0290142250139ecmr4965310pfm.59.1601521094544; Wed, 30 Sep 2020 19:58:14 -0700 (PDT) MIME-Version: 1.0 References: <20200915125947.26204-1-songmuchun@bytedance.com> <20200915125947.26204-6-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Thu, 1 Oct 2020 10:57:38 +0800 Message-ID: Subject: Re: [External] Re: [RFC PATCH 05/24] mm/hugetlb: Introduce nr_free_vmemmap_pages in the struct hstate To: Mike Kravetz Cc: Jonathan Corbet , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 1, 2020 at 6:41 AM Mike Kravetz wrote: > > On 9/15/20 5:59 AM, Muchun Song wrote: > > If the size of hugetlb page is 2MB, we need 512 struct page structures > > (8 pages) to be associated with it. As far as I know, we only use the > > first 3 struct page structures and only read the compound_dtor members > > Actually, the first 4 pages can be used if CONFIG_CGROUP_HUGETLB. Right, thanks. > /* > * Minimum page order trackable by hugetlb cgroup. > * At least 4 pages are necessary for all the tracking information. > * The second tail page (hpage[2]) is the fault usage cgroup. > * The third tail page (hpage[3]) is the reservation usage cgroup. > */ > #define HUGETLB_CGROUP_MIN_ORDER 2 > > However, this still easily fits within the first page of struct page > structures. > > > of the remaining struct page structures. For tail page, the value of > > compound_dtor is the same. So we can reuse first tail page. We map the > > virtual addresses of the remaining 6 tail pages to the first tail page, > > and then free these 6 pages. Therefore, we need to reserve at least 2 > > pages as vmemmap areas. > > I got confused the first time I read the above sentences. Perhaps it > should be more explicit with something like: > > For tail pages, the value of compound_dtor is the same. So we can reuse > first page of tail page structs. We map the virtual addresses of the > remaining 6 pages of tail page structs to the first tail page struct, > and then free these 6 pages. Therefore, we need to reserve at least 2 > pages as vmemmap areas. Sorry for my poor English. Thanks for your suggestions. I can apply this. > > It still does not sound great, but hopefully avoids some confusion. > -- > Mike Kravetz > > > So we introduce a new 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 system. > > > > Signed-off-by: Muchun Song > > --- > > include/linux/hugetlb.h | 3 +++ > > mm/hugetlb.c | 35 +++++++++++++++++++++++++++++++++++ > > 2 files changed, 38 insertions(+) > > > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > > index d5cc5f802dd4..eed3dd3bd626 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 81a41aa080a5..f1b2b733b49b 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -1292,6 +1292,39 @@ static inline void destroy_compound_gigantic_page(struct page *page, > > unsigned int order) { } > > #endif > > > > +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP > > +#define RESERVE_VMEMMAP_NR 2U > > + > > +static inline unsigned int nr_free_vmemmap(struct hstate *h) > > +{ > > + return h->nr_free_vmemmap_pages; > > +} > > + > > +static void __init hugetlb_vmemmap_init(struct hstate *h) > > +{ > > + unsigned int order = huge_page_order(h); > > + unsigned int vmemmap_pages; > > + > > + vmemmap_pages = ((1 << order) * sizeof(struct page)) >> PAGE_SHIFT; > > + /* > > + * The head page and the first tail page not free to buddy system, > > + * the others page will map to the first tail page. So there are > > + * (@vmemmap_pages - RESERVE_VMEMMAP_NR) pages can be freed. > > + */ > > + if (vmemmap_pages > RESERVE_VMEMMAP_NR) > > + h->nr_free_vmemmap_pages = vmemmap_pages - RESERVE_VMEMMAP_NR; > > + else > > + h->nr_free_vmemmap_pages = 0; > > + > > + pr_info("HugeTLB: can free %d vmemmap pages for %s\n", > > + h->nr_free_vmemmap_pages, h->name); > > +} > > +#else > > +static inline void hugetlb_vmemmap_init(struct hstate *h) > > +{ > > +} > > +#endif > > + > > static void update_and_free_page(struct hstate *h, struct page *page) > > { > > int i; > > @@ -3285,6 +3318,8 @@ void __init hugetlb_add_hstate(unsigned int order) > > snprintf(h->name, HSTATE_NAME_LEN, "hugepages-%lukB", > > huge_page_size(h)/1024); > > > > + hugetlb_vmemmap_init(h); > > + > > parsed_hstate = h; > > } > > > > -- Yours, Muchun