From patchwork Mon Nov 30 15:18:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11940791 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,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 89BF7C64E7B for ; Mon, 30 Nov 2020 15:20:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C4F920725 for ; Mon, 30 Nov 2020 15:20:14 +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="ZjgH0vr+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C4F920725 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 6867F8D000B; Mon, 30 Nov 2020 10:20:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 639A38D0002; Mon, 30 Nov 2020 10:20:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 502058D000B; Mon, 30 Nov 2020 10:20:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 331458D0002 for ; Mon, 30 Nov 2020 10:20:14 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EC318824999B for ; Mon, 30 Nov 2020 15:20:13 +0000 (UTC) X-FDA: 77541445506.06.voice02_2c05842273a2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id BFAF110047DE5 for ; Mon, 30 Nov 2020 15:20:13 +0000 (UTC) X-HE-Tag: voice02_2c05842273a2 X-Filterd-Recvd-Size: 5376 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Mon, 30 Nov 2020 15:20:13 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id o4so7990444pgj.0 for ; Mon, 30 Nov 2020 07:20:13 -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=9VN22FTK/cp8gibu50+JlwycxClP9nhjODvnGGV4tug=; b=ZjgH0vr+7SnQsHcGa2K/AiAuo7pJtkSwgWtJ++8mJ2N5dpvx4/q685PNvhcPi2L4RH zFqwO9fa0PZR53uIZxgbwWomp0bb+gwW+M0LnTiAdcqN2Q4Tt2XVUs+9Dk0QZFvzzoiF 9g4nQSo6Jyu0zrA7kF1DrDaVrzm3y6zUMZ7QVrtPujRAD+1WRi9xBGRW1rC+CFtvp2WJ sWszVSoUAnOMDq/t6yIZ/EewSR2lsiYjvv/3iPi30y9MJU19LbuhfIcXTphhMiKAqrg2 D9DlSAWK4DROV+/PKZvKzx1pF3xpR1IgUoEmV05vYOLbTqAhByvCExHRdsEN2B9Jygsh 7Hsg== 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=9VN22FTK/cp8gibu50+JlwycxClP9nhjODvnGGV4tug=; b=Cx8vB7F9S91foPcKozl+P4ByO4fhBXmUGG/VPInBjzqW1ibL/MQlRRGaMjaKHwfAhS RGFHk5rRME/h1QAIVbGYD2SbxOeHotVtfcxMX2iYYDuymnP3YRw/xY42mwcmB/Uzf0BH 5gs1sqnuGLRt3971VdzmWxiJO/YWE3vmQjpJSa6m/uOSopXH2DyEestIRThAIopVM3EF BlvmlHi7C4MRIwGSacCp7BcIreO2KLZ4/oAy6zxrtTvwGRkXr0hjoBleXjhm2TP27kFD D+G+9Tc9DbZeQcFBf8ovOYNdCytXBmQE17vwWLRtVkzA1W5ysOboMB3HtqZ0jB1THgk0 ATRg== X-Gm-Message-State: AOAM531padtwYTRIYI1kmFX2/zjA3p/KdkTFpYHzzQJntxES4LeRqnd8 d42kiA/3zztyq5/itU4NSL+pxQ== X-Google-Smtp-Source: ABdhPJyhD8o0jzVpPs+toSeNAsFByTmDI0pdIsUlVpAmaWm//ETZis2DFWTt1ieO0wvLlKMNFBzcgA== X-Received: by 2002:a05:6a00:13a4:b029:18b:cfc9:1ea1 with SMTP id t36-20020a056a0013a4b029018bcfc91ea1mr19086071pfg.25.1606749612267; Mon, 30 Nov 2020 07:20:12 -0800 (PST) Received: from localhost.bytedance.net ([103.136.221.68]) by smtp.gmail.com with ESMTPSA id q12sm16201660pgv.91.2020.11.30.07.20.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Nov 2020 07:20:11 -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 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 v7 05/15] mm/bootmem_info: Introduce {free,prepare}_vmemmap_page() Date: Mon, 30 Nov 2020 23:18:28 +0800 Message-Id: <20201130151838.11208-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201130151838.11208-1-songmuchun@bytedance.com> References: <20201130151838.11208-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: In the later patch, we can use the free_vmemmap_page() to free the unused vmemmap pages and initialize a page for vmemmap page using via prepare_vmemmap_page(). Signed-off-by: Muchun Song --- include/linux/bootmem_info.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h index 4ed6dee1adc9..239e3cc8f86c 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,29 @@ 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); + +static inline void free_vmemmap_page(struct page *page) +{ + VM_WARN_ON(!PageReserved(page) || page_ref_count(page) != 2); + + /* bootmem page has reserved flag in the reserve_bootmem_region */ + if (PageReserved(page)) { + unsigned long magic = (unsigned long)page->freelist; + + if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) + put_page_bootmem(page); + else + WARN_ON(1); + } +} + +static inline void prepare_vmemmap_page(struct page *page) +{ + unsigned long section_nr = pfn_to_section_nr(page_to_pfn(page)); + + get_page_bootmem(section_nr, page, SECTION_INFO); + mark_page_reserved(page); +} #else static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) {