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=unavailable 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 515EBC4741F for ; Thu, 1 Oct 2020 02:58:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B047421D7D for ; Thu, 1 Oct 2020 02:58:17 +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" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B047421D7D 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 506916B0062; Wed, 30 Sep 2020 22:58:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 491526B0068; Wed, 30 Sep 2020 22:58:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A88C8E0001; Wed, 30 Sep 2020 22:58:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 262596B0062 for ; Wed, 30 Sep 2020 22:58:17 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E1E621801739E for ; Thu, 1 Oct 2020 02:58:16 +0000 (UTC) X-FDA: 77321847792.02.women23_14056ce27198 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id BE67F1013FD98 for ; Thu, 1 Oct 2020 02:58:16 +0000 (UTC) X-HE-Tag: women23_14056ce27198 X-Filterd-Recvd-Size: 8236 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 02:58:15 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id 5so2807351pgf.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=QZNd4xQK0U4wNUffcFXMpyCYONh62Fzkn8VcfsZn/nVY8QjAso4onZpAAdacOTomn7 bIo8gO3cWnqsMmrqm7bWVG52Tq/LZeocNUkx31qsOUzBJacSjz87eYoPTn6b/H6sLpr/ nOLPuz8fm+hpruwemYhDzDdKPiGr7l7RzK3FIus2jjegG/m0m8+qktcK4j1rqmL+7i9n CTxeIl5fzFf2UIm3tEh1HgXvrlhDC7P52k37NZuXR3+7DTB9JOKuBlBjITqE423P5WKq 2CrSMaWfKLSICmLC7hXunsWDUJgw7tazyRMJ+S5gaSG9YHs7Qt+9ObbNGv58BPC3WKMX 0FmQ== X-Gm-Message-State: AOAM531gelZf9RiPL0ZwXqTVnGkLmvB5U5fv/EGIofg8Yf1QEXN/neMI F7x4V7rgxMu3KEkj7qAOP+h4yoRrO1rMsKzcB8TJyw== 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" 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: 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