From patchwork Sun Nov 8 14:10:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11889597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC2EA139F for ; Sun, 8 Nov 2020 14:12:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7C7721D40 for ; Sun, 8 Nov 2020 14:12:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="tot+BcAr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7C7721D40 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 D45B66B006E; Sun, 8 Nov 2020 09:12:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF4B26B0070; Sun, 8 Nov 2020 09:12:23 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBBE86B0071; Sun, 8 Nov 2020 09:12:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 8A1076B006E for ; Sun, 8 Nov 2020 09:12:23 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 356D5180AD802 for ; Sun, 8 Nov 2020 14:12:23 +0000 (UTC) X-FDA: 77461440966.09.whip69_18008d9272e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 1DE24180AD801 for ; Sun, 8 Nov 2020 14:12:23 +0000 (UTC) X-Spam-Summary: 1,0,0,21b63635982f5c72,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4118:4321:4385:4390:4395:4605:5007:6261:6653:6737:6738:7875:8603:9036:10004:11026:11473:11658:11914:12043:12048:12114:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13138:13231:13255:13894:14181:14394:14721:21080:21094:21323:21444:21451:21627:21987:21990:30029:30054:30064,0,RBL:209.85.210.193:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yfz7ubi9i4ybtxkh3rxqrfpzkbxycpfb7qdmsm8dx4csqs9h3n6opfc9nj4ch.6p9o9biqjz4bszqde19zz59y16hw844g7nzzmm9574in38qb7p7osjm8jmxf3zg.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:68,LUA_S UMMARY:n X-HE-Tag: whip69_18008d9272e4 X-Filterd-Recvd-Size: 7084 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Sun, 8 Nov 2020 14:12:22 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id q10so5534294pfn.0 for ; Sun, 08 Nov 2020 06:12:22 -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=5TzMLMYXz/tt2Duq9f+ytVwz3M0d3tJpioRexK8gCnY=; b=tot+BcArmsCT+Ujl2UrzCeAIugUfEiKhiHWRy395c/4yXQteyeyWe97yiLCpAccecK TXztPy/aljEbw+NZyD5a95ZhoRolPuBuHQyoCpR2bVqNmGNJGXOdAUb40MIrCg2PBiAA 6WoW9LJDfCfRS3xcGx7fdWVbQvKE1LxfnGb3Ret1ynvISN8iAMNXO1Vu8BPJE1HUmyd0 q+4E8kQ9WJsy1s1AZkdvogEUarTd/xDtVHAu5lk6HzZClsQqDqiJ035r2caXlcA2OSS4 wXu80VKjCTmIwYbjkWOo3kIK2fPSLXZ8rGkAvgP7933OvGQ/KskCDzP0Ini5ZtHtgtKB TO7w== 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=5TzMLMYXz/tt2Duq9f+ytVwz3M0d3tJpioRexK8gCnY=; b=V8Qjtz96tsoBjBx2rznW44TsxIeoG6RWOk7grY60HxD782nIjdAMwJ7y/L8NfffpCn tnvn28Zo7XFLPf6YMNO6aGKeGYGGO8mjC4RuiHaEVBnfZOmkj89qaR773NdKmxCtZt1/ 9nQcAkYsI2dynX+eD984o3svd+emczvmPkR9pcuMfn+jvWA/qk9TD5XiVs6FFgsH745A rp5FmZMtpoWZQ95H3+nTWKLYuSSovP3SW6kZs1p0/GRYPwhhG3jo2fkaJZIiw74FnpC9 txVJJscdCq7iwcqXqG3SkQj+vYKqZx/pXQ5kS3KHIrhcB97vTwyZrZIyREuBwJZLOT1s lrcg== X-Gm-Message-State: AOAM532KRnEbxrrEO+Hh/8ziGAnQY6lfClkEZeLTRDZb7QM33+IbgG4c qrBg+x77go1GFL5F1ZZZb4SGgQ== X-Google-Smtp-Source: ABdhPJwlFJQvzR9hK35z2RWma7Iesgmp9PzPHb9J6pbPZFxIZR8tlFKidvzMRT4M6nvoWJhgVyoekA== X-Received: by 2002:aa7:83c2:0:b029:156:5ece:98b6 with SMTP id j2-20020aa783c20000b02901565ece98b6mr10070588pfn.4.1604844741468; Sun, 08 Nov 2020 06:12:21 -0800 (PST) Received: from localhost.localdomain ([103.136.220.94]) by smtp.gmail.com with ESMTPSA id z11sm8754047pfk.52.2020.11.08.06.12.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2020 06:12:20 -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 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 v3 04/21] mm/hugetlb: Introduce nr_free_vmemmap_pages in the struct hstate Date: Sun, 8 Nov 2020 22:10:56 +0800 Message-Id: <20201108141113.65450-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201108141113.65450-1-songmuchun@bytedance.com> References: <20201108141113.65450-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: 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 4 struct page structures. Use of first 4 struct page structures comes from HUGETLB_CGROUP_MIN_ORDER. For tail pages, the value of compound_head 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. 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 Acked-by: Mike Kravetz --- include/linux/hugetlb.h | 3 +++ mm/hugetlb.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 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..a0007902fafb 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1292,6 +1292,42 @@ static inline void destroy_compound_gigantic_page(struct page *page, unsigned int order) { } #endif +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP +/* + * There are 512 struct page structs(8 pages) associated with each 2MB + * hugetlb page. 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. + */ +#define RESERVE_VMEMMAP_NR 2U + +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 (likely(vmemmap_pages > RESERVE_VMEMMAP_NR)) + h->nr_free_vmemmap_pages = vmemmap_pages - RESERVE_VMEMMAP_NR; + else + h->nr_free_vmemmap_pages = 0; + + pr_debug("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 +3321,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; }