From patchwork Tue May 21 02:39:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668799 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 3F842C25B7B for ; Tue, 21 May 2024 02:40:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D243A6B008C; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD7C66B008A; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CC896B008C; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 53D7A6B0083 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 08C40A24CB for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.04.35011A2 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf29.hostedemail.com (Postfix) with ESMTP id 28AB5120003 for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=tgCjMnuA; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716259213; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A4wbeCsOJjEbvL1QOmk6MW3+h+xr7FchNPjqmD26Xjk=; b=oRqG0fWpQlH1JibdhpGHRz7SnBfo0quCVZDmOPsElm5x8bfMR48E2hb0q5aYKq+t0eH/tN SKB6ZFN+2H3wC9PQnFWr3LXFwhir1o06Brmajr1hmd1vPeabpEkSlrkyZTtJ/tl24vnAZA ZI6dCDhHxdhat5vGCvLv7UeBa4SzimQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=tgCjMnuA; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=YLVVMKuEWeQMQycuUMxtkEzZxY/mhVDANC6uBJmQchMTr98JTY59lYrYXFMGE+GfCP4op3 o2EGU9SdBTPPsV5tj/3fEjGiT1IUAUoEBbV/2ltlzdOAhHBd7NFHayAi1oss3amjvimIfG 8ySF//BQ775IcZWN9AR1Hd3Qxox7g4E= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp0259de57a0ca546ad674c3f88709420f33~RYKiML3rh0469404694epoutp02- for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp0259de57a0ca546ad674c3f88709420f33~RYKiML3rh0469404694epoutp02- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=A4wbeCsOJjEbvL1QOmk6MW3+h+xr7FchNPjqmD26Xjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgCjMnuAZjF6xEE1YpyFfNZ57s0LIuwdl/Bl+kW5QlJTbYw6ISctx9xhqp5e2OUj+ ter/YId6f94yGfXpbBpWPLmu3GYib10KClcw1Xrz5OIMSSCr7ZvBKGcuM/JkAzRBSA LzAd2Oi6Nsxgmno6DkWWZDyvdy3V2UpCdVDcKjZk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p15e3498c3017f00d8fc80ebf9ec9411a9~RYKh2fr7q2309423094epcas1p11; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.36.227]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4VjzDn450Sz4x9Q4; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 4F.B2.10076.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p40d0ea59e8ae93f6cc89846626fea4207~RYKhhxWVN1450914509epcas1p4_; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp168b48ce8e5c6dc6ea18e32ddca44728f~RYKhg98Km2362723627epsmtrp1J; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a39-59dff7000000275c-c7-664c09892610 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 1C.75.08924.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.104.99]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epsmtip2267c0f75b4a24d70569e3cd70009b889~RYKhY20pf1232612326epsmtip2H; Tue, 21 May 2024 02:40:09 +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, jaewon31.kim@gmail.com, Jaewon Kim Subject: [RESEND PATCH 06/10] memblock: recognize late freed size by checking PageReserved Date: Tue, 21 May 2024 11:39:53 +0900 Message-Id: <20240521023957.2587005-7-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240521023957.2587005-1-jaewon31.kim@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkk+LIzCtJLcpLzFFi42LZdlhTT7eT0yfN4OEjeYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzvg16SpLwX+hip7dF9gaGP/wdTFyckgImEi0PlnI2sXIxSEksINRYu+e ZewgCSGBT4wSJ/aYQiS+MUp8urqUCaZjf/cJqI69jBJzV22Acj4zSvy495URpIpNQFvi/YJJ rCC2iICdxLfZB8BsZoFSibdvTjCD2MICMRIXf51hAbFZBFQlurZNA7N5Bewljv/tYYHYJi8x 89J3sJM4BRwk5k9ZzA5RIyhxcuYTFoiZ8hLNW2czgxwhIfCTXeLJ7v/sEM0uEqsXLGeFsIUl Xh3fAhWXknjZ3wZl50tcuPgK6DUOILtGYuFEQ4iwvcSurzNYQcLMApoS63fpQ6zik3j3tYcV oppXoqNNCKJaTaLl2VeoRTISf/89g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3MG4fdUHvUOMTByMhxglOJiVRHg3bfFM E+JNSaysSi3Kjy8qzUktPsQozcGiJM4r/qI3RUggPbEkNTs1tSC1CCbLxMEp1cCUJBd+7EjA 9O6nLC4r3d/xP335y/kWQ8O0vjkxhydJvbsYxsPjXBgnuXL1Q2H2KzllXc/rZdmaL8rUrRM7 57fk+x2xnVeeVl+vY5u445SApNisuXL7pf/lNJp1XzXuZdmYk/pBqMtcc9G2pmkHL99Y72Me 9WB15aelnkVL0h/fP7O0QFR7auWsvNvP82YtXZN2fsfqtJXFZU8rDV5d+u0a/PBGhajUL9MJ KuzPKzuv8sXvasnMV/rZpMRyVSRCe8nGNZycNp5Pv6Q7x96YMenC+VX/VztN2BGsZfBief2n Fb2Kq3PqE433yylnb0wwUeJxDoi51nWQq+4jw51TE8KE5Rlkpq1Jnd8+1W320igOJZbijERD Leai4kQAy/7GsOICAAA= X-CMS-MailID: 20240521024009epcas1p40d0ea59e8ae93f6cc89846626fea4207 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p40d0ea59e8ae93f6cc89846626fea4207 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 28AB5120003 X-Stat-Signature: urdz4m4myoji6ng1ms37tsychx51o867 X-HE-Tag: 1716259212-411566 X-HE-Meta: U2FsdGVkX19+183wVhRLtcUOajW+9ZUGFaeWRf/36Vu5lxfucC8h5Va6jz/7LqNl1l86xsE5EFqGIg0x9Qt7hVbbXYZh96uRwASlCvtcCPwvGcg5WKdSzZJwgVqo2Eii0mkYu0o113L57tJ3AkU0UnK2bOn66w8wSW7RLEX/XiTe/sK/z3NWnmheyuzf2p5MFUNJQKbgopKJpAW2rYqhaBtNukcnRlJrAdM+lYS/69SDwxFa/asXmWoQeGF6vTntb2rrX2spkylSUTsqtQhKcc/B7h/ecV0+OO2ZzYDexLpkjHfY+McDgU3EaXXJYjtUocCdz4NL+gbq/vfBt6oZ1LxEU87KZDxwezCrsj0a8rPJdCsQ3734ijbkgeOGPJs8AkIupqHaxgs5CiGcbKnYq0SaABHgsBo7Kv50q+OKsa34v1J1un0TYVR7LMLMyqKE0XEGDksHnaAiGEcLhlYFqxtfBuQu8GZxjePf6GHD3nIL0baEZ0Hqf/+9iG4WbhrOfo4GEKjvmgj7GxgL4yccimn2aWwuRzcLZExzGJHzyzTYapx5F2NPPLbVIdR7EJIB2KwTcMvWLdT1vuF4bS70gWbp1KsGw8LKhFIiAlMa/99gDPsU45OqCqRzdE8/XumYLWzsbNAP4K/pROD8q2UwJRn5BGVxysSdMG78zk72OsR3nnKQuRvqPnMb6GvC7og+3GqHk9clQUitpvnMqIpNCJFyaxBZPDCVuD5cZH3nnXFRdV1n77nVGiqfHK+5FpVmUkUthkXyR1m3MdT6UALzla8Vix0dNpVDTYI/tdQagMcsf5IvTSWLTxpeeOg0jZt3oss2lbd1mUN3lj9Cc7Y4MsAMyOxr8r+eXes8qXN2LGAdorID2IbnDApHbzRLB6+y/WlPaIdmER1cQ1iY8t6xNa9Kz2VtsRe5xNegPT2bmQPf4N+5bgRsU8S7oDMG276k8WBbkyZHOrpEWjK/j6Z tupXapKA JNGml013fm92DtZRxa0wa50CgUczjfJm1whrMYjaiq8X5ajbfnMWv3NJvgWEndpANNQznwrv6pjEm5l/KmlNgPGx6umpnvLjvCaGPa386IBDt3Zlz5gH3wE9tqYmIDOqPJiD2pZbCP7u55Y/AqqLpsgkVRV8TVdX1YNhH 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: List-Subscribe: List-Unsubscribe: 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 64 KB 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 edb2575967ab..de49e7ce74f1 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2608,6 +2608,39 @@ static int memsize_rgn_cmp(const void *a, const void *b) return 0; } +/* assume that freed size is always 64 KB 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_64K >= end)) + memblock_memsize_free(freed, end - freed); + phy += SZ_64K; + } +} + static int memblock_memsize_show(struct seq_file *m, void *private) { int i; @@ -2621,6 +2654,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;