From patchwork Thu Dec 10 03:55:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11963231 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.5 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,URIBL_BLOCKED,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 48F7EC433FE for ; Thu, 10 Dec 2020 03:57:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DED1623BC6 for ; Thu, 10 Dec 2020 03:57:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DED1623BC6 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 841B36B006C; Wed, 9 Dec 2020 22:57:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F1DD6B006E; Wed, 9 Dec 2020 22:57:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66B616B0070; Wed, 9 Dec 2020 22:57:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id 515A96B006C for ; Wed, 9 Dec 2020 22:57:56 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 16B638249980 for ; Thu, 10 Dec 2020 03:57:56 +0000 (UTC) X-FDA: 77576014152.13.corn91_5c04075273f5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id EBC8B18140B60 for ; Thu, 10 Dec 2020 03:57:55 +0000 (UTC) X-HE-Tag: corn91_5c04075273f5 X-Filterd-Recvd-Size: 5458 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Dec 2020 03:57:55 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id v29so2936745pgk.12 for ; Wed, 09 Dec 2020 19:57: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=/XGFv2MFzigC1jXEGuh+0xsxrvpr1DgA3wrXZ9QAYoM=; b=UM06XiPJqXnNYlPIjuwiT0W1AlWph80UIuK+UAPTeaaBD6XgIYHFSlzuWNT515fqmr k9xRiE585WZptnPdyF/efcDBc5v26PvTmi7zF6JEPLA7KZDEi5fUX8V1PAsJt2cwG4QN xDqkJEdc49ZcSV5xsP50XZF9cBNLJXJAuD0Oqp/yvOd/rD3/dWb2EeC76jEsV0/dD+rU io2TGZx+zIPTjnSZCGRC9Hn/Zd2e+M/nauB6/VdrvwG2R0nMFjXWLfuijL6REIXYS8vg lgWfZw4n3fgyKfwTNsGhlrIBMhTYuEMIMgfytqfzyYHF/Ffq4ImSVxTENbIQpYnzaK0X Y17A== 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=/XGFv2MFzigC1jXEGuh+0xsxrvpr1DgA3wrXZ9QAYoM=; b=odCEODrPs085UN7EJIFlG6vtNVBdSsIslP/NQtse+U+lY0N/twQbZxojvsrkJQXo3r 3CUoOv+LkOLpjTqLJbfy2AOaj7iFpN/N+byNE/y2acnEvolQOF6SPRm4K4OjZSkfa9IV CkygyHso8SlWLP9WSDhKAg28b3v6m6w613bqB4UpCEwVW805mtXFLThiPGXMRV15Hc0z QTh86Y3dRgrlY+cEXLTdkwhhqQ2TS+y6Wrg+HbT6F7kEQ9nyK6L8WBaV22PQbJBGyLP2 SQ/oVwDfjM4AW42spfYrNewdXCtjrDC2hWm40fo0btI4sYlExaNscEPH1EwnYPabxwtk HPhw== X-Gm-Message-State: AOAM531H29qFkEJo+xeR4eeicT8MxBGoef4v3Kj9HQzYtg9nbPCPeo6e jtF4HaptAV1XOyx+FC10XN9ntw== X-Google-Smtp-Source: ABdhPJxwKlxOJeNA9Om/OdTPt9auWCJxB8SXy1Uy9JpRxNcf+KV7zoDGblL5f34prJm4UPuvAUEw9Q== X-Received: by 2002:a63:e207:: with SMTP id q7mr4799499pgh.377.1607572674495; Wed, 09 Dec 2020 19:57:54 -0800 (PST) Received: from localhost.localdomain ([103.136.220.85]) by smtp.gmail.com with ESMTPSA id f33sm4266535pgl.83.2020.12.09.19.57.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 19:57:53 -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 v8 03/12] mm/bootmem_info: Introduce free_bootmem_page helper Date: Thu, 10 Dec 2020 11:55:17 +0800 Message-Id: <20201210035526.38938-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201210035526.38938-1-songmuchun@bytedance.com> References: <20201210035526.38938-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: Any memory allocated via the memblock allocator and not via the buddy will be makred reserved already in the memmap. For those pages, we can call free_bootmem_page() to free it to buddy allocator. Becasue we wan to free some vmemmap pages of the HugeTLB to the buddy allocator, we can use this helper to do that in the later patchs. Signed-off-by: Muchun Song --- include/linux/bootmem_info.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h index 4ed6dee1adc9..20a8b0df0c39 100644 --- a/include/linux/bootmem_info.h +++ b/include/linux/bootmem_info.h @@ -3,6 +3,7 @@ #define __LINUX_BOOTMEM_INFO_H #include +#include /* * Types for free bootmem stored in page->lru.next. These have to be in @@ -22,6 +23,24 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat); void get_page_bootmem(unsigned long info, struct page *page, unsigned long type); void put_page_bootmem(struct page *page); + +/* + * Any memory allocated via the memblock allocator and not via the + * buddy will be makred reserved already in the memmap. For those + * pages, we can call this function to free it to buddy allocator. + */ +static inline void free_bootmem_page(struct page *page) +{ + unsigned long magic = (unsigned long)page->freelist; + + /* bootmem page has reserved flag in the reserve_bootmem_region */ + VM_WARN_ON(!PageReserved(page) || page_ref_count(page) != 2); + + if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) + put_page_bootmem(page); + else + WARN_ON(1); +} #else static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) {