From patchwork Thu Mar 24 07:01:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790445 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 B61A9C433F5 for ; Thu, 24 Mar 2022 06:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66EFB6B0080; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59EA06B0082; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F8186B0081; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id F2DE86B0078 for ; Thu, 24 Mar 2022 02:59:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AC2768248D52 for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) X-FDA: 79278378690.29.0461879 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf30.hostedemail.com (Postfix) with ESMTP id BACCB80020 for ; Thu, 24 Mar 2022 06:59:24 +0000 (UTC) Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220324065921epoutp02e259191e7c59df315162e36d40baf80d~fPumYNjh-1428414284epoutp02c for ; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220324065921epoutp02e259191e7c59df315162e36d40baf80d~fPumYNjh-1428414284epoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105161; bh=i1obRaKln+JV61/ToEUs1DW8bLXWehO+ng6Tc5bG6zY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzdlgRHlaOzAYWMzIJb3U7mRDZz934P/diMTh0e+zsTieV1w7RkuzAvIrJBtCXd8K ioTA09KlrJFwPl/OxfokJ2PSnLj3HNppu9UA+yotTiRAfKq9aT4mLuqeL8RTPpEEqa lSk+kZQfdAH/0K0XhydL7z4B+yIkJG27xduPyEas= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20220324065921epcas1p120c094af8495d5028a21a4ffe0b787ba~fPumClA0W2490124901epcas1p1G; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.36.225]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4KPGKz6Z2bz4x9Qd; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id 73.5E.21932.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88~fPukU-vay0539605396epcas1p3f; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp251e68bae4cabf8123ba8522925b42157~fPukUQ-yk2562225622epsmtrp2a; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a38-93fff700000255ac-07-623c16c7f41b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 0F.E5.29871.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 20220324065919epsmtip26222ae87a5e323ea9be0c16449612469~fPukGV93K3063230632epsmtip28; 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 1/8] memblock: introduce memsize showing reserved memory Date: Thu, 24 Mar 2022 16:01:51 +0900 Message-Id: <20220324070158.22969-2-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+NgFnrJKsWRmVeSWpSXmKPExsWy7bCmru5xMZskg7eLdCzmrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKzAr3ixNzi 0rx0vbzUEitDAwMjU6DChOyMm2tvMBXccqxomb+FtYHxkUkXIyeHhICJxJWlU5m7GLk4hAR2 MEr0LPrFBuF8YpSYtfgbVOYbo8S1V2dYYVqWzLzHApHYyyixd/lWVgjnB6PEizdfmUGq2AS0 Jd4vmATWISJgJ/Ft9gGwImaBLkaJBx8OsoAkhAU8JDYtm8YIYrMIqErMbZnJBGLzCthKTPt/ lQ1inbzE6g0HwIZyAg1aueQAI0T8EbvEkSZHCNtF4ui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2yUus3nCAGcTmFLCTWLnkACPEMluJsycPsE1g5FvAyLCKUTK1oDg3PbfYsMAwL7Vcrzgx t7g0L10vOT93EyM4ILU0dzBuX/VB7xAjEwfjIUYJDmYlEd77l62ThHhTEiurUovy44tKc1KL DzFKc7AoifNe6DoZLySQnliSmp2aWpBaBJNl4uCUamBqF9fzr/RwjpXxjGixfxYh/NFW2O+j +JdtDj3Bi20E77xTUVfenrRkyWHX07MZZzH+Dz7mJfnE/tzhBUeCSlm2lu6u2nzvUt+CyLKb J8Kj619HfzwY3v1Bo5tjmqyR+1d25k2LCo7/+hI0+W+G8L8tIv8TvhvMZTjEkT3JsMxz5o+v NtvbmB36lby2MxxxYXyT0Rm5+/d7zYPB/+drX2SZUdt3KDdkmzib/Vp7v7fnPvc9dKpRkfqw MXN1jfAO/pTwwGv2bAvjdVd3LHfmXsy7KC7bvtxB79+xGTz/Kzmf1Hz8Jldvv26i95bEqzyB q8I4w57tr5l6ubTIp+V0l13wlbsfBVgYb5peEbW41K7EUpyRaKjFXFScCACmpwo/twIAAA== X-CMS-MailID: 20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88 References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Stat-Signature: ssg6bkjegg5dkhb63xtkch9xsqmaaqnr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BACCB80020 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=dzdlgRHl; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf30.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com X-Rspam-User: X-HE-Tag: 1648105164-259750 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: Some of memory regions can be reserved for a specific purpose. They are usually defined through reserved-memory in device tree. If only size without address is specified in device tree, the address of the region will be determined at boot time. We may find the address of the memory regions through booting log, but it does not show all. And it could be hard to catch the very beginning log. The memblock_dump_all shows all memblock status but it does not show region name and its information is difficult to summarize. This patch introduce a debugfs node, memblock/memsize, to see reserved memory easily. The first patch here will show the only reserved-memory in device tree like following example. The next patches will show more information. $ cat debugfs/memblock/memsize 0x0f9000000-0x0fb000000 0x02000000 ( 32768 KB ) map reusable linux,cma 0x0b1900000-0x0b1b00000 0x00200000 ( 2048 KB ) nomap unusable test1 0x0b0200000-0x0b0400000 0x00200000 ( 2048 KB ) map unusable test2 .unusable : 4096 KB .reusable : 32768 KB Signed-off-by: Jaewon Kim --- drivers/of/fdt.c | 2 + drivers/of/of_reserved_mem.c | 7 ++- include/linux/memblock.h | 9 +++ kernel/dma/contiguous.c | 2 + mm/Kconfig | 7 +++ mm/memblock.c | 103 +++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ec315b060cd5..ec2f60a78f8f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -619,6 +619,7 @@ static void __init fdt_reserve_elfcorehdr(void) } memblock_reserve(elfcorehdr_addr, elfcorehdr_size); + memblock_memsize_record("elfcorehdr", elfcorehdr_addr, size, false, false); pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n", elfcorehdr_size >> 10, elfcorehdr_addr); @@ -645,6 +646,7 @@ void __init early_init_fdt_scan_reserved_mem(void) if (!size) break; early_init_dt_reserve_memory_arch(base, size, false); + memblock_memsize_record("memreserve", base, size, false, false); } fdt_scan_reserved_mem(); diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 75caa6f5d36f..40323751efb2 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -261,9 +261,10 @@ void __init fdt_init_reserved_mem(void) int len; const __be32 *prop; int err = 0; - bool nomap; + bool nomap, reusable; nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; + reusable = of_get_flat_dt_prop(node, "reusable", NULL) != NULL; prop = of_get_flat_dt_prop(node, "phandle", &len); if (!prop) prop = of_get_flat_dt_prop(node, "linux,phandle", &len); @@ -283,6 +284,10 @@ void __init fdt_init_reserved_mem(void) else memblock_phys_free(rmem->base, rmem->size); + } else { + memblock_memsize_record(rmem->name, rmem->base, + rmem->size, nomap, + reusable); } } } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..468b016e179b 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -604,5 +604,14 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) } #endif +#ifdef CONFIG_MEMBLOCK_MEMSIZE +extern void memblock_memsize_record(const char *name, phys_addr_t base, + phys_addr_t size, bool nomap, + bool reusable); +#else +static inline void memblock_memsize_record(const char *name, phys_addr_t base, + phys_addr_t size, bool nomap, + bool reusable) { } +#endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 6ea80ae42622..7415c1135afa 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -239,6 +239,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, dma_contiguous_early_fixup(cma_get_base(*res_cma), cma_get_size(*res_cma)); + memblock_memsize_record("dma_cma", cma_get_base(*res_cma), + cma_get_size(*res_cma), false, true); return 0; } diff --git a/mm/Kconfig b/mm/Kconfig index 761f5021ba51..e29f6cd8394e 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -96,6 +96,13 @@ config HAVE_FAST_GUP depends on MMU bool +config MEMBLOCK_MEMSIZE + bool "memblock based reserved memory profiling" + default n + help + This patch introduce a debugfs node, memblock/memsize, to see reserved + memory easily. + # Don't discard allocated memory used to track "memory" and "reserved" memblocks # after early boot, so it can still be used to test for validity of memory. # Also, memblocks are updated with memory hot(un)plug. diff --git a/mm/memblock.c b/mm/memblock.c index b12a364f2766..8492757f7192 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -19,6 +19,7 @@ #include #include +#include #include "internal.h" @@ -1928,6 +1929,49 @@ static int __init early_memblock(char *p) } early_param("memblock", early_memblock); +#ifdef CONFIG_MEMBLOCK_MEMSIZE + +#define NAME_SIZE 30 +struct memsize_rgn_struct { + phys_addr_t base; + long size; + bool nomap; /* 1/32 byte */ + bool reusable; /* 1/32 byte */ + char name[NAME_SIZE]; /* 30/32 byte */ +}; + +#define MAX_MEMSIZE_RGN 64 +static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock; +static int memsize_rgn_count __initdata_memblock; + +void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, + phys_addr_t size, bool nomap, bool reusable) +{ + struct memsize_rgn_struct *rgn; + phys_addr_t end; + + if (memsize_rgn_count == MAX_MEMSIZE_RGN) { + pr_err("not enough space on memsize_rgn\n"); + return; + } + rgn = &memsize_rgn[memsize_rgn_count++]; + rgn->base = base; + rgn->size = size; + rgn->nomap = nomap; + rgn->reusable = reusable; + + if (!name) { + strcpy(rgn->name, "unknown"); + } else { + strncpy(rgn->name, name, NAME_SIZE - 1); + rgn->name[NAME_SIZE - 1] = '\0'; + } + end = base + size - 1; + memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n", + __func__, &base, &end, nomap, reusable); +} +#endif /* MEMBLOCK_MEMSIZE */ + static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn) { struct page *start_pg, *end_pg; @@ -2138,6 +2182,61 @@ static int memblock_debug_show(struct seq_file *m, void *private) } DEFINE_SHOW_ATTRIBUTE(memblock_debug); +#ifdef CONFIG_MEMBLOCK_MEMSIZE + +static int memsize_rgn_cmp(const void *a, const void *b) +{ + const struct memsize_rgn_struct *ra = a, *rb = b; + + if (ra->base > rb->base) + return -1; + + if (ra->base < rb->base) + return 1; + + return 0; +} + +static int memblock_memsize_show(struct seq_file *m, void *private) +{ + int i; + struct memsize_rgn_struct *rgn; + unsigned long reserved = 0, reusable = 0; + + sort(memsize_rgn, memsize_rgn_count, + sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); + for (i = 0; i < memsize_rgn_count; i++) { + phys_addr_t base, end; + long size; + + rgn = &memsize_rgn[i]; + base = rgn->base; + size = rgn->size; + end = base + size; + + seq_printf(m, "0x%09lx-0x%09lx 0x%08lx ( %7lu KB ) %s %s %s\n", + &base, &end, + size, DIV_ROUND_UP(size, SZ_1K), + rgn->nomap ? "nomap" : " map", + rgn->reusable ? "reusable" : "unusable", + rgn->name); + if (rgn->reusable) + reusable += (unsigned long)rgn->size; + else + reserved += (unsigned long)rgn->size; + } + + seq_printf(m, "\n"); + seq_printf(m, " .unusable : %7lu KB\n", + DIV_ROUND_UP(reserved, SZ_1K)); + seq_printf(m, " .reusable : %7lu KB\n", + DIV_ROUND_UP(reusable, SZ_1K)); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(memblock_memsize); +#endif + static int __init memblock_init_debugfs(void) { struct dentry *root = debugfs_create_dir("memblock", NULL); @@ -2150,6 +2249,10 @@ static int __init memblock_init_debugfs(void) debugfs_create_file("physmem", 0444, root, &physmem, &memblock_debug_fops); #endif +#ifdef CONFIG_MEMBLOCK_MEMSIZE + debugfs_create_file("memsize", 0444, root, + NULL, &memblock_memsize_fops); +#endif return 0; } From patchwork Thu Mar 24 07:01:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790448 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 A43A1C433EF for ; Thu, 24 Mar 2022 06:59:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7E386B007B; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA6966B007D; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AC7F6B0081; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 50DAD6B007E for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 289A86099D for ; Thu, 24 Mar 2022 06:59:26 +0000 (UTC) X-FDA: 79278378732.10.2185581 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf05.hostedemail.com (Postfix) with ESMTP id 1CFE3100032 for ; Thu, 24 Mar 2022 06:59:24 +0000 (UTC) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220324065922epoutp0155b0ccbcedf84de888fe3243a982238a~fPum73LEX2825628256epoutp01f for ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220324065922epoutp0155b0ccbcedf84de888fe3243a982238a~fPum73LEX2825628256epoutp01f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105162; bh=04++ejy5/yIf+QVT4m1oQmzMNHrje9zF1MhViQLha2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qKNtYeZ0d13TzxYZ6nir9OU9mDYAaeIQRgOPACiwmFkZx2JKmG7vl77+xIioF1AHO 8GQv2kEKrsN+24cnMwXD4uP91Rzah0Ruhvju+h3Fyak3hYhXkSF5Mj+ulSd8IIoxto HV1Kp9YTkH94CbnJNFyhClITZTcNaCoZKdqBoi3Y= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220324065921epcas1p470d911984edf8b239256e90b1c145648~fPump5zYj2719127191epcas1p4r; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.38.248]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4KPGKz5PQ0z4x9QJ; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 01.2B.28648.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea~fPukRm-t23006230062epcas1p1U; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp20497a364e1b0f1aacf11b10546c2b47a~fPukQ0VTV2562325623epsmtrp2W; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a39-ff1ff70000006fe8-8c-623c16c79bb9 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 56.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 20220324065919epsmtip2c96f2e23e1233729ba054029a3a09905~fPukJGmsT3186931869epsmtip2b; 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 2/8] memblock: detect hidden memory hole size Date: Thu, 24 Mar 2022 16:01:52 +0900 Message-Id: <20220324070158.22969-3-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+NgFnrBKsWRmVeSWpSXmKPExsWy7bCmvu5xMZskg9YOdYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwWj9dzO3B47Jx1l91j06pONo9Nnyaxe5yY8ZvF o2/LKkaPMwuOsHt83iQXwB6VbZORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCX mJtqq+TiE6DrlpkDdJSSQlliTilQKCCxuFhJ386mKL+0JFUhI7+4xFYptSAlp8CsQK84Mbe4 NC9dLy+1xMrQwMDIFKgwITvj8rfrbAUHZCt2zOFsYLws3sXIySEhYCLxd1EDexcjF4eQwA5G ie1fjrFAOJ8YJZY9b4LKfGaUONbwihmm5eafy1CJXYwSp1/0M0M4Pxgl3m+4BVbFJqAt8X7B JFYQW0TATuLb7AOsIEXMAl2MEg8+HGQBSQgL2Eo03nkPVsQioCox7980NhCbFyh+YdpbNoh1 8hKrNxwAG8oJNGjlkgOMEPFH7BLTt0J94SJxYekKdghbWOLV8S1QtpTE53d7oeZkSzw9eQRo DgeQnSPRsEEWwrSXeH/JAsRkFtCUWL9LH6JYUWLn77lgi5gF+CTefe1hhajmlehoE4IoUZNo efaVFcKWkfj77xmU7SEx5eQEaIhMZJTo2/WOeQKj3CyEDQsYGVcxiqUWFOempxYbFpjC4ys5 P3cTIzjJaVnuYJz+9oPeIUYmDsZDjBIczEoivPcvWycJ8aYkVlalFuXHF5XmpBYfYjQFh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dnm5o/WSCg6JMUEJDf/31zavYC6at+62sfLc4/nC6wfY1 s3+8q/zD+nafTukd3i1XckM3+0lP2rTo8796FZlW61sXmN4cf3D9xMuP+89IB3iKmV748fb9 593LDwlUXmANDmOTYk5IcM6SXv8i/dOy63+f8d5PmOdSOturdMI69lqrqw/5lZdsvq+ZJm5R cJJxe4aEsPX2p2fj47hk5+sXfbNbytWtd3wLY0/JCy1BH6t6zeknlV2E/gU8PXw177R9zv7v P15NfRTE754YmTR9kduvFadv2qbqZfK/Cn7UorCKv0WJpTgj0VCLuag4EQBzrkittwIAAA== X-CMS-MailID: 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea References: <20220324070158.22969-1-jaewon31.kim@samsung.com> Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=qKNtYeZ0; spf=pass (imf05.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Stat-Signature: bddpt9wxbra7yugpxf5auojpj7xtsyfi X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1CFE3100032 X-HE-Tag: 1648105164-773577 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: Bootloader knows the actual memory size, but bootloader may reserve some memory for a specific purpose and pass the only remaining memory region to kernel. Even though kernel does not know what it is, we need to detect those regions to sum up all reserved memory. Let me call it memory hole. To expect the hole size, this patch assume two things. One is that each physical memory has 1GB aligned size and address. And the hole is less than 1GB. For the hole, let it be shown as unknown in memsize logic. This is an example. 0x0bf000000-0x0c0000000 0x01000000 ( 16384 KB ) nomap unusable unknown Signed-off-by: Jaewon Kim --- drivers/of/fdt.c | 2 ++ include/linux/memblock.h | 2 ++ mm/memblock.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ec2f60a78f8f..9721a3d7b7ae 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1294,6 +1294,8 @@ void __init early_init_dt_scan_nodes(void) /* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range(); + + memblock_memsize_detect_hole(); } bool __init early_init_dt_scan(void *params) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 468b016e179b..201f8723dfd8 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -608,10 +608,12 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) extern void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable); +extern void memblock_memsize_detect_hole(void); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { } +static inline void memblock_memsize_detect_hole(void) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/mm/memblock.c b/mm/memblock.c index 8492757f7192..8e032f44eb57 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1970,6 +1970,51 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n", __func__, &base, &end, nomap, reusable); } + +/* This function will be called to by early_init_dt_scan_nodes */ +void __init memblock_memsize_detect_hole(void) +{ + phys_addr_t base, end; + phys_addr_t prev_end, hole_sz; + int idx; + struct memblock_region *rgn; + int memblock_cnt = (int)memblock.memory.cnt; + + /* assume that the hole size is less than 1 GB */ + for_each_memblock_type(idx, (&memblock.memory), rgn) { + prev_end = (idx == 0) ? round_down(rgn->base, SZ_1G) : end; + base = rgn->base; + end = rgn->base + rgn->size; + + /* only for the last region, check a hole after the region */ + if (idx + 1 == memblock_cnt) { + hole_sz = round_up(end, SZ_1G) - end; + if (hole_sz) + memblock_memsize_record(NULL, end, hole_sz, + true, false); + } + + /* for each region, check a hole prior to the region */ + hole_sz = base - prev_end; + if (!hole_sz) + continue; + if (hole_sz < SZ_1G) { + memblock_memsize_record(NULL, prev_end, hole_sz, true, + false); + } else { + phys_addr_t hole_sz1, hole_sz2; + + hole_sz1 = round_up(prev_end, SZ_1G) - prev_end; + if (hole_sz1) + memblock_memsize_record(NULL, prev_end, + hole_sz1, true, false); + hole_sz2 = base % SZ_1G; + if (hole_sz2) + memblock_memsize_record(NULL, base - hole_sz2, + hole_sz2, true, false); + } + } +} #endif /* MEMBLOCK_MEMSIZE */ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn) From patchwork Thu Mar 24 07:01:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790447 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 95A20C433EF for ; Thu, 24 Mar 2022 06:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE22C6B0078; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 947B86B007B; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66EE96B0078; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 0CE726B0080 for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B4C21A5BC0 for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) X-FDA: 79278378690.28.7D1B4BC Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf17.hostedemail.com (Postfix) with ESMTP id C36BF40017 for ; Thu, 24 Mar 2022 06:59:24 +0000 (UTC) Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20220324065922epoutp036124cc8190b3ac738f03d46df0b67fa5~fPunCbhYe2276022760epoutp03u for ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20220324065922epoutp036124cc8190b3ac738f03d46df0b67fa5~fPunCbhYe2276022760epoutp03u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105162; bh=YGpkejzEBgPEWiqqAXB1bDr6fxKfkieYcgxWNQ4BKdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SIs+MnfaZdinj0I7IqYyE76A0LCYFOkrXDH0sxIEPxIUHJh7Eg2irIs9Ubs5DL1RH kWBQGWboIq6xZK3LM01to4nvxScEhsLvTMWZ1BXgpmTje2OSUaTDPBsz9/096KTnwv ntmUmlBIWi5kUjEAzy3b++WhHyqzDCHlSyBiTxYs= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220324065922epcas1p401e2cf5f6906a46039fd08e4ecf3fd5e~fPumw-BJ02260522605epcas1p40; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.38.248]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4KPGKz6PMjz4x9QF; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 11.2B.28648.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p3429ec2c9595c54ffe4ee25f273febd1c~fPukVRPTh0544005440epcas1p36; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp2654a6c9391ab508b7f30a149d7adbdae~fPukUkKYV2562325623epsmtrp2X; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a39-813e6a8000006fe8-8d-623c16c7a2f6 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 76.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 20220324065919epsmtip2bcffa62f9f2f6596a2a156bca5ee78d9~fPukLbdZS3186531865epsmtip2d; 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 3/8] memblock: handle overlapped reserved memory region Date: Thu, 24 Mar 2022 16:01:53 +0900 Message-Id: <20220324070158.22969-4-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+NgFnrJKsWRmVeSWpSXmKPExsWy7bCmvu5xMZskg1+bNC3mrF/DZtG9eSaj Re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epcas1p3429ec2c9595c54ffe4ee25f273febd1c X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p3429ec2c9595c54ffe4ee25f273febd1c References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C36BF40017 X-Stat-Signature: pseiwdxquymeuhu5sxuico93jqtx49km Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=SIs+Mnfa; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf17.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com X-Rspam-User: X-HE-Tag: 1648105164-816753 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: It is not common, but defining an overlapped region is possible. Actually memblock_add_range allows to overlap with existing ones. The memsize currently does not handle this overlapped case. But this patch tries to handle one overlapped case. Here's the case. There is an unknown memsize region, which means the region was removed and not passed at bootloader stage. And there is a reserved memory region defined in device tree which is overlapped with the unknown region. We expect that information in device tree make the unknown region clear. This patch handle the overlapped region with following conditions. 1) The already existing overlapped region should be unknown and no-map. 2) The newly added region should have a name, and its region should be same with or part of the existing one. Here is an example. Before this patch, memsize shows both overlapped region. 0x0ea000000-0x0ed900000 0x03900000 ( 58368 KB ) nomap unusable overlapped 0x0ea000000-0x0f1400000 0x07400000 ( 118784 KB ) nomap unusable unknown After this patch, the overlapped region is named. 0x0ea000000-0x0ed900000 0x03900000 ( 58368 KB ) nomap unusable overlapped 0x0e9b00000-0x0ea000000 0x00500000 ( 5120 KB ) nomap unusable unknown Signed-off-by: Jaewon Kim --- mm/memblock.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 8e032f44eb57..9195a51bfa5d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1944,6 +1944,75 @@ struct memsize_rgn_struct { static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock; static int memsize_rgn_count __initdata_memblock; +static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void) +{ + if (memsize_rgn_count == ARRAY_SIZE(memsize_rgn)) { + pr_err("not enough space on memsize_rgn\n"); + return NULL; + } + return &memsize_rgn[memsize_rgn_count++]; +} + +static bool __init_memblock memsize_update_nomap_region(const char *name, phys_addr_t base, + phys_addr_t size, bool nomap) +{ + int i; + struct memsize_rgn_struct *rmem_rgn, *new_rgn; + + if (!name) + return false; + + for (i = 0; i < memsize_rgn_count; i++) { + rmem_rgn = &memsize_rgn[i]; + + if (!rmem_rgn->nomap) + continue; + if (strcmp(rmem_rgn->name, "unknown")) + continue; + if (base < rmem_rgn->base) + continue; + if (base + size > rmem_rgn->base + rmem_rgn->size) + continue; + + if (base == rmem_rgn->base && size == rmem_rgn->size) { + strncpy(new_rgn->name, name, NAME_SIZE); + new_rgn->name[NAME_SIZE - 1] = '\0'; + return true; + } + + new_rgn = memsize_get_new_rgn(); + if (!new_rgn) + return true; + new_rgn->base = base; + new_rgn->size = size; + new_rgn->nomap = nomap; + new_rgn->reusable = false; + strncpy(new_rgn->name, name, NAME_SIZE); + new_rgn->name[NAME_SIZE - 1] = '\0'; + + if (base == rmem_rgn->base && size < rmem_rgn->size) { + rmem_rgn->base = base + size; + rmem_rgn->size -= size; + } else if (base + size == rmem_rgn->base + rmem_rgn->size) { + rmem_rgn->size -= size; + } else { + new_rgn = memsize_get_new_rgn(); + if (!new_rgn) + return true; + new_rgn->base = base + size; + new_rgn->size = (rmem_rgn->base + rmem_rgn->size) + - (base + size); + new_rgn->nomap = nomap; + new_rgn->reusable = false; + strcpy(new_rgn->name, "unknown"); + rmem_rgn->size = base - rmem_rgn->base; + } + return true; + } + + return false; +} + void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { @@ -1954,7 +2023,14 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, pr_err("not enough space on memsize_rgn\n"); return; } - rgn = &memsize_rgn[memsize_rgn_count++]; + + if (memsize_update_nomap_region(name, base, size, nomap)) + return; + + rgn = memsize_get_new_rgn(); + if (!rgn) + return; + rgn->base = base; rgn->size = size; rgn->nomap = nomap; From patchwork Thu Mar 24 07:01:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790446 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 DBDF0C433F5 for ; Thu, 24 Mar 2022 06:59:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 951B76B007E; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5AF8D0001; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30C156B007B; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 067BF6B007D for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AC807A30BF for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) X-FDA: 79278378690.31.BD953E5 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf16.hostedemail.com (Postfix) with ESMTP id B226C18002D for ; Thu, 24 Mar 2022 06:59:24 +0000 (UTC) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220324065922epoutp026f9cdeae790dcef706178b59a038e58b~fPumzQVK51428414284epoutp02d for ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220324065922epoutp026f9cdeae790dcef706178b59a038e58b~fPumzQVK51428414284epoutp02d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105162; bh=KyBdZg8CThIyXolubx/7sGIn+ypooiLqPM4nQuxNNcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T/F8+jQJnqAcCruZ1LHJv3s2D5EeFE9uc/DAPnXzMUbMCBtDN4oE2+be0W6plmVh8 xXn1JSY/llGkikbr9ZuTjrYvJA/FpuZ7EXs/OXW9N2Ru2ienSZTr2CiOWwQ5WEfrQT w/+fhPVod3jnWj3FJrVWJCvWzhOVpmoq7VWytMtI= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20220324065921epcas1p3b26228c7923bad0615f453f252832899~fPumTg15a0544405444epcas1p3J; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.226]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4KPGKz6rNvz4x9QX; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id C2.0A.64085.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p256ff799f37a765a432475808e708d639~fPukWGpZ80342903429epcas1p28; 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 20220324065919epsmtrp17a689e995e1ebee583756cc406048a8b~fPukVPaz92225222252epsmtrp1U; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a35-9c3ff7000000fa55-0c-623c16c78af8 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 86.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 20220324065919epsmtip28837454c5e037d06492410f49713d2ec~fPukNtTfb3186931869epsmtip2c; 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 4/8] memblock: track memblock changed at early param Date: Thu, 24 Mar 2022 16:01:54 +0900 Message-Id: <20220324070158.22969-5-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+NgFnrJKsWRmVeSWpSXmKPExsWy7bCmge5xMZskgwsLdCzmrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziEl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l3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHsUl01Kak5mWWqRvl0CV8a+adfZC65bVizduoe1gfGmbhcjJ4eE gIlE565fjCC2kMAORolf+4wg4jISb84/Zeli5ACyhSUOHy7uYuQCKvnGKNFz9yIzSA2bgLbE +wWTWEFsEQEniQ1XVrOAFDELTGCUWLnsEwtIQljAReLfx/9sIDaLgKrEwxlXwWxeAVuJ96/O skAsk5dYveEA2FBOATuJlUsOQB1kK3H25AG2CYx8CxgZVjFKphYU56bnFhsWGOWllusVJ+YW l+al6yXn525iBAekltYOxj2rPugdYmTiYDzEKMHBrCTCe/+ydZIQb0piZVVqUX58UWlOavEh RmkOFiVx3gtdJ+OFBNITS1KzU1MLUotgskwcnFINTAb/lF2K/u87uqp+sVT3sw7jnMZptsHv p88IrrLTFan2N+Gbt+TH0uIWLZ7/tVYmlzldm6cVmqT6LT/Hd3TR/d2xTpJLPu/oydrfmmUo yOg1j3Xff7aN+07Pd62X6ft3vo19haf0OrYMTdlyj7L/bX51s62u38r7faXywMdO10/ry2YY 8jtZJ812FA373lu29feVfXwZ55ZHJwbNFbOUX84hF53wxFP0nc+S1FzJO47WLfaPNC77zVft Oz1TfO76aXPF7E9ZMW6dn7vdwmm9VW9qtK2vq/GCzqCl77+nV+X7LCv5VX5I9ovR8uTZh3Ki Zm86ccqVy2nqlscVTx+bpj4yzMsPTzZ7vOps6/EdSizFGYmGWsxFxYkA3wxP9bcCAAA= X-CMS-MailID: 20220324065919epcas1p256ff799f37a765a432475808e708d639 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p256ff799f37a765a432475808e708d639 References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="T/F8+jQJ"; spf=pass (imf16.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B226C18002D X-Stat-Signature: 4u41a6hsc918ckr79zrrdzr8naf9qfzg X-HE-Tag: 1648105164-984780 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 addition to reserved-memory in device tree, an option in cmdline may result in memblock allocation. This patch tries to distinguish memblock changes done at early param. A region in memsize will be created with name as the param string. And the region size will be updated during the param function. Signed-off-by: Jaewon Kim --- include/linux/memblock.h | 4 ++ init/main.c | 13 ++++- mm/memblock.c | 101 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 112 insertions(+), 6 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 201f8723dfd8..4be4e0e6baf4 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -609,11 +609,15 @@ extern void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable); extern void memblock_memsize_detect_hole(void); +extern void memblock_memsize_set_name(const char *name); +extern void memblock_memsize_unset_name(void); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { } static inline void memblock_memsize_detect_hole(void) { } +static inline void memblock_memsize_set_name(const char *name) { } +static inline void memblock_memsize_unset_name(void) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/init/main.c b/init/main.c index 560f45c27ffe..ce59521b5ae5 100644 --- a/init/main.c +++ b/init/main.c @@ -214,8 +214,15 @@ static bool __init obsolete_checksetup(char *line) pr_warn("Parameter %s is obsolete, ignored\n", p->str); return true; - } else if (p->setup_func(line + n)) - return true; + } else { + int ret; + + memblock_memsize_set_name(p->str); + ret = p->setup_func(line + n); + memblock_memsize_unset_name(); + if (ret) + return true; + } } p++; } while (p < __setup_end); @@ -736,8 +743,10 @@ static int __init do_early_param(char *param, char *val, (strcmp(param, "console") == 0 && strcmp(p->str, "earlycon") == 0) ) { + memblock_memsize_set_name(p->str); if (p->setup_func(val) != 0) pr_warn("Malformed early option '%s'\n", param); + memblock_memsize_unset_name(); } } /* We accept everything at this stage. */ diff --git a/mm/memblock.c b/mm/memblock.c index 9195a51bfa5d..4f21b596687e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -169,6 +169,18 @@ static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size) return *size = min(*size, PHYS_ADDR_MAX - base); } +#ifdef CONFIG_MEMBLOCK_MEMSIZE +static void memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size); +static void memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size); +#else +static inline void memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) { } +static inline void memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) { } +#endif /* CONFIG_MEMBLOCK_MEMSIZE */ + /* * Address comparison utilities */ @@ -578,6 +590,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, bool insert = false; phys_addr_t obase = base; phys_addr_t end = base + memblock_cap_size(base, &size); + phys_addr_t new_size = 0; int idx, nr_new; struct memblock_region *rgn; @@ -592,7 +605,8 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, type->regions[0].flags = flags; memblock_set_region_node(&type->regions[0], nid); type->total_size = size; - return 0; + new_size = size; + goto done; } repeat: /* @@ -621,10 +635,12 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, #endif WARN_ON(flags != rgn->flags); nr_new++; - if (insert) + if (insert) { memblock_insert_region(type, idx++, base, rbase - base, nid, flags); + new_size += rbase - base; + } } /* area below @rend is dealt with, forget about it */ base = min(rend, end); @@ -633,9 +649,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, /* insert the remaining portion */ if (base < end) { nr_new++; - if (insert) + if (insert) { memblock_insert_region(type, idx, base, end - base, nid, flags); + new_size += end - base; + } } if (!nr_new) @@ -653,8 +671,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, goto repeat; } else { memblock_merge_regions(type); - return 0; } +done: + if (new_size == size) + memblock_memsize_record_add(type, obase, size); + return 0; } /** @@ -790,6 +811,7 @@ static int __init_memblock memblock_remove_range(struct memblock_type *type, for (i = end_rgn - 1; i >= start_rgn; i--) memblock_remove_region(type, i); + memblock_memsize_record_remove(type, base, size); return 0; } @@ -2091,6 +2113,77 @@ void __init memblock_memsize_detect_hole(void) } } } + +/* assume that freeing region is NOT bigger than the previous region */ +static void __init_memblock memblock_memsize_free(phys_addr_t free_base, + phys_addr_t free_size) +{ + int i; + struct memsize_rgn_struct *rgn; + phys_addr_t free_end, end; + + free_end = free_base + free_size - 1; + memblock_dbg("%s %pa..%pa\n", + __func__, &free_base, &free_end); + + for (i = 0; i < memsize_rgn_count; i++) { + rgn = &memsize_rgn[i]; + + end = rgn->base + rgn->size; + if (free_base < rgn->base || + free_base >= end) + continue; + + free_end = free_base + free_size; + if (free_base == rgn->base) { + rgn->size -= free_size; + if (rgn->size != 0) + rgn->base += free_size; + } else if (free_end == end) { + rgn->size -= free_size; + } else { + memblock_memsize_record(rgn->name, free_end, + end - free_end, rgn->nomap, rgn->reusable); + rgn->size = free_base - rgn->base; + } + } +} + +static const char *memblock_memsize_name; + +void __init memblock_memsize_set_name(const char *name) +{ + memblock_memsize_name = name; +} + +void __init memblock_memsize_unset_name(void) +{ + memblock_memsize_name = NULL; +} + +static void __init_memblock memblock_memsize_record_add(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) +{ + if (memblock_memsize_name) { + if (type == &memblock.reserved) + memblock_memsize_record(memblock_memsize_name, + base, size, false, false); + else if (type == &memblock.memory) + memblock_memsize_free(base, size); + } +} + +static void __init_memblock memblock_memsize_record_remove(struct memblock_type *type, + phys_addr_t base, phys_addr_t size) +{ + if (memblock_memsize_name) { + if (type == &memblock.reserved) + memblock_memsize_free(base, size); + else if (type == &memblock.memory) + memblock_memsize_record(memblock_memsize_name, + base, size, true, false); + } +} #endif /* MEMBLOCK_MEMSIZE */ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn) From patchwork Thu Mar 24 07:01:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790451 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 EAA7FC433F5 for ; Thu, 24 Mar 2022 06:59:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE1F78D0002; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B258A8D0003; 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 6B0C46B0081; 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 E18886B0081 for ; Thu, 24 Mar 2022 02:59:26 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A8A025D4 for ; Thu, 24 Mar 2022 06:59:26 +0000 (UTC) X-FDA: 79278378732.12.241C74D Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf10.hostedemail.com (Postfix) with ESMTP id C1532C0028 for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220324065923epoutp017f3255c75c7932110007441f77e6fd0e~fPuoIdiYZ3028930289epoutp01U for ; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220324065923epoutp017f3255c75c7932110007441f77e6fd0e~fPuoIdiYZ3028930289epoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105163; bh=Bqm/uYAUxy26yMvY4oGKIsXAEx3p7iHRdLjtnHs2oTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EbruOS4pLz4J6X/p21E4Xg00qDE+HW1p8xe+EeBvtkugsYa0F32S7rlv9nlTs9U94 7iNAfYNhTM7hgEJ/TSOm2wNjUg7IXfMrnjBHhinzy5GofyYnB2Y85A/0u9ybxBBJIV HM0YDG++MxslSqbcpJqJjfYCX1a3zrkGGDCGVQjg= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20220324065922epcas1p287d475f1da44cd5157aa68723aa7fc64~fPunicYXx0552505525epcas1p2W; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.38.247]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4KPGL11p4Wz4x9QC; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 54.68.09592.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p3a3a267c4348be4fd3bb8437d4e6db142~fPukZTpC50544405444epcas1p3H; 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 20220324065919epsmtrp143dd5c0a9b1565df9fecce82a4a1d18b~fPukYGkAZ2225322253epsmtrp1O; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a37-2a5ff70000002578-f1-623c16c75437 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 97.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 20220324065919epsmtip2f6256c3ab39428720f6e8985cbb638fe~fPukP_OPb3186531865epsmtip2e; 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 5/8] memblock: track kernel size on memsize Date: Thu, 24 Mar 2022 16:01:55 +0900 Message-Id: <20220324070158.22969-6-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+NgFnrGKsWRmVeSWpSXmKPExsWy7bCmnu5xMZskg9n3TC3mrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKzAr3ixNzi 0rx0vbzUEitDAwMjU6DChOyMN6t2sxQctau4dreLqYHxnHEXIyeHhICJxLlnU9i7GLk4hAR2 MEps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xeZNcAHsUl01Kak5mWWqRvl0CV8abVbtZCo7aVVy728XUwHjOuIuRg0NC wERi4/bwLkYuDiGBHYwSG28tY+li5ASKy0i8Of+UBaJGWOLw4WKImm+MEjsebgCrYRPQlni/ YBIriC0i4CSx4cpqFpAiZoEJjBIrl30CKxIWsJZ4f+IWWBGLgKrEy0ez2UCG8grYSiy/Ygqx S15i9YYDzCA2p4CdxMolBxhBbCGgkrMnD7BNYORbwMiwilEytaA4Nz232LDAKC+1XK84Mbe4 NC9dLzk/dxMjOBy1tHYw7ln1Qe8QIxMH4yFGCQ5mJRHe+5etk4R4UxIrq1KL8uOLSnNSiw8x SnOwKInzXug6GS8kkJ5YkpqdmlqQWgSTZeLglGpgsi5S+1jtbagnEFu37N4Cb6eDRyMOV+Vx KJxKOnTYdOkrRV2eeeJlZVOFqs6I1k57+jL48aazTpMF4jaXMLCdWunrdXXPBMbdv6cpr3rz dNLx7Ed36g69y+ftT1Hz3VF0Udf2Q4j2Qztjzkfb8rmXi85+L6wkVqq2/Q2b2JVXvVVKTD+t d52pi5iQIbm6iS/mL08Fo+KlnSy/Of2+G5zez/7P7qR4ROGX8DcRaxcGrdry1t+Zt6Xn2/On Vf5FOR33JRQnaH5cOkcivKRN/kG7yb42z/92oW8de8VaX3d5bPu7RHy7Rp/AMc9zqpc37L4g 5GS5Kzs7nE96hso6y/97BSfe7s/MSnoW3v9xdcIRJZbijERDLeai4kQA6tE0GrYCAAA= X-CMS-MailID: 20220324065919epcas1p3a3a267c4348be4fd3bb8437d4e6db142 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p3a3a267c4348be4fd3bb8437d4e6db142 References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=EbruOS4p; spf=pass (imf10.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C1532C0028 X-Stat-Signature: s18r3uckng4gdihoeo1fjiooqwnwk97t X-HE-Tag: 1648105165-672122 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: Some memory regions are already being tracked by previous patches. But there are many memory allocations from memblock and frees to memblock during the boot time. This patch tracks the memblock size used for the common kernel. To to this, tracking memblock size is disabled for some memory handling logics like early param, device tree, and default cma size. For precise kernel size, this patch counts not actually freed size to buddy at boot time, and does not count freed size from ramdisk and init section. Additionally this patch does one important thing. This patch blocks memblock_add_range of memblock_remove_range not to update memsize if free pages were already released to the buddy allocator. This is an example. The kernel size is newly added by this patch. .kernel : 135137 KB .unusable : 788073 KB .reusable : 294912 KB Signed-off-by: Jaewon Kim --- drivers/of/fdt.c | 6 ++++++ include/linux/memblock.h | 6 ++++++ kernel/dma/contiguous.c | 7 ++++-- mm/memblock.c | 46 ++++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 9 +++++++- 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9721a3d7b7ae..8d38d1499d71 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -640,6 +640,8 @@ void __init early_init_fdt_scan_reserved_mem(void) if (!initial_boot_params) return; + memblock_memsize_disable_tracking(); + /* Process header /memreserve/ fields */ for (n = 0; ; n++) { fdt_get_mem_rsv(initial_boot_params, n, &base, &size); @@ -652,6 +654,7 @@ void __init early_init_fdt_scan_reserved_mem(void) fdt_scan_reserved_mem(); fdt_reserve_elfcorehdr(); fdt_init_reserved_mem(); + memblock_memsize_enable_tracking(); } /** @@ -1289,12 +1292,15 @@ void __init early_init_dt_scan_nodes(void) if (rc) pr_warn("No chosen node found, continuing without\n"); + memblock_memsize_disable_tracking(); + /* Setup memory, calling early_init_dt_add_memory_arch */ early_init_dt_scan_memory(); /* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range(); + memblock_memsize_enable_tracking(); memblock_memsize_detect_hole(); } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 4be4e0e6baf4..6d59c6e68467 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -611,6 +611,9 @@ extern void memblock_memsize_record(const char *name, phys_addr_t base, extern void memblock_memsize_detect_hole(void); extern void memblock_memsize_set_name(const char *name); extern void memblock_memsize_unset_name(void); +extern void memblock_memsize_enable_tracking(void); +extern void memblock_memsize_disable_tracking(void); +extern void memblock_memsize_mod_kernel_size(long size); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, @@ -618,6 +621,9 @@ static inline void memblock_memsize_record(const char *name, phys_addr_t base, static inline void memblock_memsize_detect_hole(void) { } static inline void memblock_memsize_set_name(const char *name) { } static inline void memblock_memsize_unset_name(void) { } +static inline void memblock_memsize_enable_tracking(void){ } +static inline void memblock_memsize_disable_tracking(void){ } +static inline void memblock_memsize_mod_kernel_size(long size) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 7415c1135afa..2a3ecf6a6b22 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -230,10 +230,11 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, { int ret; + memblock_memsize_disable_tracking(); ret = cma_declare_contiguous(base, size, limit, 0, 0, fixed, "reserved", res_cma); if (ret) - return ret; + goto out; /* Architecture specific contiguous memory fixup. */ dma_contiguous_early_fixup(cma_get_base(*res_cma), @@ -241,7 +242,9 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, memblock_memsize_record("dma_cma", cma_get_base(*res_cma), cma_get_size(*res_cma), false, true); - return 0; +out: + memblock_memsize_enable_tracking(); + return ret; } /** diff --git a/mm/memblock.c b/mm/memblock.c index 4f21b596687e..aee22dbc2500 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1965,6 +1965,23 @@ struct memsize_rgn_struct { #define MAX_MEMSIZE_RGN 64 static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock; static int memsize_rgn_count __initdata_memblock; +static long kernel_init_size; +static bool do_memsize __initdata_memblock = true; + +void __init memblock_memsize_enable_tracking(void) +{ + do_memsize = true; +} + +void __init memblock_memsize_disable_tracking(void) +{ + do_memsize = false; +} + +void memblock_memsize_mod_kernel_size(long size) +{ + kernel_init_size += size; +} static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void) { @@ -2170,6 +2187,12 @@ static void __init_memblock memblock_memsize_record_add(struct memblock_type *ty base, size, false, false); else if (type == &memblock.memory) memblock_memsize_free(base, size); + } else if (do_memsize) { + if (type == &memblock.reserved) { + memblock_dbg("%s: kernel %lu %+ld\n", __func__, + kernel_init_size, (unsigned long)size); + kernel_init_size += size; + } } } @@ -2182,6 +2205,12 @@ static void __init_memblock memblock_memsize_record_remove(struct memblock_type else if (type == &memblock.memory) memblock_memsize_record(memblock_memsize_name, base, size, true, false); + } else if (do_memsize) { + if (type == &memblock.reserved) { + memblock_dbg("%s: kernel %lu %+ld\n", __func__, + kernel_init_size, (unsigned long)size); + kernel_init_size -= size; + } } } #endif /* MEMBLOCK_MEMSIZE */ @@ -2289,6 +2318,19 @@ static unsigned long __init __free_memory_core(phys_addr_t start, unsigned long end_pfn = min_t(unsigned long, PFN_DOWN(end), max_low_pfn); +#ifdef CONFIG_MEMBLOCK_MEMSIZE + unsigned long start_align_up = PFN_ALIGN(start); + unsigned long end_align_down = PFN_PHYS(end_pfn); + + if (start_pfn >= end_pfn) { + memblock_memsize_mod_kernel_size(end - start); + } else { + if (start_align_up > start) + memblock_memsize_mod_kernel_size(start_align_up - start); + if (end_pfn != max_low_pfn && end_align_down < end) + memblock_memsize_mod_kernel_size(end - end_align_down); + } +#endif if (start_pfn >= end_pfn) return 0; @@ -2374,6 +2416,8 @@ void __init memblock_free_all(void) pages = free_low_memory_core_early(); totalram_pages_add(pages); + + memblock_memsize_disable_tracking(); } #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) @@ -2441,6 +2485,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private) } seq_printf(m, "\n"); + seq_printf(m, " .kernel : %7lu KB\n", + DIV_ROUND_UP(kernel_init_size, SZ_1K)); seq_printf(m, " .unusable : %7lu KB\n", DIV_ROUND_UP(reserved, SZ_1K)); seq_printf(m, " .reusable : %7lu KB\n", diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6e0b4596cde9..bbbe314850b0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8230,8 +8230,15 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char free_reserved_page(page); } - if (pages && s) + if (pages && s) { pr_info("Freeing %s memory: %ldK\n", s, K(pages)); + if (!strcmp(s, "initrd") || !strcmp(s, "unused kernel")) { + long size; + + size = -1 * (long)(pages << PAGE_SHIFT); + memblock_memsize_mod_kernel_size(size); + } + } return pages; } 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+5mgtgmL7F6wwFmEJsTaM7KJQcYQeZICNxjlzi9Zz3YHAkBF4lVd9Mg6oUlXh3fAnWplMTL /jYoO1vi6ckjzBDlORING2QhTHuJ95csQExmAU2J9bv0IYoVJXb+nssIYjML8Em8+9rDClHN K9HRJgRRoibR8uwrK4QtI/H33zMo20Pi2LGzTJAAmcgo8eTYYdYJjHKzEDYsYGRcxSiWWlCc m55abFhgCI+u5PzcTYzgFKdluoNx4tsPeocYmTgYDzFKcDArifDev2ydJMSbklhZlVqUH19U mpNafIjRFBhyE5mlRJPzgUk2ryTe0MTSwMTMyMTC2NLYTEmcd9W004lCAumJJanZqakFqUUw fUwcnFINTJr7Ez+9Tvxw+cHp4/+7K2W/TtMVlbu9xf/3lNW36p4ETzaxeFDKpd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MCpM+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; From patchwork Thu Mar 24 07:01:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790450 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 C2C06C433F5 for ; Thu, 24 Mar 2022 06:59:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94A9F8D0001; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83B678D0002; 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 418636B007D; 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 037A96B0083 for ; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id C94A160568 for ; Thu, 24 Mar 2022 06:59:26 +0000 (UTC) X-FDA: 79278378732.06.F86099D Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf07.hostedemail.com (Postfix) with ESMTP id 0EB1C40036 for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220324065923epoutp01b88e8039d4652b22339aacdb417b62b7~fPuoid2cz3028930289epoutp01V for ; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220324065923epoutp01b88e8039d4652b22339aacdb417b62b7~fPuoid2cz3028930289epoutp01V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105164; bh=PwBzPZxuTryly8gTU/4JXZYuZ8XrDmft5OHgh415hkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F72tEsEKFQcFMguq+1/A44KVgP/ON+Rt1KswvLfmxSsm9W4PLFAeCCzVGxZtsIEpm cAgjg5M9eyDkiIg5z45axkDZIqa6lvf0ajztqKtEbM9JV7nEXc9dzD6YSgPZxS8Sfb Y/vBgG5I8t39XKMTESa6XxX9gT7c8gnRpVpmS3Oo= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20220324065923epcas1p26fadde41347eda12b659c67ce636d567~fPuoPcYfB0342903429epcas1p2U; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.36.222]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4KPGL213Fpz4x9QQ; Thu, 24 Mar 2022 06:59:22 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 52.2B.28648.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p4b935c884aa3fde0917f6dff8bff128ed~fPukeTqKQ2463324633epcas1p4-; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220324065919epsmtrp2525e0b3bc0b06b141feab270e0fdde3d~fPukdoAAc2562225622epsmtrp2b; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a39-ff1ff70000006fe8-8f-623c16c756f9 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id B8.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 20220324065919epsmtip2fdb11aefb76992321248a719fdd451e8~fPukVfQeh3186531865epsmtip2f; 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 7/8] memblock: print memsize summary information Date: Thu, 24 Mar 2022 16:01:57 +0900 Message-Id: <20220324070158.22969-8-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+NgFnrJKsWRmVeSWpSXmKPExsWy7bCmru5xMZskg+vdJhZz1q9hs+jePJPR ovf9KyaLy7vmsFncW/Of1eLI+u1MFrMb+xgtHq/nduDw2DnrLrvHplWdbB6bPk1i9zgx4zeL R9+WVYweZxYcYff4vEkugD0q2yYjNTEltUghNS85PyUzL91WyTs43jne1MzAUNfQ0sJcSSEv MTfVVsnFJ0DXLTMH6CglhbLEnFKgUEBicbGSvp1NUX5pSapCRn5xia1SakFKToFZgV5xYm5x aV66Xl5qiZWhgYGRKVBhQnbGpUUPmQt+8lW87XnH2MB4kruLkZNDQsBEYufSA+xdjFwcQgI7 GCXmPjzNBOF8YpSYcOgVM4TzmVGi42crI0zL7xdroVp2MUrMvLGCDcL5wSgx+ccmZpAqNgFt ifcLJrGC2CICdhLfZh9gBSliFuhilHjw4SALSEJYwEFizYIzYGNZBFQlTv/oArN5BWwleiaf gFonL7F6wwGwoZxAg1YuOcAIMkhC4B67xLe/rawQRS4SGzumskPYwhKvjm+BsqUkPr/bywZh Z0s8PXkEaBAHkJ0j0bBBFsK0l3h/yQLEZBbQlFi/Sx+iWFFi5++5YBcwC/BJvPvawwpRzSvR 0SYEUaIm0fLsK9R+GYm//55BlXhILHrmCAmRiYwSd//eZZ7AKDcLYcECRsZVjGKpBcW56anF hgWm8AhLzs/dxAhOc1qWOxinv/2gd4iRiYPxEKMEB7OSCO/9y9ZJQrwpiZVVqUX58UWlOanF hxhNgSE3kVlKNDkfmGjzSuINTSwNTMyMTCyMLY3NlMR5V007nSgkkJ5YkpqdmlqQWgTTx8TB KdXAtJ3v0hrxTw5SFu/+XVZJvf7h60GNF9onq9v/Lj+TKPH95vPc075LbTXv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3Sw+xvkw UfGhgeu/aCtjVpOri7gbtWTuOFQU3Z6nJ8bw4dD+nC3Ln5unFG1cxHTZjbf6J9t7hrl8M4Ss Enw8nkyd2teh2xoYqt2zsHblykTpz1M2fLC5rzut8dXyD9kBuxhXu5i5L/O/bVtmvPnuEYXH JTn3Xz5OzvrzI6Mouuje+2dLXnLr8UfUs6f+ZvHZo8RSnJFoqMVcVJwIACXlyq+3AgAA X-CMS-MailID: 20220324065919epcas1p4b935c884aa3fde0917f6dff8bff128ed X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p4b935c884aa3fde0917f6dff8bff128ed References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Stat-Signature: mhmstudknr943b8w16f387dp1tzbb1nf Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=F72tEsEK; spf=pass (imf07.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.24 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0EB1C40036 X-HE-Tag: 1648105165-976025 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: With the previous patches, now we can print summary information. Here's an example of 4GB DRAM device. Reserved : 746924 KB .kernel : 137027 KB .unusable : 609897 KB System : 3447380 KB .common : 3152468 KB .reusable : 294912 KB Total : 4194304 KB ( 4096.00 MB ) Signed-off-by: Jaewon Kim --- mm/memblock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 597ec7fb5bb2..ef8cec6242d2 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2492,7 +2492,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private) { int i; struct memsize_rgn_struct *rgn; - unsigned long reserved = 0, reusable = 0; + unsigned long reserved = 0, reusable = 0, total; + unsigned long system = totalram_pages() << PAGE_SHIFT; sort(memsize_rgn, memsize_rgn_count, sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); @@ -2518,13 +2519,24 @@ static int memblock_memsize_show(struct seq_file *m, void *private) reserved += (unsigned long)rgn->size; } + total = kernel_init_size + reserved + system; + seq_printf(m, "\n"); + seq_printf(m, "Reserved : %7lu KB\n", + DIV_ROUND_UP(kernel_init_size + reserved, SZ_1K)); seq_printf(m, " .kernel : %7lu KB\n", DIV_ROUND_UP(kernel_init_size, SZ_1K)); seq_printf(m, " .unusable : %7lu KB\n", DIV_ROUND_UP(reserved, SZ_1K)); + seq_printf(m, "System : %7lu KB\n", + DIV_ROUND_UP(system, SZ_1K)); + seq_printf(m, " .common : %7lu KB\n", + DIV_ROUND_UP(system - reusable, SZ_1K)); seq_printf(m, " .reusable : %7lu KB\n", DIV_ROUND_UP(reusable, SZ_1K)); + seq_printf(m, "Total : %7lu KB ( %5lu.%02lu MB )\n", + DIV_ROUND_UP(total, SZ_1K), + total >> 20, ((total % SZ_1M) * 100) >> 20); return 0; } From patchwork Thu Mar 24 07:01:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 12790452 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 E6A89C433F5 for ; Thu, 24 Mar 2022 06:59:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F16646B007D; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7D2A8D0003; 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 8ACAD6B007D; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 43D596B0087 for ; Thu, 24 Mar 2022 02:59:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0E7D4A5A8E for ; Thu, 24 Mar 2022 06:59:27 +0000 (UTC) X-FDA: 79278378774.24.C079033 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf28.hostedemail.com (Postfix) with ESMTP id ED99FC003C for ; Thu, 24 Mar 2022 06:59:25 +0000 (UTC) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220324065923epoutp0497cde865f1dedb9bc1dcba9ec8cfc00d~fPuoFLq_y3232032320epoutp04r for ; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220324065923epoutp0497cde865f1dedb9bc1dcba9ec8cfc00d~fPuoFLq_y3232032320epoutp04r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1648105163; bh=u2PvZFuDuPIcIAY1hJK/XTTeOGQZUldkV5e7lNDxAA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3wXxW+6VhA7zj1NSHXfo5YgmI9n4AmSo8KRHuBwd/9veg2/bRKJE6y2XigLDEntJ 5MT7NQWB2KF32mhDPP3PwIdTsIVOXcThu1IiA8vhPV3VrAu8f1JPYIkZwA+mwHk+OV nNfj2tqVqDki2W/r+vPEwHIQLnYyA43A4+cCBqEI= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20220324065923epcas1p2f77068faaac78c1d5d75ea1578fb839f~fPun0Z66l0552505525epcas1p2Y; Thu, 24 Mar 2022 06:59:23 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.38.249]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4KPGL14rDzz4x9Q8; Thu, 24 Mar 2022 06:59:21 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id 06.5E.21932.7C61C326; Thu, 24 Mar 2022 15:59:19 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba~fPukhRbUE2719127191epcas1p4f; 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 20220324065919epsmtrp1b9d08e69937ca6837a40816657b753d2~fPukgfiBF2225322253epsmtrp1P; Thu, 24 Mar 2022 06:59:19 +0000 (GMT) X-AuditID: b6c32a38-93fff700000255ac-09-623c16c77173 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 49.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 20220324065919epsmtip2b1517ebb1eed97e0ddc2f6fd2c2abfa1~fPukYUhQY3186931869epsmtip2d; 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 8/8] memblock: print kernel internal size Date: Thu, 24 Mar 2022 16:01:58 +0900 Message-Id: <20220324070158.22969-9-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+NgFnrBKsWRmVeSWpSXmKPExsWy7bCmge5xMZskg08/LCzmrF/DZtG9eSaj Re/7V0wWl3fNYbO4t+Y/q8WR9duZLGY39jFaPF7P7cDhsXPWXXaPTas62Tw2fZrE7nFixm8W j74tqxg9ziw4wu7xeZNcAHtUtk1GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJe Ym6qrZKLT4CuW2YO0FFKCmWJOaVAoYDE4mIlfTubovzSklSFjPziElul1IKUnAKzAr3ixNzi 0rx0vbzUEitDAwMjU6DChOyMm692sBRslKg4e+EVcwPjH6EuRk4OCQETiU0bZrJ0MXJxCAns YJSYPvsrK0hCSOATo8SGTnOIxGdGiXuz77DDdNxde5MZIrGLUWL2hnOsEM4PRonPvx6ygVSx CWhLvF8wCWyUiICdxLfZB8CKmAW6GCUefDjIApIQFrCUWN+8lBHEZhFQlfhy9AAziM0rYCux 7nIbK8Q6eYnVGyDinECDVi45wAgRv8cu0ddtB2G7SLS9vMoMYQtLvDq+BepUKYmX/W1QdrbE 05NHgGo4gOwciYYNshCmvcT7SxYgJrOApsT6XfoQxYoSO3/PBVvELMAn8e5rDytENa9ERxs0 4NQkWp59hbpRRuLvv2dQtofEx61dTJAQmcgo8WHaC9YJjHKzEDYsYGRcxSiWWlCcm55abFhg Ao+v5PzcTYzgJKdlsYNx7tsPeocYmTgYDzFKcDArifDev2ydJMSbklhZlVqUH19UmpNafIjR FBhyE5mlRJPzgWk2ryTe0MTSwMTMyMTC2NLYTEmct3fq6UQhgfTEktTs1NSC1CKYPiYOTqkG JsfoDOFwVVWVivhHqx18E50415VrL1y2+vM27yu/+nmObH1hteaDe6ZLgWXZx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PsLsZlrj9Ef6/Qy5/ivvQ+48NrxZoLF/svaZ0y5rOy4ea3tbY6BdtlJx 6wydqH8RbxY07jn9akLwGSlRq1UFjt+3bbh9VrDiyYO8g4snBvCUywvM6a/KZUn75y+Wyd07 yXjSlSNP50p9lv4tKzr/wGYhSUV7Fn51w13vzlyUUWIpzkg01GIuKk4EAEzqEgu3AgAA X-CMS-MailID: 20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba References: <20220324070158.22969-1-jaewon31.kim@samsung.com> X-Stat-Signature: qjk8njghac8aprpn4atsisi1ru94skf5 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=L3wXxW+6; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf28.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: ED99FC003C X-HE-Tag: 1648105165-841586 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: Kernel internal size information is also useful to compare with other binary. This patch print kernel text, rwdata, rodata, bss, and others. Here's an example. Reserved : 746924 KB .kernel : 137027 KB .text : 28158 KB .rwdata : 3238 KB .rodata : 13468 KB .bss : 12570 KB .etc : 79593 KB .unusable : 609897 KB System : 3447380 KB .common : 3152468 KB .reusable : 294912 KB Total : 4194304 KB ( 4096.00 MB ) Signed-off-by: Jaewon Kim --- include/linux/mm.h | 3 +++ mm/memblock.c | 17 +++++++++++++++++ mm/page_alloc.c | 6 +++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 7a3dd7e617e4..6b874c602b3b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3387,4 +3387,7 @@ madvise_set_anon_name(struct mm_struct *mm, unsigned long start, } #endif +extern unsigned long physpages, codesize, datasize, rosize, bss_size; +extern unsigned long init_code_size, init_data_size; + #endif /* _LINUX_MM_H */ diff --git a/mm/memblock.c b/mm/memblock.c index ef8cec6242d2..083d19b1d061 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2494,6 +2494,13 @@ static int memblock_memsize_show(struct seq_file *m, void *private) struct memsize_rgn_struct *rgn; unsigned long reserved = 0, reusable = 0, total; unsigned long system = totalram_pages() << PAGE_SHIFT; + unsigned long text, rw, ro, bss, etc; + + text = codesize; + rw = datasize; + ro = rosize; + bss = bss_size; + etc = kernel_init_size - text - rw - ro - bss; sort(memsize_rgn, memsize_rgn_count, sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); @@ -2526,6 +2533,16 @@ static int memblock_memsize_show(struct seq_file *m, void *private) DIV_ROUND_UP(kernel_init_size + reserved, SZ_1K)); seq_printf(m, " .kernel : %7lu KB\n", DIV_ROUND_UP(kernel_init_size, SZ_1K)); + seq_printf(m, " .text : %7lu KB\n" + " .rwdata : %7lu KB\n" + " .rodata : %7lu KB\n" + " .bss : %7lu KB\n" + " .etc : %7lu KB\n", + DIV_ROUND_UP(text, SZ_1K), + DIV_ROUND_UP(rw, SZ_1K), + DIV_ROUND_UP(ro, SZ_1K), + DIV_ROUND_UP(bss, SZ_1K), + DIV_ROUND_UP(etc, SZ_1K)); seq_printf(m, " .unusable : %7lu KB\n", DIV_ROUND_UP(reserved, SZ_1K)); seq_printf(m, "System : %7lu KB\n", diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bbbe314850b0..2bf75ba3c66d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8243,11 +8243,11 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char return pages; } +unsigned long physpages, codesize, datasize, rosize, bss_size; +unsigned long init_code_size, init_data_size; + void __init mem_init_print_info(void) { - unsigned long physpages, codesize, datasize, rosize, bss_size; - unsigned long init_code_size, init_data_size; - physpages = get_num_physpages(); codesize = _etext - _stext; datasize = _edata - _sdata;