From patchwork Thu Mar 24 07:01:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA1A5C433EF for ; Thu, 24 Mar 2022 06:59:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B51F6B0082; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63BA68D0001; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32FA46B0085; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id E19CE6B0082 for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BBCF120E51 for ; Thu, 24 Mar 2022 06:59:26 +0000 (UTC) X-FDA: 79278378732.10.4CACCE7 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf11.hostedemail.com (Postfix) with ESMTP id D9F7740005 for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220324065923epoutp03bf8c3fa1b02660bf84b31fa539c00a55~fPuoS2xqf2260822608epoutp03H for ; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220324065923epoutp03bf8c3fa1b02660bf84b31fa539c00a55~fPuoS2xqf2260822608epoutp03H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105163; bh=RidzKqNjs5HOBkuuO6v6/5UvbzPkwAJOqwZxf+Nkf5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RLNsDx2RF6HSMQUXxTcrxoLsEUm7JYz44Q2WLX2wI+p+9InegBRNQ955YyCd3s0fh e8OerodeQx9FOPVKDn1jkXz+1C5oAU8Xc7ktIBz5b2nUk5YazIP9eGXk3bNxndfjyN HERqVYT8j+MS21z+CwLZTkwRv6u3iee+ywWKi6O4= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220324065923epcas1p410186b7151a7c4ad59fee32272e82fe8~fPun-IGKB2463324633epcas1p4S; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.247]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4KPGL23R0fz4x9Q8; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 53.0A.64085.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p1058e2841b009d8c7d683bc0408f8a5a4~fPukbUYx22488924889epcas1p1G; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp19ec153dd781008488dd7015f92b513f7~fPukafMFB2225222252epsmtrp1V; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a35-9adff7000000fa55-0d-623c16c7a91b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 28.AD.03370.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.100.104]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epsmtip2bdc91d1127b721c804555b0fc29dcfcf~fPukSrsVT3063230632epsmtip29; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) From: Jaewon Kim To: rppt@kernel.org, vbabka@suse.cz, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ytk.lee@samsung.com, jaewon31.kim@gmail.com, Jaewon Kim Subject: [PATCH 6/8] memblock: recognize late free by checking PageReserved Date: Thu, 24 Mar 2022 16:01:56 +0900 Message-Id: <20220324070158.22969-7-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOKsWRmVeSWpSXmKPExsWy7bCmnu5xMZskg78nzCzmrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKzAr3ixNzi 0rx0vbzUEitDAwMjU6DChOyMjs9bWAp+ClUcvdPO2sD4na+LkZNDQsBE4v3Mm6xdjFwcQgI7 GCVWnX7CCpIQEvjEKHFjMQ9E4jOjxNtHU9lhOrYunsICkdjFKLFsej87hPODUWLH9XYmkCo2 AW2J9wsmgY0SEbCT+Db7ANgOZoEuRokHHw4CtXNwCAt4S7x4bAJSwyKgKrFszSKwDbwCthJr l+5mgtgmL7F6wwFmEJsTaM7KJQcYQ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VYtmYRO4jNK2ArsXbpbiaI XfISqzccAJvJKWAnsXLJAUYQWwio5uzJA2wTGPkWMDKsYpRMLSjOTc8tNiwwykst1ytOzC0u zUvXS87P3cQIDkgtrR2Me1Z90DvEyMTBeIhRgoNZSYT3/mXrJCHelMTKqtSi/Pii0pzU4kOM 0hwsSuK8F7pOxgsJpCeWpGanphakFsFkmTg4pRqYdnl/VAs0e8t5Ruvz/nlHT9zk2v9cdUXI lkMTZFJDghbf++zHLxu/yDC2WLQ10L+YY4rQ2X+TOo8fLT24eXnaq29WrXsnnPnTtkxMpyz3 Uesv7n2LrkabuTsWzMzf4CEWJG3vVp2bPIU966lnxCLt4K79i4+dnhby+3SluUpiamJkyi7V tYrMCpM+6czq2NqzWDfl77qbTqf2c3b/X/nG9DP3/YXhbitjxCsMRENnOxb7Hm9I1f6oF9XH HXh+5uTg/b4tto/tCsWcihKc0tbuN/jLzWS0xkJj63wOi8KvYTODtmxy+vlxvtvbL9c/Nh1c ssQmxLqsI1ztdlDy2pUBk29odK89dq1b6nLQBaZZSizFGYmGWsxFxYkATpK1hLcCAAA= X-CMS-MailID: 20220324065919epcas1p1058e2841b009d8c7d683bc0408f8a5a4 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p1058e2841b009d8c7d683bc0408f8a5a4 References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D9F7740005 X-Stat-Signature: qncaobf5wjuyhquc8jnga5qbes47hmih X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=RLNsDx2R; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf11.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com X-HE-Tag: 1648105165-886757 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: There are some cases in which reserved pages are freed late after the initial memblock_free_all of mem_init. We'd like to recognize this late free pages, and update the memsize information. Because additional job is needed to a no-map or reusable region, the late free is usually done to a map and unusable region. So only for map and unusable region, check if some pages within the region is freed. The freed pages can be recoginzed by checking if PageReserved flag is clear. To be fast, let's skip other pages within 1 MB range. And this check is done when a user wants to see the memsize information. This is an example. If all pages are freed the region size will be 0. Before 0x0a2300000-0x0a2400000 0x00100000 ( 1024 KB ) map unusable latefree After 0x0a2300000-0x0a2300000 0x00000000 ( 0 KB ) map unusable latefree Signed-off-by: Jaewon Kim --- mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mm/memblock.c b/mm/memblock.c index aee22dbc2500..597ec7fb5bb2 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2455,6 +2455,39 @@ static int memsize_rgn_cmp(const void *a, const void *b) return 0; } +/* assume that freed size is always MB aligned */ +static inline void memblock_memsize_check_size(struct memsize_rgn_struct *rgn) +{ + phys_addr_t phy, end, freed = 0; + bool has_freed = false; + struct page *page; + + if (rgn->reusable || rgn->nomap) + return; + + /* check the first page of each 1 MB */ + phy = rgn->base; + end = rgn->base + rgn->size; + while (phy < end) { + unsigned long pfn = __phys_to_pfn(phy); + + if (!pfn_valid(pfn)) + return; + page = pfn_to_page(pfn); + if (!has_freed && !PageReserved(page)) { + has_freed = true; + freed = phy; + } else if (has_freed && PageReserved(page)) { + has_freed = false; + memblock_memsize_free(freed, phy - freed); + } + + if (has_freed && (phy + SZ_1M >= end)) + memblock_memsize_free(freed, end - freed); + phy += SZ_1M; + } +} + static int memblock_memsize_show(struct seq_file *m, void *private) { int i; @@ -2468,6 +2501,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private) long size; rgn = &memsize_rgn[i]; + memblock_memsize_check_size(rgn); base = rgn->base; size = rgn->size; end = base + size;