From patchwork Tue May 21 02:39:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668802 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 0F4F6C25B77 for ; Tue, 21 May 2024 02:40:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7851A6B0096; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BFC16B0088; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF4426B009A; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 884676B0083 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4A468120871 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.22.453683F Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 437374000A for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=nmo4ySHF; spf=pass (imf27.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=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=PxYQXA34qCgfe8GO97dXEa7W4zQKRhqOk+fXrigSuB4=; b=tDnrvO8PVSwjZUeEHDuVELihS5iJFtkU+zija1juTpIU53oI111ThQ9yYsLed9eisJkUL/ xlLtAplGPmQvKIAnaoOGFQCn/hyS9ndBC7p51SpOcpd8GqiWX3Bj4b3+2oczi12CHR1nEU IDHHs8rbifqrHEUx8UIFtS6qmI+vfD8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=3BeaRjM7ibK2Rc/QDAbHzNiqVixAVgD0fHnH3NQPi4iVOqxKo8+KHsvGcpaMTvpNi6RRsj 41nYIwSB4fY3qpu9dYDOJtcpy3UAiB3p+hHX+XyDmTL/il7iF6EkC2q9w3gVyMdelcw+Vm SLg6kf8uHvjGm0k8vJ/oREdkuh6KONQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=nmo4ySHF; spf=pass (imf27.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp0451c317202236c9a5fd49a9a6c7338219~RYKip_o7O1839418394epoutp04o for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240521024010epoutp0451c317202236c9a5fd49a9a6c7338219~RYKip_o7O1839418394epoutp04o DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=PxYQXA34qCgfe8GO97dXEa7W4zQKRhqOk+fXrigSuB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmo4ySHFeHa1k8OqFW4m4SdJ1CA+2GltoaYHpQeo2QbBAq4L8KVMYNLvoXC7Z66OS fG1qVVh8mlTlloumnvo2K/Sqpbu8Mr/90g9qnxUiJqazMaX6opy6shNPGQnpfCQcVr 7KEk5SYFKj2AKbfWKoZM9RNowTP9iDIL6mG/ms2A= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p4c9f71380c8227e6c9d58ad4a55f15698~RYKiEKIk_2938729387epcas1p4a; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.38.240]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4VjzDn3hdbz4x9Q3; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id E2.13.10158.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p4451928c8f5b32bf84082a24c59ca7dd0~RYKhVWO221520715207epcas1p43; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp28aac1566bc1d70947e63cddc2b6abc54~RYKhUfLwN2496224962epsmtrp2h; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a38-b41fa700000027ae-08-664c09890d7b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 45.D3.19234.8890C466; Tue, 21 May 2024 11:40:08 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.104.99]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240521024008epsmtip211bad4828adbe078dc88acc85576b390~RYKhIrXH91232612326epsmtip2E; Tue, 21 May 2024 02:40:08 +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 01/10] memblock: introduce memsize showing reserved memory Date: Tue, 21 May 2024 11:39:48 +0900 Message-Id: <20240521023957.2587005-2-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+NgFupik+LIzCtJLcpLzFFi42LZdlhTT7eT0yfN4MhvcYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzvg19SVzwUnvirn7rrE3MB626WLk5JAQMJF4d+gHaxcjF4eQwA5Gib5P k5ghnE+MEp+m7GWBc84++soO03Lu+VEmiMRORollU6dDVX1mlNj7+i4LSBWbgLbE+wWTWEFs EQE7iW+zD4DZzAKlEm/fnGAGsYUFgiX+PFsKZrMIqErMOL8VzOYVsJdoW/4Oapu8xMxL38Fs TgEHiflTFrND1AhKnJz5hAViprxE89bZYHdLCHxkl7h4/hUrRLOLxPznr6AGCUu8Or4FypaS +PxuLxuEnS9x4eIroHc4gOwaiYUTDSHC9hK7vs5gBQkzC2hKrN+lD7GKT+Ld1x5WiGpeiY42 IYhqNYmWZ1+hlspI/P33DMr2kNi85TI0rCYzSrxYsZRpAqP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Bu2uKZJsSbklhZ lVqUH19UmpNafIhRmoNFSZxXOaczRUggPbEkNTs1tSC1CCbLxMEp1cAkEmxWovrH48vF7S8a 7yr7/6xuCHGYFJwwLbd4H0t2jRSPvVzM99jVjOvnz786kZ9vd+qHP+wONaIXVm58yD/pYLCr VgHD78rg0P/pk7xO6tX6bI43MD6/5eQDr3KFfYr3/4XMLXyxPXVK5EnlyQ1sZvtnmU3r6HO3 9r34ezL7j8lmO480l/WovBfk5XKY7JR34/u3s0ftzspZOE3M+iInxfB0hmVb2PW9/if7L/v8 d9g9yfO0wJcVURc2lIWY79p9hJF1vbHX7zVhqneOSrQzf4sXO/aQOWOntGnSzRWvz02pWHjq 4W7nftuC3ECzni6Ns+eDfdyehVifqbl44GzH9PsXepkVGG6Lci/nye9RYinOSDTUYi4qTgQA Jn5UF98CAAA= X-CMS-MailID: 20240521024009epcas1p4451928c8f5b32bf84082a24c59ca7dd0 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p4451928c8f5b32bf84082a24c59ca7dd0 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Stat-Signature: fd8okrfkjwzsfrg5h9xfydq7a813r8rb X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 437374000A X-HE-Tag: 1716259212-360547 X-HE-Meta: U2FsdGVkX19y/0R+zzSw3Pe6Fqe4ulcN71zPINCr5p8W27N7tLbzMhtWZf4puJ9yZ1UO3MSW/vJ1AYa8UiA2Z6plO6LRtpbNyIIrdaMDIBqKpb95ksP0y6R/1RY1Z6VgM5L5qtnf99LzpDVsFAFx+yY7aHh4ZDty8OXtZM6Mvq08tC6sMnc+yenA9zH9ckNsG8jRK2V24yPCv6otIlbt6vKkxmPXu2tBLLlYZkTLT+br05E81Izf2e7QNkawnyn8GocSaE/Gq5jPjQmteUlON/JCgcCxql1B1iiScYDh5MT1oozFH0WBnOrMhPVDDB6CVcl/Ef30LOMgaeVzQj7CJUBdmXliOp33HjCgxm/uVN43k9o7nNFk7H0wntXjYDkZnLLez/Zu7F8qai/Oo9Cs/ADD4boldJrzdYZsVwEUXticJuzh4UmXuumAu4wH1YuJusnwFs2oF+W08VMGu+foOlNEx4pCS8N5S87X7jdw3zHYQ4f1JZrywVn82nFihWics5Hw3g4VSfWDDSOdl6lEZIQJ9hg6jA1WbH5aWHH+N9AQvfKcg65QWyzp6FIjDHuGf+HT4lFYYI52niWN6QtHjx0gwRWvHgla2RZNYJWGsIWClHD3KRxVGCxKzpkoKpt607Wd2tRwIeyhF7UP7x+08I6LcNhvoOjguhPwo6/4aF3+V93LWcK2ri5/AL9gHlXgsuX+tB7rINk3gaNgh7hKmkxpGs48T5jWQ3SAqcQ7uDQRhBRSn+ThpExugvz5/anwaywqcFgWTOmGiE8VSisSpF3iX9jBmXAOUIBJ7UaNrEFGVauC97lM9oxB/nIa5O0iIADb0qGTlnD+ToHf305bOix+jng9keA5aS4DTXGzerjs9jJf2JrGAnBNxeKa3ySS9CDjetl/x0fzeyhNLHxzZwxiVoc6tY1VSux6HBJWBHQeh3079Uvkl9dx0XOPl1lkdu1ENM8nM6N1warcyWa pjsxAkgg jIns+2DI58UtjXWaImQfCqSBA3k6JpgMIEyU5SRCyKU81cI4hGBZMHyy3xw/GqQk622BWIIhhvfutJCR1Mk2ADziRPbQh9BUCPdUtq1/ohEYvHO5uVIyk00/tBwgvlUOxE6DG3bM0YZdd24Yh+43uxS1q9P3aoVWP41/o 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: 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. There is a case in which the reserved memory region name has @ staring string at the end. That information is not actually needed. Let's remove those string. $ 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 | 3 + drivers/of/of_reserved_mem.c | 9 ++- include/linux/memblock.h | 9 +++ kernel/dma/contiguous.c | 2 + mm/Kconfig | 16 +++++ mm/memblock.c | 120 +++++++++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 3 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index a8a04f27915b..605c7f471908 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -502,6 +502,8 @@ static void __init fdt_reserve_elfcorehdr(void) } memblock_reserve(elfcorehdr_addr, elfcorehdr_size); + memblock_memsize_record("elfcorehdr", elfcorehdr_addr, elfcorehdr_size, + false, false); pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n", elfcorehdr_size >> 10, elfcorehdr_addr); @@ -531,6 +533,7 @@ void __init early_init_fdt_scan_reserved_mem(void) if (!size) break; memblock_reserve(base, size); + memblock_memsize_record("memreserve", base, size, false, false); } fdt_init_reserved_mem(); diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 46e1c3fbc769..ece678e07304 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -438,9 +438,10 @@ void __init fdt_init_reserved_mem(void) struct reserved_mem *rmem = &reserved_mem[i]; unsigned long node = rmem->fdt_node; 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; if (rmem->size == 0) err = __reserved_mem_alloc_size(node, rmem->name, @@ -457,14 +458,16 @@ void __init fdt_init_reserved_mem(void) rmem->size); } else { phys_addr_t end = rmem->base + rmem->size - 1; - bool reusable = - (of_get_flat_dt_prop(node, "reusable", NULL)) != NULL; pr_info("%pa..%pa (%lu KiB) %s %s %s\n", &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), nomap ? "nomap" : "map", reusable ? "reusable" : "non-reusable", rmem->name ? rmem->name : "unknown"); + + memblock_memsize_record(rmem->name, rmem->base, + rmem->size, nomap, + reusable); } } } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index e2082240586d..9ccba9bb20cb 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -613,5 +613,14 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) { } static inline void memtest_report_meminfo(struct seq_file *m) { } #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 055da410ac71..437c85878280 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -286,6 +286,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 b4cb45255a54..7fd25088b9b8 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -476,6 +476,22 @@ config HAVE_GUP_FAST depends on MMU bool +config MAX_MEMBLOCK_MEMSIZE + int "Maximum number of tracking regions" + depends on MEMBLOCK_MEMSIZE + default 100 + range 0 200 + help + This number sets maximum number of tracking regions. If this is set to + 0, nothing will be saved. + +config MEMBLOCK_MEMSIZE + bool "memblock based reserved memory profiling" + default n + help + This patch introduce a 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 d09136e040d3..f05e7df2f8e1 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -19,6 +19,7 @@ #include #include +#include #include "internal.h" @@ -2025,6 +2026,66 @@ static int __init early_memblock(char *p) } early_param("memblock", early_memblock); +#ifdef CONFIG_MEMBLOCK_MEMSIZE + +#define NAME_SIZE 100 +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 */ +}; + +static struct memsize_rgn_struct memsize_rgn[CONFIG_MAX_MEMBLOCK_MEMSIZE] __initdata_memblock; +static int memsize_rgn_count __initdata_memblock; + +static void __init_memblock memsize_get_valid_name(char *valid_name, const char *name) +{ + char *head, *tail, *found; + int val_size; + + head = (char *)name; + tail = head + strlen(name); + + /* get tail position after valid char */ + found = strchr(name, '@'); + if (found) + tail = found; + + val_size = tail - head; + if (val_size > NAME_SIZE - 1) + val_size = NAME_SIZE - 1; + strscpy(valid_name, head, val_size); + valid_name[val_size] = '\0'; +} + +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 == CONFIG_MAX_MEMBLOCK_MEMSIZE) { + 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) + strscpy(rgn->name, "unknown", sizeof(rgn->name)); + else + memsize_get_valid_name(rgn->name, name); + 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; @@ -2289,6 +2350,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%pK-0x%pK 0x%08lx ( %7lu KB ) %s %s %s\n", + (void *)base, (void *)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_puts(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); @@ -2301,6 +2417,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 Tue May 21 02:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668803 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 9613CC25B77 for ; Tue, 21 May 2024 02:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB0FB6B0088; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 620686B009D; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02B856B0083; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 90B996B0085 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 36501A0FFD for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.25.771B4A7 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 3CE2E120007 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=AIUR1WPc; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=zfdbqoJ3Tmb1eSzL6LV7bRgLUYSKWEgUd90tmZag82SMsAdQBmJIZAKm4tiTLMiZ1tb0zd TBn++uPC0wybvynGHUk6Y8SGLAIv/2sD6siVghP4+fWc1G+oIWYS9cLYjokVDveb9oxVLT fZOcfEC60H8RQ0g6z+wz5IgA95Mp5RU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=AIUR1WPc; spf=pass (imf29.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=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=3CfHcPoy4LZXqF1JfuCe7exgO9FOdW12+9aW417X+QU=; b=QrL6IY9p0bCNzh/+7T4Y8ll32gcTy4sq5isW6iVIwHSY4PCjk2qESL4pNmuyt8Y1qYZumy P+XGOcnaPFjKHyyJphT3gUmi/KtWfXXKoh1RdQZCp4tU6S1QaphqX/OieqLhPALDy4FVO5 UYrGQT3E1+94YO0c8rtgsBg9aijHJ0M= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp048b54b35e8dd6786675a0a69b3c691030~RYKifkVgL1838018380epoutp04b for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240521024010epoutp048b54b35e8dd6786675a0a69b3c691030~RYKifkVgL1838018380epoutp04b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=3CfHcPoy4LZXqF1JfuCe7exgO9FOdW12+9aW417X+QU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIUR1WPc/vUs4bOffPOm5oSZU1OsaPGBqgVt0bmib7J75/fHxavdA4WMIfdmNzeDu p6B03zN9aWEcmwz1BcfFcG16UOfTtY6IHwFvCh94Vl2AIn84zcE36rL4dUWuRvQlIO QDzQrOEQlaRYgKxq/oo1wTISnF7WUCavpNnZtCts= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p35a6821f1ae02a131f8d71e39773e8fd3~RYKiAz8Bn0314503145epcas1p3d; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.242]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn39p7z4x9QB; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id AE.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p3e80e90863a453053d5aac901ef644070~RYKhVkSAh0309203092epcas1p3t; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp276a000fb3675b0aa18a6053708976075~RYKhU_TN-2496124961epsmtrp2o; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-053ff700000025be-a7-664c09892ffc Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 55.D3.19234.8890C466; 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 20240521024008epsmtip279bc42a8e8f3048a6ffbd81990fd292b~RYKhMbR9s1233912339epsmtip2B; Tue, 21 May 2024 02:40:08 +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 02/10] memblock: detect hidden memory hole size Date: Tue, 21 May 2024 11:39:49 +0900 Message-Id: <20240521023957.2587005-3-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+LIzCtJLcpLzFFi42LZdlhTX7eT0yfN4PMccYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzph37hZTwV7Zin8vt7A2MJ4X72Lk4JAQMJFovOfexcjFISSwg1Fi28y5 zBDOJ0aJvtd3mOCci3PWMHYxcoJ19G88xAaR2MkoMftoM5TzmVHi+eszYFVsAtoS7xdMYgWx RQTsJL7NPgBmMwuUSrx9c4IZxBYWcJO492sumM0ioCpx9PRisBpeAXuJ5zsWsEBsk5eYeek7 O4jNKeAgMX/KYnaIGkGJkzOfsEDMlJdo3job7G4JgY/sErvm9bFBNLtIzNqyggnCFpZ4dXwL O4QtJfH53V6omnyJCxdfMUECo0Zi4URDiLC9xK6vM1hBwsw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omlpQ nJuem1xgqFecmFtcmpeul5yfu4kRHOBaQTsYl63/q3eIkYmD8RCjBAezkgjvpi2eaUK8KYmV ValF+fFFpTmpxYcYpTlYlMR5lXM6U4QE0hNLUrNTUwtSi2CyTBycUg1MUze+fncvd/YxZe/y 889sLr9h5AxM91gpzrL5+fVy54UZ6w21rddsDVyl9VT/Ua7juqtcRUKCN7OYb3Itf9qnHP7u 8ddr4TvDd/+cwDNnw3EtqznbMnZX7j8lYnJh+ZzGddq7HR/9zODwq/R61bGL43DyTsOyvayb NO+pJrOZNWRIvapQ+6V+TZpNK9OhbXutT0pUV/vL9SIfWYtmnDOQvOM5yeeuin6IV7t/64zW DdejRZbG3RB93Dr/7McNe9+Wyah5PK4IfhXeKzcp+sh075QIw4yHR2bEm9+ZlC20bqfOv3C3 CvnkCHse782tWs0uQsHcnBXrH5z7oCrsvJRLMKD3glOyf2XAGQHTeU1KLMUZiYZazEXFiQBz NwUD3wIAAA== X-CMS-MailID: 20240521024009epcas1p3e80e90863a453053d5aac901ef644070 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p3e80e90863a453053d5aac901ef644070 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspamd-Queue-Id: 3CE2E120007 X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 31s9jtodkatuao8yiod6az5z56r3tc6f X-HE-Tag: 1716259212-667004 X-HE-Meta: U2FsdGVkX19kp3M8QzqBaSk4WGN7ly0qVe13diDTozpbQOEA2pI1BOx5lm1+ykCNsyhGRwicn2F9nQLaPJMcTvv/+wOWZWfPCkcecgOzdKN6GjCN2KMJR17b5YkC/XGyQrPSSf4HCyxG3N3mp1+wNvbKYRhFNDoBS7HJDb5RsDsdZczvnpq7yzxKvRuAXkB6TwsEC/1klx3qcTIlim9Da4hCp2qKyFk4/0ajMFvoLuWMbZ9VUymO51yDUyJqI+ja6Q+uBSZ+dt7JyVselepW0xshfCKVEGhs7Zs8QQbN6kHKRhVqza1DHmlrl5cKGYgHB0BXpBajuKMlJIyDS/fg0eO9l+JxpD6ZkAPVpfSiDuiEl47xvCCKGL2cr7hFYBhTtShw+A7+hetd3qTNHWn1HdLHP0b8Mukvcpmvs6FAdi3pmnqLotDKoymBr96Hn4LvENgi9PLMm+SM2cz6b2Ywnkhjn/v6lx7qXATXifywQOO8yBUiCivlJwnC05f1OS2dZKVaCCJsqSQwWo+i1HH9qRqCPdLgiS4jLrZIDkQm3krWlP3EO+s8zEMWMyQAjtl1zQ84zqIt4uAdW3UH+lo6NwkKhkYnZnC/gV6f3PFDU2k0SagT1A2ARezKS6mytysKoq62ImxcFULtim3515uwoPNTsERMkXi1A1ZrXOtNL+iNXKUFLXI3DwNxNuXRd9gn8ta7HDlsiCyOp+nDKRAuB4ZffQIoAaskpAyVRnUpPni3FcGL1YZkWuBxvEaBCcmJJ1hxVEzD3YwxykL8R5RoNCVhJRMBT8zA5FSLoDQHoekQTV0ciO6YCuLm7xO2ldwWP5yPp+uxhkjsX1wzowyqZfuAAxzg2yFRtPz1tY8/+raCSgIYGpQ9+hlzDTCcrFqQUWTbUSJlK9eTZdW1zY/3bwFe9o5wiiBBFzNXAPj1Q4tXJQvxBNF6FU8S9MFXwVsWYkuSJTovXdgMbdQIwlC znrPL0m3 XDR0F73uwnUrsb+ER5rqRKwMOGKzkxqD3yxViZ/lNFC1KqjX3eSPkpCDRvhNm71lflCoksWsXid5U1iSrWif/uwZQLNv+MFbbjp1w0px2S4S0sPLXBDpX8YNMsS6MFTgTYcYhe9nx5jvP77yTUTOMPfFN/1KckDP8zm07 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: 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 605c7f471908..da82e5afed01 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1194,6 +1194,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 9ccba9bb20cb..049313871059 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -617,10 +617,12 @@ static inline void memtest_report_meminfo(struct seq_file *m) { } 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 f05e7df2f8e1..5204ee71ae29 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2084,6 +2084,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 Tue May 21 02:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668808 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 71C6EC25B77 for ; Tue, 21 May 2024 02:40:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6024A6B0099; Mon, 20 May 2024 22:40:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BA436B009A; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BB6C6B0083; Mon, 20 May 2024 22:40:17 -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 164546B008A for ; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD971140B57 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.28.06FF18C Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf30.hostedemail.com (Postfix) with ESMTP id 092F480002 for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=GmWAPwUP; 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; dmarc=pass (policy=none) header.from=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=nc9ytWVtzu00a7dgwLwPEFskmN2vz5dkqC+Zm4IulfA=; b=vASfV4y3aNxHTU7vykjoQsRjXGhBCG+IINES2+p+RLyo/IHFTqx16cppFVO6GlCFGP6ho2 ZaiWbdo1PwAxcMUrntBJOPzOzDjm31bJZS3M8hK9JgXsDTkpvJ+lgXWbEy5d6jujz1lPRi S/SudurDupbxE45FQp6THP1IYM1wzHg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=GmWAPwUP; 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; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=UpRADwbnCimcZBsPEeIUzhD3wzUUPXkPdBmVlLEDRyjZk1PDVAEoco7dkaLUPaNzUr+wvm rtJ97EZjIkOnIzkE61M+a1IB073lFVIurhWemJyZtajJNvMQ+zZDIRe1Eau6aEmOtYrslw fa3J7aRw7YwLeOyuRGPbvPmLAo6B4ZE= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp02ca1e3adc80fe4c0a51aa3c069ad9784d~RYKiWilNw0459104591epoutp021 for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp02ca1e3adc80fe4c0a51aa3c069ad9784d~RYKiWilNw0459104591epoutp021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=nc9ytWVtzu00a7dgwLwPEFskmN2vz5dkqC+Zm4IulfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmWAPwUPJUumyIommwOd368ltzs6tEpcbknX9PM8XQAOHVWnJkt6n3/awC1sZxKBa uGIaHt3eL9jlpIWjc6TSETkoLd7hclQ6Dg8YZGcjFIon6PKX0EQE4AFBJAVEKG5jiw ULJWvMF7TcBLXhF/SoCUZfbXqqCmXcehj5Ly0Mgk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p4ae0afa00bd066e0581c51603cd14c1c5~RYKiDy1mA1450914509epcas1p4D; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.250]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4VjzDn3Btwz4x9Q0; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id BE.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb~RYKhZLuN42349123491epcas1p1a; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp2ab32c1df17e1b63fac42592843b39454~RYKhYk-MV2496124961epsmtrp2p; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-2b3fa700000025be-a8-664c0989734b Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id E5.D3.19234.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 20240521024009epsmtip23fed4a67c5d9cdc27984091a265bcdeb~RYKhPg7O11233912339epsmtip2C; 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 03/10] memblock: handle overlapped reserved memory region Date: Tue, 21 May 2024 11:39:50 +0900 Message-Id: <20240521023957.2587005-4-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+NgFmpmk+LIzCtJLcpLzFFi42LZdlhTV7eT0yfN4HmvhMWc9WvYLLo3z2S0 6H3/isni8q45bBb31vxntTiyfjuTxezGPkYHdo+ds+6ye2xa1cnmsenTJHaPEzN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cOm+f0ueYcrODTUtOP3y7 4p71x03tqvN63yixFGckGmoxFxUnAgAmduORFgQAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsWy7bCSvG4np0+aweSpbBZz1q9hs+jePJPR ovf9KyaLy7vmsFncW/Of1eLI+u1MFrMb+xgd2D12zrrL7rFpVSebx6ZPk9g9Tsz4zeLRt2UV o8eZBUfYPT5vkgtgj+KySUnNySxLLdK3S+DKeDDnC1NBr0LFi21hDYzPJbsYOTkkBEwkJjXf Ze9i5OIQEtjOKDFh8Xc2iISMxJvzT1m6GDmAbGGJw4eLIWo+MkoseXGcBaSGTUBb4v2CSawg toiAk8SGK6vB4swClRL/bt8CiwsLBEiceXaMEcRmEVCV+L7xPhOIzStgL3G19y7ULnmJmZe+ s4PYnAIOEvOnLAazhYBqzlw6zwpRLyhxcuYTqPnyEs1bZzNPYBSYhSQ1C0lqASPTKkbR1ILi 3PTc5AJDveLE3OLSvHS95PzcTYzg8NYK2sG4bP1fvUOMTByMhxglOJiVRHg3bfFME+JNSays Si3Kjy8qzUktPsQozcGiJM6rnNOZIiSQnliSmp2aWpBaBJNl4uCUamAKePXBZLr5XaOJP65O DdVXCF/E0SCz/NK9Jf4Oxxmu3p5cJvUy6C2n4+G8qnlXWttbJm3cGsUsUVaTYbDwqZ5Q+qSc OSLzWOqi5PPyivt+e9op3dyn9Fi/ek/z19cmVtM+ZK5pX83Gruev3mArt9yp9lFq+PzXzwyL TxnfXfpWTe7t5ofFdue/n5zxyOftyuK6NzyTXU+sd0p6tnt1qcrnBXOFlnBHHznIvGKxnrq9 Hpf4lb6nKaZfSyLFppVN+X09nlc9YcbBp43HXG9u0og2DGbleNDHZZ9/90vtGc9/OXZ2bLXq zE38G5n3cakrc4lEblo549YGl99KewJ/um/sZz2lecen5qaT+LWVNvFKLMUZiYZazEXFiQA4 nBKK3gIAAA== X-CMS-MailID: 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p152671a613e86fa83d840962ee3db50fb References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Stat-Signature: sxsgrxfkg6xxufsaabd37789zzew3psr X-Rspamd-Queue-Id: 092F480002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716259212-848889 X-HE-Meta: U2FsdGVkX19r0pnSiCWHRP3+fJ6uxHPvNdUqiNsj4QyuLxrkeeu7onHuU7cXU1+mEOC4FgdkktBLWnUHywb7ap/lHdRWwyAQnY+WrwfBBs/Ke2WLs66bPIsjuqjnhVWgzAxVtmtCDw14mwweGRBhF5XXdog0fkNEmUXGO9gYT1B1XKhomXkSEuwi5XgOHcVsQq96zZadDIihRt3u8XQ//TNr3B9Z0xnfX8hK/hxRCxpUV6KSoXjtOVImyJ8XH0MhgJ0jcLGkT5gzbT0Bum0LBgwKrpGd7US5kK1e7c5NpWMxxAYlaQmU0myl+l2AopQqdEdxc5tdCYbk6MOT+s3enofNMsz/Qd8nQjP8v2xEmXtwUnTa539NVvTZ17SDNcAXT2GEwegEmTT67HpmObpKKAUulLpj0ubNU/y8duXlq6K6peYcMBGWH1XS87ylV+FkwT58SG46ZK+2VifS4qs6QUyTWCosIWF82T1m/V1uZWC5fL1gNK/ZrmYvLhMbKU73h3j5ZXEXoiyIEllSwPvxONoDZG/55KHUstLETnxlcB3mmBpWUC1ZbrjD0YQW6G1KLma+TTtDct43HCbJnECKISReCr0s0B/WRAngSJwpeET3R9W31oeFOr2C4v9/tJK36VJhAbWEE7E/aZyb+zkBZ9CXoWvw77cG3JaA6eqZ861bioI4kPx4+F12PtUI4BFd9Gr/H7hI1Xd6kPjEaxwqm5PQT/1hWF88LB10o1mJlCB0+Hhbx0tfrtazycQAA25i7/yAaM5q+icNdor3MCRidGgLuKAijg358iRgq5vqPA9Zbnlr1J5yvP7z1NAXED43cpLJUOyqhqQjf7be3qufvBU9OwUbd0/TOtq3AfgjdLaY5UScLJUOWoFdqW/06GzjWf9v3Ly7cmbzm51FYPDfgiwmV2jL8IUxMb2S1kvbHQqgqW4mqje+Y9dxWvmb2CFsEkqVNnH0wL6/N8+XBjR dJMz+J9z 3N5X9TDHa9f5k4phe/DAZccPWSUza6uQbVyfq/Al6KbgMtzIBDYSyZBfPxHZxKvtipdcidw2Blje8mjADiBa6RJBXcqvnY+O3HXqp48Vo4UyHOalaHOnVslIAc02KPM2pzPHq40drp1RZ0TtA9/TXLvmjDMUNb1d+l/XR 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: 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 | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 5204ee71ae29..4a0506e14025 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2060,6 +2060,73 @@ static void __init_memblock memsize_get_valid_name(char *valid_name, const char valid_name[val_size] = '\0'; } +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) { + memsize_get_valid_name(rmem_rgn->name, name); + 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; + memsize_get_valid_name(new_rgn->name, name); + + 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; + strscpy(new_rgn->name, "unknown", sizeof(new_rgn->name)); + 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) { @@ -2070,7 +2137,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 Tue May 21 02:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668807 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 34BB7C25B77 for ; Tue, 21 May 2024 02:40:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42B406B0093; Mon, 20 May 2024 22:40:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E37686B009C; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70A906B009A; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3121D6B0099 for ; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EE7CCA0FFD for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.14.F4EB842 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by imf09.hostedemail.com (Postfix) with ESMTP id 2D513140006 for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="eu3E5L/p"; spf=pass (imf09.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 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=zEBuyZNhF/CL5lPcNah+oRHllxv4MjfsSuOU5w+v1uI=; b=PUysP+WIP33pSh1zsPcgJiqAdBJyZ9QdpMJYevBDHrpMl++6WBzqonDG/y6mfq+prhns9b BTnf6Fi9aNeI7PWTGAn+S0lVNs3gh1sb+4VjuMEAsT1UKQaxQVoy5brC2l4O4oRi5uyiWO /Yf4EeqcVDk9lBGMDm84od/CUQTOpAI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=H46KBqQlpk9Bl9iXP4vwh+JDUuQj4F6Gz6uSVoek+N8nZKY2n+vezI8IPPRg8mIF7zvkkg NiGO4/Q3ZsyGoNd23KMptE1TJVDDkePel3MdZtsoTFKyrMpFjhntFDRAl/4bAYrrg7qXhg msW7I3uKlDWmJglCGS1tonqPjwE9Q5s= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="eu3E5L/p"; spf=pass (imf09.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 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp012c418eed776d999d0fd9ecba9e9406b9~RYKiWJ9WL1194311943epoutp012 for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20240521024010epoutp012c418eed776d999d0fd9ecba9e9406b9~RYKiWJ9WL1194311943epoutp012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=zEBuyZNhF/CL5lPcNah+oRHllxv4MjfsSuOU5w+v1uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eu3E5L/pUZoUnW3GZHjjN+T4eiYopRIR47Dc2o2Tc38FgW+ULbYlL8zoZt6D14DiD ixQU3fgmJcYFOzyU8kUKleXa8ZPICIXBDMBLq8fHLrhJE4LRN5CQhvIiJ03umcSfvg l5GQOBJ19AK1N9Mt4RmYFd4oCRSNLF+BPD2TWtnA= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p28bd3d0438a305494443a92e585d320ba~RYKiHHtqm0671506715epcas1p21; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.36.225]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn4FC1z4x9QJ; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 8A.40.09663.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p3440f857e3b31b319c270e2d658379383~RYKhd4Ike1250112501epcas1p3y; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp19f0c8de878deda13b3a4e6889ec4b12f~RYKhdLe4_2362723627epsmtrp1I; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a37-557fa700000025bf-5d-664c09893051 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0A.54.08390.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 20240521024009epsmtip2409720cc711bae36955b9fba12d29dc8~RYKhSinmk1232612326epsmtip2G; 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 04/10] memblock: take a region intersecting an unknown region Date: Tue, 21 May 2024 11:39:51 +0900 Message-Id: <20240521023957.2587005-5-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+NgFmplk+LIzCtJLcpLzFFi42LZdljTQLeT0yfN4PJ6RYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzmg79JSp4KpQxc2Tf9gaGPfzdTFycEgImEjcW+7bxcjFISSwg1Gi98ts dgjnE6PE4zsTgRxOIOcbo8Syfc4gNkjD1CePmSHiexkljh1JgrA/M0rM7U0GsdkEtCXeL5jE CmKLCNhJfJt9AMxmFiiVePvmBFivsECYxLxHX8HiLAKqEmeOTgazeQXsJQ4dfM4CsUteYual 72A3cAo4SMyfspgdokZQ4uTMJywQM+UlmrfOZgY5WkLgJ7vE3J/fmCGaXSTeXjzBBGELS7w6 voUdwpaSeNnfBmXnS1y4+IoJEhI1EgsnGkKE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Q4OfMJ1Hx5ieats5knMArMQpKahSS1gJFpFaNkakFx bnpusWGBUV5quV5xYm5xaV66XnJ+7iZGcKBrae1g3LPqg94hRiYOxkOMEhzMSiK8m7Z4pgnx piRWVqUW5ccXleakFh9ilOZgURLn/fa6N0VIID2xJDU7NbUgtQgmy8TBKdXAZPey0vLNyRfl wtu27XTe/tRb8bevprzSzVoblosLrR+WTXBrZZ03geFoEefF6FuH1pl9VZKfdPSQ/xY2jo/r I+cmRrZM9RNS3iH/d/1l68LHe9ZktJ/eonhNZ+lzrttL75kq/xTc9ND8xuaM4EUC0sXP5gTu Krl5TLJ3/4c3jLut/lnf2+VvPE/g7OfITcudNjz9qpf2b/3hhMxAidW77+v3Fjy038DyJLGp 34TvXxjDmxPszCJ3Cr96cG6sarAQb5IX39y9Le4z56SJK5WsH3/eopJ0e34gD9sDWbsF+x55 95yZsVpy9/bHp29vWz7BtK/l75qOgxPsNh0zeHMjYHds56epH35zXP7wVWWK6rw2JZbijERD Leai4kQAvBDQM+MCAAA= X-CMS-MailID: 20240521024009epcas1p3440f857e3b31b319c270e2d658379383 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p3440f857e3b31b319c270e2d658379383 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Stat-Signature: ppm46qzgrdazyh5cafwgc8ni5ebs6wda X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2D513140006 X-HE-Tag: 1716259212-841765 X-HE-Meta: U2FsdGVkX1+PA5PqVhkP0N2hQrAFnVcXDzUyI6WYQt1WPwR9zCeig4N1PBjUAiAkHv4JVTPggT54Ham7mTLWH5hCylZcHO9uS/HTpsH6ARzJf3SKJHR0KHuilN01T7fgIjvntgz2mH6eGBfNP05y50HAH+7TbsNXLIHEDy4eGQWNYUgLWKh3uYoNc2yFtBQvwIiDpgbZeGDY1AWiJBHh5S37fbJhM/xdqPBwVSlB3N+097PmU1n76YrLG4cj7lFYvmCr2tYE8Ju+eZqg2xCCo1hkPx08ta2imt/ob0+gNk9v2kXl/Rk5Nf+6boBibJBNO4R43UnWeo5/ljhgRZck3qss4HZRIJiN5LotQYGSeG6buArxw0t2HcyqnfPX5xp1VJjuLB+SLlnjT6qwYTBfqFxh61YgeG9ke6AoQ82qpBM2MTBUx/z5XOb+ZQDUCT5zxr4QK+dbrJiHuKmWTgpT+o/E+jZxAMXBRd7fGWkD3iyhYW8otyB3fx539bi7rMWV9hMiHn1e4+dC5Oisn8GZ+HP8bqkTMEcQm/BkTqH8YyOAsXO+n0J0NYBPTEQOzeYlC6WFYmJO571bWNayxEz1Ec3HPH/0VEQ4w2ObFDx/xSP/1yWplnv3MzAI2Be21QbzWJd5HXQ/dGzFcztINrncAD7wXesIGXv+U+IlEZdEpu+CsU0tm4k43DWhsiOpE/bymr+NkK5+UdDA2NQiukwfYtOiSl5whpU6zCH1E0xg7f7nHItDVculO2iUW0/AqB5n4ocZKdJBrZ+72MDvN1qnunAHSuy3K+P+mn7tku37VVeutpoiWdHQ6Jb7Dc+vJApngwNfhp7UMbCH+0X6BfGJWiP1iMKVNQIJgBrg6eNZ3mph+X/aWRrsdCvXtE/ZAItZrEoJSys2nifFfUq6YKD/t2b9+bUEVmHQlkUPZ0S23H5lMzZ1Ys7oREj4rvlvn6Udn2Ip1r0Nyz9aMXi7/hH DKkJvj4c fPK+7aRoB4CgIoC+lWbPT3UyhFt4D0yN3iNsgryidMn99xSjVufjLbLqF8b5J6BCynaLT2OKYkw99B5RZRtSMvZGJBQYOD1zr8Pfz5lOwTx32vSqHDB9aAWiQ7kqWneGxZ6Et0m2Dr7h7sJQGd3DIEHPpsbP3da5FqGJG 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 is case where reserved regions overlapped with already checked as unknown regions. To get more information of the name, size, so far we allowed only regions which are exactly matching with or located within the unknown region. For a region intersecting an unknown region, we did not take and just showed that duplicated information. So total size was not perfect. To fix this, let's allow to take even the intersecting region. Signed-off-by: Jaewon Kim --- mm/memblock.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 4a0506e14025..9b68ddc4af5e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2081,20 +2081,54 @@ static bool __init_memblock memsize_update_nomap_region(const char *name, phys_a for (i = 0; i < memsize_rgn_count; i++) { rmem_rgn = &memsize_rgn[i]; + /* skip either !nomap, !unknown, !overlap */ if (!rmem_rgn->nomap) continue; if (strcmp(rmem_rgn->name, "unknown")) continue; - if (base < rmem_rgn->base) + if (base + size <= rmem_rgn->base) continue; - if (base + size > rmem_rgn->base + rmem_rgn->size) + if (base >= rmem_rgn->base + rmem_rgn->size) continue; + /* exactly same */ if (base == rmem_rgn->base && size == rmem_rgn->size) { memsize_get_valid_name(rmem_rgn->name, name); return true; } + /* bigger */ + if (base <= rmem_rgn->base && + base + size >= rmem_rgn->base + rmem_rgn->size) { + memsize_get_valid_name(rmem_rgn->name, name); + rmem_rgn->base = base; + rmem_rgn->size = size; + return true; + } + + /* intersect */ + if (base < rmem_rgn->base || + base + size > rmem_rgn->base + rmem_rgn->size) { + 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; + memsize_get_valid_name(new_rgn->name, name); + + if (base < rmem_rgn->base) { + rmem_rgn->size -= base + size - rmem_rgn->base; + rmem_rgn->base = base + size; + } else { + rmem_rgn->size -= rmem_rgn->base + + rmem_rgn->size - base; + } + return true; + } + + /* smaller */ new_rgn = memsize_get_new_rgn(); if (!new_rgn) return true; From patchwork Tue May 21 02:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668805 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 418EFC25B77 for ; Tue, 21 May 2024 02:40:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F06ED6B008A; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92C266B009B; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EAEF6B0093; Mon, 20 May 2024 22:40:17 -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 D6DBA6B0093 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 98E0F120FC7 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.04.5E4349C Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf27.hostedemail.com (Postfix) with ESMTP id B868E40013 for ; Tue, 21 May 2024 02:40:13 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ioKZ5v8+; spf=pass (imf27.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716259214; 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=3kKY9p5rX9c1bN2ssSLpLQuO2G9ldZSHB4ioCNHoa30=; b=bLIhHEvqH2jg15J+6lXtw5F/ZehZCiIq3plNfvRFEmLCtvZRrxW9emaGJ/NifvVy1M+ftC oyzUP4QIyWON0glKOrWWZu/Fpd9n0yPfXNXYhIgNOtLCaxZam7y44il0mPPrbMLHXD6zrs Hgow6CHjIv8J0joRkWp4v9g0Fcnz1O8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=ioKZ5v8+; spf=pass (imf27.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259214; a=rsa-sha256; cv=none; b=4kt+QZcqRYkbTLKDSsl/FzmhVm1eynYS794YERFRsbBP1asvcQhUHudnmay/NEdtBCCxlo mAZtPh0Bi9oaGeCppklk4UwwhslnqJSPN2YHrrOQEBTeqmedgHd4AfcpQPaAbAr8u0i2OL QggY+UBE/iEyf2dRTFo/J9eAee6hA78= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp02d97f4018e0d3cd0b41cdd8c86a2ca6e7~RYKizHyaC0406504065epoutp02c for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp02d97f4018e0d3cd0b41cdd8c86a2ca6e7~RYKizHyaC0406504065epoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=3kKY9p5rX9c1bN2ssSLpLQuO2G9ldZSHB4ioCNHoa30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ioKZ5v8+EiGjygozsgC5p+pkEgQD7JtEhkp4fN0M3y/s/D/L3qEG5YWaLeDKQDydR P9usUwGGq173W1LY+Ivw3z2D5R6Y4x9wCwreahs5irq2gx+TifrgR5xHU14xuEg8R7 AJO7t7DQCYACPiabfKp742Xo0JJVZe3pYTeXjMnM= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epcas1p1cf3280cf33e9d6057ea5c4b3f7d01c0b~RYKiHzV952332223322epcas1p1j; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.224]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn48LTz4x9Q0; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id AF.4F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077~RYKhfz-vs0129801298epcas1p2n; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp22b86ded1b29f1daf8837089c371f91f3~RYKhfM07S2496124961epsmtrp2q; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-8da83a80000025be-a9-664c0989ddba Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id AE.EA.09238.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 20240521024009epsmtip24e01e0bac44534b743d22ec2b6b08031~RYKhVkH0A1233912339epsmtip2D; 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 05/10] memblock: track memblock changed at early param Date: Tue, 21 May 2024 11:39:52 +0900 Message-Id: <20240521023957.2587005-6-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+NgFmpnk+LIzCtJLcpLzFFi42LZdlhTX7eT0yfN4PBpOYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIztg4+zdrwX6rir69G1kbGG/qdTFycEgImEgcXGrSxcjFISSwg1HiwPEJ jBDOJ0aJbztXs0A43xglmiYfZe9i5ATruPV6OxtEYi+jxPXj06CqPjNKnNv6ngWkik1AW+L9 gkmsILaIgJ3Et9kHwGxmgVKJt29OMIPYwgL+Es1b1rGB2CwCqhLLPk4D6+UVsJdoO7SQEWKb vMTMS9/BNnMKOEjMn7KYHaJGUOLkzCcsEDPlJZq3zmaGqP/KLnFkfRqE7SKxc84hFghbWOLV 8S1QH0hJfH63lw3Czpe4cPEVEyQsaiQWTjSECNtL7Po6gxUkzCygKbF+lz7EJj6Jd197WCGq eSU62oQgqtUkWp59ZYWwZST+/nsGZXtIXL/eDLZISGAyo8S/BZwTGOVnIbl/FpL7ZyEsW8DI vIpRLLWgODc9tdiwwBAepc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+BCjNAeLkjiv4YzZKUIC6YklqdmpqQWpRTBZJg5OqQYmfb3DTy/di7V6 m6a1UGd7vcG8afulHjjKcyZZrFc2vGsZeYJv2oW8LlYdCanDNVmrTrObNtge/5R48PGXVlmh XjfZy54cUS4P55xfs+qgzbk25WPfqw5O+3kja7ZR1eWzEZMPse/Kr9t+pGmh0M+tk9W+fuHP idXY0SzSpLbG23FG7MyDh84FK1/Z4hzhoOLQV5Rr1rxE8egR64gf/NPZ8+SLmoUltzat9bz7 YuU0G97bUa+nq2/P4Jd7t2Tp5sod8y8lCiVdOXZ69/YLS78t0vSsktedHKE2WW5i1s3816nb A+e7rIj+F7Jc1ql4yYf6r99vnuXY56d6o20L1xMRnrt6kWVhwkX3BXjVUnnPKLEUZyQaajEX FScCALkqXMfjAgAA X-CMS-MailID: 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p20ddcabed3d037904a9c651d27f82c077 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B868E40013 X-Stat-Signature: rk57bbmxcsdr9czcxpfxea7iczog3jrp X-HE-Tag: 1716259213-259463 X-HE-Meta: U2FsdGVkX19m+pc29ge5fxamtTsGQRLnRSU1g6951S0TkYmHWTiw41nT8ETrpnGwsiYGarlo7G37+hZFTM8ms9pBHDFbkuWECyZaKtdoIIuPE7zSOd/x2aBZrdl7zFx8gTKC08dhPh3zxJURzf7rG253Ek3eUh40e9cFdvXGyhOWBRuoiartZ+ILHAndi4xh51Uz5MOjUKCK5/xn6lkIfcT+ttJ+y2AJNbQjlhS/QDRxH+J2c3h601iGjL4hvlhpJxvpY1nFaK7bp1oOrARucBivOJl7Fm3Qm0ZhmaTaZQ1RL0yyeKj/pz+U3tcyey76Va4s3b0Y/djlCytKnDhNNFwD7Uu65ZNZqwtN2oGstFMunIxPPeu4fDNH+4ubq1rFa8oAzp/ytN+qU2iqxPYM/dxDvf1aP3Nbc+5lzwjulO1hzlawAq7poKh/S3RPisQbbxkGn1O8dA5cFDWck9ZGl/LkIvrzfJfW8yxOpCzJQYdbWSuUxgquaU98yA9nfcPPc39t5qv7o52kYOihJRr3MMAWklZqo4PuO5QSXW3uxB6gCV5uZUO7W9vTxgEXXMGqr9r0ESdb4yKus607EjqWNA7QucYraIusGabZl2ufXHJdvo/nCmwxLTfAD3TnzCV9fZbXxbLcY4jS739W8hRD+53w/BcmrcvLne5eYg93rNT7lp/uhkDuR512aNnv/z3k2jC64iUseiE1FC3KN8J6wvp7MgnWO2GS7QRpqeBgb/lHG+gK2LBsUmOzgvX/pf616tQaIifauxacXvPO9m8Q3tsmARTQ45lelBZTqTnk30Q5izYWK2YZdGaVOuCoa4jDacnQK5WDNjSwa1l/CBIjZ5+JJ3QRw1VO++6tQd6sE4nnMJaRTy2LRBD0zJ7I8loNS4zvBCojOcjz6CqptZ54gYcpZOUyjMWb9o008uQLYCr8+Nu/It9ddizu+RWXQlTEA5lNyxG5s0srb58Mn57 05L4n3e5 gHbG9cfg1Xgxxua0iAUO775odW3VelYidLIBllmTFVY4JwE4mPhzAnWYtQ2CjwBwppohTr656oh1gUmZ7NhygNJ8qBK78Uch9TgIxOfotB8aS8xTBnPZBo18R7tqH10jpZchtNjDwzs72T5mQKd4f9BF019/Gx32C9a2j 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: 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 | 94 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 4 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 049313871059..aef02c150f2c 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -618,11 +618,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 206acdde51f5..17c751aac854 100644 --- a/init/main.c +++ b/init/main.c @@ -212,8 +212,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); @@ -758,8 +765,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 9b68ddc4af5e..edb2575967ab 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -178,6 +178,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 */ @@ -595,6 +607,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, phys_addr_t end = base + memblock_cap_size(base, &size); int idx, nr_new, start_rgn = -1, end_rgn; struct memblock_region *rgn; + phys_addr_t new_size = 0; if (!size) return 0; @@ -607,7 +620,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; } /* @@ -654,6 +668,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, memblock_insert_region(type, idx++, base, rbase - base, nid, flags); + new_size += rbase - base; } } /* area below @rend is dealt with, forget about it */ @@ -669,6 +684,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, end_rgn = idx + 1; memblock_insert_region(type, idx, base, end - base, nid, flags); + new_size += end - base; } } @@ -687,8 +703,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type, goto repeat; } else { memblock_merge_regions(type, start_rgn, end_rgn); - return 0; } +done: + if (new_size == size) + memblock_memsize_record_add(type, obase, size); + return 0; } /** @@ -858,6 +877,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; } @@ -2039,6 +2059,7 @@ struct memsize_rgn_struct { static struct memsize_rgn_struct memsize_rgn[CONFIG_MAX_MEMBLOCK_MEMSIZE] __initdata_memblock; static int memsize_rgn_count __initdata_memblock; +static const char *memblock_memsize_name __initdata_memblock; static void __init_memblock memsize_get_valid_name(char *valid_name, const char *name) { @@ -2237,6 +2258,75 @@ 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; + } + } +} + +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 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/89g7I9JN59uMQOCZ7JjBIT+t4zTWCUn4Xkg1lIPpiFsG0B I/MqRrHUguLc9NRiwwJTeKQm5+duYgSnSS3LHYzT337QO8TIxMF4iFGCg1lJhHfTFs80Id6U xMqq1KL8+KLSnNTiQ4ymwPCdyCwlmpwPTNR5JfGGJpYGJmZGJhbGlsZmSuK8Z66UpQoJpCeW pGanphakFsH0MXFwSjUwtbTE3bfpCslhjH50uifoqZ7efJaW+H2Tv6lyXH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 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; From patchwork Tue May 21 02:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668801 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 4FFDFC25B77 for ; Tue, 21 May 2024 02:40:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C2566B0095; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 276036B0096; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEF6E6B0099; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6BCD16B008A for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D763CC057E for ; Tue, 21 May 2024 02:40:15 +0000 (UTC) X-FDA: 82140848790.12.57DE3F3 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by imf15.hostedemail.com (Postfix) with ESMTP id 2AF3BA000A for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=muSdhv+c; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.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=RvOy3FDyQQAo8yQO1IZqkwS+ImL75+nyHDK07TC3cHQ=; b=buwojyR0S+wLHfhn6eLAQYRP7eleBnRUhtQ5yXeXKmhvYGtUZ5wpJBjx+5x2gM8glCeIYA tVBkhVKNiBmwmNi+PF00DhSstRk4Eps+ByP89Iha6f18PljU/8RAU9+PJr1Muq1sv2oYGD kHcI0+5RGDkDAw8uJiOVsLhl5rMPNGY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259213; a=rsa-sha256; cv=none; b=49XywVcXbG9rKPMYfaKy1/oXaYWYybgChA/BRduGDEo6I7GMGxTo9NwJADCbedeKp6J8eI yXCJn0KWEacQbACL7sQBu37VOJ9NKDAWR934Uudfp9PYNGWeKbmeo2TMIwhqKUw/LU5Gt3 VJRlKIfTW3l7UnSCcn/V7bPN7Y+Sdxc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=muSdhv+c; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf15.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.25 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp02e490ce39445b49cfb3af4de9bebba694~RYKizXwnc0378603786epoutp02c for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20240521024010epoutp02e490ce39445b49cfb3af4de9bebba694~RYKizXwnc0378603786epoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=RvOy3FDyQQAo8yQO1IZqkwS+ImL75+nyHDK07TC3cHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=muSdhv+cDnjC2IoX2AQ+taOaMDnDYlA7gEy5suCiGSs+axutgrYlep5EjHuC7Sl5i 8f+xm5eiqO63tEcH12evKerEfsXidQ+q8C/o1wrkHK4O8pS/8eS6bJKrbkWY3ePrYe ZSE0sfuhvHrprr5k4ygthfmFV4YR3A+hLArgBORQ= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epcas1p2ec24a0caf94e985d6606e0995b215200~RYKiZq-Vd0928709287epcas1p2E; Tue, 21 May 2024 02:40:10 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.224]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4VjzDn6BCnz4x9Pq; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 20.5F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p3ccda7b2d9e6518b4575427c957e19377~RYKhnx8H90314503145epcas1p3c; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp166705647a9d5dccc3e4a41573f7bf81e~RYKhmgNYK2362723627epsmtrp1K; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-053ff700000025be-aa-664c09894993 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id F6.D3.19234.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 20240521024009epsmtip2fa7c3b4f548e6e646832f9ce331c5706~RYKhbz5Nr1132711327epsmtip2U; 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 07/10] memblock: track kernel size on memsize Date: Tue, 21 May 2024 11:39:54 +0900 Message-Id: <20240521023957.2587005-8-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+NgFmplk+LIzCtJLcpLzFFi42LZdlhTV7e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oxEQy3mouJEAAwD K73dAgAA X-CMS-MailID: 20240521024009epcas1p3ccda7b2d9e6518b4575427c957e19377 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p3ccda7b2d9e6518b4575427c957e19377 References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Stat-Signature: h1oz67rorkggbyp97aoz44gpfqf5a9h6 X-Rspamd-Queue-Id: 2AF3BA000A X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1716259212-286860 X-HE-Meta: U2FsdGVkX18fCHyr5O9HWcIjal82JD4lp1JxQYpy3uTfLnxjOKeeyX5HC5w3ZFGdmSeYYPPYYvQsszOt3Y5AgeCNteX5WQU1B4oAl59vDRR+OORbMxRKIKvRl5uLSDKY+OvjLSBxGTFoRpMBNdBoZQJ7lxVrc7PQlVyiPM84VIDAna77AV0bnfj96IGxwclWcS+D9QIoA9CjRPbwiVBs4L+pG0nQT+hXMk67Qx0HWbCBAQRN98Vu/fK5JbwWwRs7/qxdzCIawlOhOit7C/JZ+g+N9wWVeKAtqSxOGaT4NBMpSj5pn/L7MVrpTKnhaDutazlxNb7oJ/vqBti8GZMQDlyqVYF0VpyuRvqEGR7TT80FEBTwiUQmidTr8kwpTGcfLVmKs0NVHQV/tKKjuV+3CzdZeibMkZsVHP4DmveCRig57hzYv3Ve+w2jb6xTqcDqWV9FoxeYQCtfdOsSJKiPM8uXMWodherAGuhn9I3Ar9yBZlkW+a+rMVxyHMi/6kdb1JeMBvelLsiB2LSoO7D/S0q+Dp5V8CxmAgx/o3+WEeORSjzgy4SXlbm0GsJsBM8JfjqMOaleDCtVQA0/leXugFFi18CQmvvaF6DjPzablSajoO9AC2l4zs6XAOvK18yRYbH17PrEIEsmUPPSUvdxxpl5alnVxwVu1px0npkHYshh5wnM7C2ZDoXl+8NmAB+6rcn8wuXTZsDQHgKdTRMWVYMmMiieTp8v82iY+K1QtpQS+5oAfOU2mobatmOs1zkfT7oMlispjOqEP2jfGXNMz5GPTMuzkoXsMHKWBHxSCSf8BS0L/QaPtRL25Kh8yS7MGf1l+bSEl1bX5DFcSESIaLra1Nd3jPb1pVeQhHzdB6PCBI1MJuQGdub1F9kgwrBLo49xvhWXoWaEH7K0/EUgScfB8da2lRE3y3fkDnnTjaWRou5OtFm17CWTlakBe156vmBogJooH3+FW0L7sfH avuyY16q 2Zb5sG3k/1lQo8B+ZPUFdqKl0TrZvVqsJhpE8KFJVLPrF/W8yQ/o2y4jvzrqT7ujGKGWw 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: 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 | 10 ++++++++- 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index da82e5afed01..08638673e106 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -524,6 +524,8 @@ void __init early_init_fdt_scan_reserved_mem(void) if (!initial_boot_params) return; + memblock_memsize_disable_tracking(); + fdt_scan_reserved_mem(); fdt_reserve_elfcorehdr(); @@ -537,6 +539,7 @@ void __init early_init_fdt_scan_reserved_mem(void) } fdt_init_reserved_mem(); + memblock_memsize_enable_tracking(); } /** @@ -1189,12 +1192,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 aef02c150f2c..a83ad98ac252 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -620,6 +620,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, @@ -627,6 +630,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 437c85878280..e9c68b1ee975 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -277,10 +277,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), @@ -288,7 +289,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 de49e7ce74f1..bb033c20ec43 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2060,6 +2060,23 @@ struct memsize_rgn_struct { static struct memsize_rgn_struct memsize_rgn[CONFIG_MAX_MEMBLOCK_MEMSIZE] __initdata_memblock; static int memsize_rgn_count __initdata_memblock; static const char *memblock_memsize_name __initdata_memblock; +static long memsize_kinit __initdata_memblock; +static bool memblock_memsize_tracking __initdata_memblock = true; + +void __init memblock_memsize_enable_tracking(void) +{ + memblock_memsize_tracking = true; +} + +void __init memblock_memsize_disable_tracking(void) +{ + memblock_memsize_tracking = false; +} + +void memblock_memsize_mod_kernel_size(long size) +{ + memsize_kinit += size; +} static void __init_memblock memsize_get_valid_name(char *valid_name, const char *name) { @@ -2313,6 +2330,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 (memblock_memsize_tracking) { + if (type == &memblock.reserved) { + memblock_dbg("%s: kernel %lu %+ld\n", __func__, + memsize_kinit, (unsigned long)size); + memsize_kinit += size; + } } } @@ -2325,6 +2348,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 (memblock_memsize_tracking) { + if (type == &memblock.reserved) { + memblock_dbg("%s: kernel %lu %+ld\n", __func__, + memsize_kinit, (unsigned long)size); + memsize_kinit -= size; + } } } #endif /* MEMBLOCK_MEMSIZE */ @@ -2442,6 +2471,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; @@ -2546,6 +2588,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) @@ -2672,6 +2716,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private) } seq_puts(m, "\n"); + seq_printf(m, " .kernel : %7lu KB\n", + DIV_ROUND_UP(memsize_kinit, 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 2e22ce5675ca..a4c692635e9b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -5776,8 +5777,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 Tue May 21 02:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668804 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 05124C25B77 for ; Tue, 21 May 2024 02:40:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD30A6B0098; Mon, 20 May 2024 22:40:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77E036B008A; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B2096B009B; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B172B6B0098 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6EC5FA25BF for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.10.85133BE Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf19.hostedemail.com (Postfix) with ESMTP id B9E891A0011 for ; Tue, 21 May 2024 02:40:13 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=cKAiiHkc; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf19.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 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=1716259214; 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=BSK9Qlu8VaXXXrgxPdkSNVuJQ8cVVtzS2NFztJ8CnqA=; b=LkiFqRH/r4pecPwnsXuZXf86hpPGTsK+J04I3Olvptr2PP8fAxr5fH7o+dELQ0HLCKlZ5X Ygkd+J8Y91C4X3zjopZ84vlTrsVUmwRudJT8v6MEXhgcX39Kp3htETYTHmHrdEdjHITXWl dkE3Ca/DHjUcADv3W0IjawD/I6eT1nQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=cKAiiHkc; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf19.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259214; a=rsa-sha256; cv=none; b=YWlf914K7NrXYo+/aZaUFsv99ziiUBo4eT+KjnWqJgjPFzX8V7+Dt9vDJomdAIEX1ZlbfF KXgGN0j9hQj+boFAZQwRy+Vzmj0oaIv8ujcYrCJCIWC2nliN7WLvNo8Ks2NdllkY0LxmXB lRfB/JQSW2ykQmeOzU53D/GAkuqHjrc= Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp0350e1726ae347e557edf36ca2d19914dd~RYKi2Cq9-0915109151epoutp03N for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240521024010epoutp0350e1726ae347e557edf36ca2d19914dd~RYKi2Cq9-0915109151epoutp03N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=BSK9Qlu8VaXXXrgxPdkSNVuJQ8cVVtzS2NFztJ8CnqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKAiiHkcGQ94RyEZo9XB/RgCZpFSiLysOAf2Hihl96Wt0XQSOpFnzm/kLE4afI/Di Ct14RIE7wrF+hdho0i8/ZsvMrzpbjIRn/XBHf5lGZNbUVOtcCco7IFU0wIE6qmBzoZ v1O2WFuCRI+lmo4bZEALhdKvDHEqUHDHaqNF1+rE= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20240521024010epcas1p2f12c4f8f47d1a12c3d5ab40ebefa4071~RYKiX1IbC0671506715epcas1p24; Tue, 21 May 2024 02:40:10 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.36.223]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn5bj4z4x9Pp; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 30.5F.09662.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p291bbc11c4e5cdaa922ca302d95330e6b~RYKhpOgNM0129801298epcas1p2p; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp1a516b7dd01533488b1018c01119b6bb9~RYKhoZ7fg2362723627epsmtrp1L; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a35-2b3fa700000025be-ab-664c0989e2e9 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 3F.EA.09238.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 20240521024009epsmtip2f1862bf201bde31cc9f190cb892768e6~RYKhfMz3e1132711327epsmtip2V; 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 08/10] memblock: print memsize summary information Date: Tue, 21 May 2024 11:39:55 +0900 Message-Id: <20240521023957.2587005-9-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+NgFupgk+LIzCtJLcpLzFFi42LZdljTQLeT0yfN4O1PNYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzjh4ehJrwTu+iofbzrA1MO7j7mLk5JAQMJG4c3MOaxcjF4eQwA5GielH ZjOBJIQEPjFK3PwvAJH4xijxprOZCaaj//xsNojEXkaJ1/2rGSGcz4wSqybMB6tiE9CWeL9g EiuILSJgJ/Ft9gEwm1mgVOLtmxPMILawgKfEsimNYHEWAVWJJ91tjCA2r4C9xJrrlxkhtslL zLz0nR3E5hRwkJg/ZTE7RI2gxMmZT1ggZspLNG+dzQxR/5Vd4ufBFAjbRWLu+rksELawxKvj W9ghbCmJl/1tUHa+xIWLr4Bu5gCyayQWTjSECNtL7Po6gxUkzCygKbF+lz7EJj6Jd197WCGq eSU62oQgqtUkWp59ZYWwZST+/nsGZXtIHJrxlwkSOpMZJVr2/GafwCg/C8kDs5A8MAth2wJG 5lWMYqkFxbnpqcWGBYbwOE3Oz93ECE6SWqY7GCe+/aB3iJGJg/EQowQHs5II76YtnmlCvCmJ lVWpRfnxRaU5qcWHGE2BwTuRWUo0OR+YpvNK4g1NLA1MzIxMLIwtjc2UxHnPXClLFRJITyxJ zU5NLUgtgulj4uCUamBqymudE7NLzo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w+nea/e9jzx9wenz06vz u0yH75qC9hZz+TnMTNnnjq33CFgwseCSTN6L/8G39p5zsWZ/Kj4jMlNX/1nm3RCxVDlG5rXe AWcduW6+vjQ9QTEmR3fh+bXNr6XeLN/Pprr+Mfuf9tMGe349Xfev5OT+efdW9NzmWDQz19tU Xv+aJ6fxhzVXZvfaT+uYuL1APr7hLvvrvfXzYxa6bJzI3B/9XyPqafKzH567UpRYijMSDbWY i4oTAU5uzwzjAgAA X-CMS-MailID: 20240521024009epcas1p291bbc11c4e5cdaa922ca302d95330e6b X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p291bbc11c4e5cdaa922ca302d95330e6b References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspamd-Queue-Id: B9E891A0011 X-Stat-Signature: hg3ng5ncrjx5gihhzcd41h9uqsbcfoq8 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1716259213-239812 X-HE-Meta: U2FsdGVkX18rwdeO0kJ/U6JXs4/GzPL08I1Is3P2Esn3kJsIqFEK3+VshTFsc0ytfcFoCKcG2Ut7hdTJ9cdL02n9RlZ5Mj19cBUnQP2KsLO2B0j+/TATIG2b0dDiMmWeM7RfOzY/gl5/tuX+QLI7xJUfAcrntIEzCjhuNdEoDgStiattMaR3FJ3s12NxrT2aTIaVS8aAVy/sCBbSa8MxpY5EbHNBjdI85ihFuvLOm/oOAzlQczHG8ntKmlaKuYlN3REZ1hZpJxak8a9/uBcSWcz5Bz1sZNcUQwR8bfrosGpoyW1QKwAkU3Vykrp8rHsA2cV5Z0cHUZ3lpx9j7lbMEoTzqIi4ThyDTWEmKAutfAp3DCc731Ll0qTSS6WoTZ92hBWFYIquXKxVgwxhHrZLgQytULP4oNFXI6opYEEoVNitGJd0DWYnsQgF3TjdlwXfHlA6Pf6hC/eOS5hgfl6DTt7ECxxEMp4RJpfh7LjRJJwhtcSp2y6K1paI74HoQ9zWILrXiN7wD36TBaNLDjoX58mn2W0ifGRDkfvpgC9QzH0csurO5W8Q2GeRc5q114J3tqiY+oUmvh9YoXaf+xe1cuqA2wguFSeh34ut2bpddk0Ex7+KF3y4Ppf0b1sQav3TZ0hr+cbjQRm8Q2e9C19nXp8jsAdM5uhjTq65haaSOifYff/xUz4FyICb4mJb6Ne+D9i7TVehOvx1YzfDHa33pAryx829a6/oI0HAcZ8f9uRNg5M58siNlxigBIVo506ZuU10gsVoE5hLWaxFQHgabmQ/ResKVxJiaUdxwcWifrt6N1WzrIGb+yxzjqXpgPjUJFNFTitvhIPQbURJfa9XUNk/OrYZQFreIy49SafJVBj6aGJaKdbx/N9rIKnZxYn2O5xTfT9HF5xBSumu/GG+h9vz9AZ+oAwf8UOUln0Rs8r7iOnbpn5El/WrqgS59lUEfjTX83IdYWfYsUyfAfr HnFwKISO wOkvy5Swla0pVI1DntlFZCvCEXpLUwto3frvLudd69hVqvQ1qLK5AZB/nNX5vLtA4fExA 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: 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 bb033c20ec43..0906d81f66c2 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2689,7 +2689,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); @@ -2715,13 +2716,24 @@ static int memblock_memsize_show(struct seq_file *m, void *private) reserved += (unsigned long)rgn->size; } + total = memsize_kinit + reserved + system; + seq_puts(m, "\n"); + seq_printf(m, "Reserved : %7lu KB\n", + DIV_ROUND_UP(memsize_kinit + reserved, SZ_1K)); seq_printf(m, " .kernel : %7lu KB\n", DIV_ROUND_UP(memsize_kinit, 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 Tue May 21 02:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668798 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 86E9AC25B77 for ; Tue, 21 May 2024 02:40:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A67B36B0092; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F1A26B0088; 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 73C0C6B0092; Mon, 20 May 2024 22:40:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5497D6B0085 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EAA6A140B57 for ; Tue, 21 May 2024 02:40:15 +0000 (UTC) X-FDA: 82140848790.08.3459BD1 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf01.hostedemail.com (Postfix) with ESMTP id 280B34000D for ; Tue, 21 May 2024 02:40:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=qCQFDudw; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf01.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 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=IzdCz5v5Q5xEqtPrJCRP7MpeWiihFzW0vfPNWZ8gj+E=; b=YJNhzbvyBedsCdk+Urm+OHm3TmzQWrZewLeMq0mPQCeEXxGzG5DPcmIWlOL37ZEoIPkphK Sk8npWoGiZCPL+ux8xnz35QDKM0poHnEjwpp3giCowgXrnhvfDYYAmNV/7PstfBs4X2yF2 JPw6wJQ1eJcwtpbZB7s2UW2KQG4m/go= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=qCQFDudw; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf01.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.33 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=7tjgtN/nA7pZ/K1kuwGqOHPB2gtncZxMws9W+EZ3DT0m0WxgFbCOyDuvSAxKe4SvtI3FvM vdAhyyL/g1w9ozXWYb5CzJ0JO27NBbcnEatRlUAmEC/g2XpqB+J86F9UTtSis9SI8x/Fub cATIRE0wWyYByB5LRQm4iZjqp5f/tAA= Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp037d2adcc54ca9a69ba381ac253c1726b1~RYKixIufN0915109151epoutp03M for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240521024010epoutp037d2adcc54ca9a69ba381ac253c1726b1~RYKixIufN0915109151epoutp03M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=IzdCz5v5Q5xEqtPrJCRP7MpeWiihFzW0vfPNWZ8gj+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qCQFDudwnYicldDAVbNAk4mpz+/2NOUsDw2QtTNmdMiW6DkQJpUZoHvEdXMJGjQ0M gkzP8YxG5E9Urbdwu1v6JNImzuoyFrTr7F5ezVSZO9bDL+lufYcsRaAyNHKrZBPqCm x+jDUaGnGZVrA/m0jUqzUcWXkCYmDvURZzOw6qZw= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epcas1p4bd4b067f9fdf176020dc0e36398edee0~RYKiaScxj1520715207epcas1p4C; Tue, 21 May 2024 02:40:10 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.38.242]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4VjzDn6G3Hz4x9Q2; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 4B.40.09663.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 20240521024009epcas1p441a4c458d251eec7bb6e63e671c25b4e~RYKhroupz2938729387epcas1p4Z; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp10e6704301994088e82ffff0fff8d83bc~RYKhqvsNS2362723627epsmtrp1O; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a37-b863ba80000025bf-60-664c0989ee09 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 37.D3.19234.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 20240521024009epsmtip2b43a8fc85df3b4318a52e7f789e21f95~RYKhiIo8T1232612326epsmtip2J; 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 09/10] memblock: print kernel internal size Date: Tue, 21 May 2024 11:39:56 +0900 Message-Id: <20240521023957.2587005-10-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+NgFmplk+LIzCtJLcpLzFFi42LZdlhTX7eT0yfN4ModI4s569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 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93jK5K7UnYerJmrjtf 3nWDzGtTRZRYijMSDbWYi4oTATC/RngYBAAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsWy7bCSvG4np0+awa01khZz1q9hs+jePJPR ovf9KyaLy7vmsFncW/Of1eLI+u1MFrMb+xgd2D12zrrL7rFpVSebx6ZPk9g9Tsz4zeLRt2UV o8eZBUfYPT5vkgtgj+KySUnNySxLLdK3S+DKmLLwGXPBFa2KCzeWsTQwnlTqYuTkkBAwkXi+ awcTiC0ksJ1RYvXrOoi4jMSb809Zuhg5gGxhicOHi7sYuYBKPjJKrLjawghSwyagLfF+wSRW EFtEwEliw5XVLCA2s0ClxL/bt8DiwkDx2/NOs4PYLAKqEn8+/QSr4RVwkLh55A87xC55iZmX voPZnEDx+VMWs0PcYy9x5tJ5Voh6QYmTM59AzZeXaN46m3kCo8AsJKlZSFILGJlWMYqmFhTn pucmFxjqFSfmFpfmpesl5+duYgSHt1bQDsZl6//qHWJk4mA8xCjBwawkwrtpi2eaEG9KYmVV alF+fFFpTmrxIUZpDhYlcV7lnM4UIYH0xJLU7NTUgtQimCwTB6dUA5Pv092/Xk/cvn7Zn+bg P71aLltsDu7eu/XP6hNpRqKfPnUuzHt1YO6OeMW2ZUYbIl+e3bh/VgOj0MTrZpdst617EPHv 0n3j2haLps/XzNueGq21318bwdNmeP1TQ6WB0fpvVWIn98Xb/FczsIkxvdcVYV7+ftXHqpAw hr+/zI6/O/9NYmt4h+uv5ncy1z5VPpKPLFu9UffoFBfuRzx8l65LFEYLsk17LWN+fdGv2yUM 936cmrHpSOzdOM9HDTd4DrXc+TnX9IzJJsZfWruepERm3bY79/hPGGv9Wbk8w+StPUxlG55O feH7u7616a9PjOiEtLi9bVqV5XMv8vieUvse5nu+qCuJz7R1vXNB2ZaZSizFGYmGWsxFxYkA 4WIq4t4CAAA= X-CMS-MailID: 20240521024009epcas1p441a4c458d251eec7bb6e63e671c25b4e X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p441a4c458d251eec7bb6e63e671c25b4e References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspamd-Queue-Id: 280B34000D X-Stat-Signature: 8zyjrpeaunaht8rzqy3bkgmauphifbxk X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1716259212-559781 X-HE-Meta: U2FsdGVkX18sFVd/mQOWsrJaeuu5MkAkjypQl3XX08GfNmAb5FwDrxfZHcqylCe08GAPe79x86jeaBGB/F4VJoS7g4s6Ads15VKnn/wdgiBWlqU/bITBv2+dq7nE2P5wRum765+E45RBwfHYNZrgvLVz93rZQATu2LZjMrxZF/09zf6yDIaKVs5x9ljTJYFSrpayVFfKH2mB00iIO4mAkmylfUOO5xshV7Nwxwj4YbpmffVqvsqH1V7ZcrnpDjVoSvIpvT9NjuCoF7OBYIcIGpgk57TkhJA3UpASbSFO5L/3RkjHhi0nSA6FbIlgJoW9iB0oDWO2Cg0usUD5yvTeCPIKUVehFRNsI2DX+T21E4L7/SwK7UYEKML79T4qEmRwUt0KJeN6ANkrC2O9DPKA9OIwzVbQ7INHNBahr+hWe/T9PLeyVWqXE/uceVuGx84zsvFjhfyvFFy4i1P2nqvATd32tx2rFBt3toCjx6Ecsz2GlXVDMNc+6vB+7C0L32m+YdC5Iz4i7T9m6pReZVnvYwuHWLH7yf5syh0SCUhJ1fpn/AtC4RzRvn+eivPWiZRl/XlAJsiHU/Wr5OKqjNV2SeduTFqySuQoz2Iuk4YZc7Hj99v/BrWHlPH+A2i+cg7NmSUTYDCF4Z7eN+Ls5L/kOcPYIW2gayKqBLqhZgsaAbLdfPCm2xHxc/b3UnM9n/WB6sWhHK+akX7G695mjNPeQAS0WG+7eZGAURrGqbFt3y3avQ2HEhs0vAW95dTf3yAQ9pWJDH7zKC7QF9Sn5dNmu9vzsEmSqOczu8kvXNbYb/SCQk7DAB8HCkYwOvrTWebgyyTVmmTVlsuatCFMZZwh2U7hTXNmKuVu2uL2Pce4CpHqSl7/gGSaxzOamfAdh4NeHa7kIIVpUob8qvcoGBAXWr9kGmm3twuHOFjIgP32+HCWdWB09muU8UtljVgyIAocuLBS3v8uNPGlX2v7oc8 Ha8Umisd +bJtVuEaI3DnaRENG12pcAY6/5hA9bBt6NG8+2S05ezuo0YkLIU8CheBU/OI36bVVuuO4xEr/wv7BoX/Ygd1AH6+j1OiwVhQe7qWozn9nEhPKQE7Cnldi+DMP9WbUnxvhjjFIG4ziAHlb+ZLOvLB8nEah+TY4eqbpbjhs 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: 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 : 1181708 KB .kernel : 296172 KB .text : 16960 KB .rwdata : 2299 KB .rodata : 16464 KB .bss : 7549 KB .memmap : 196608 KB .etc : 56293 KB .unusable : 885536 KB Signed-off-by: Jaewon Kim --- include/linux/memblock.h | 6 ++++++ mm/memblock.c | 36 ++++++++++++++++++++++++++++++++++++ mm/mm_init.c | 6 +++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index a83ad98ac252..7ab8b59bfbc1 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -623,6 +623,9 @@ 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); +extern void memblock_memsize_mod_memmap_size(long size); +extern void memblock_memsize_kernel_code_data(unsigned long code, + unsigned long data, unsigned long ro, unsigned long bss); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, @@ -633,6 +636,9 @@ 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) { } +static inline void memblock_memsize_mod_memmap_size(long size) { } +static inline void memblock_memsize_kernel_code_data(unsigned long code, + unsigned long data, unsigned long ro, unsigned long bss) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/mm/memblock.c b/mm/memblock.c index 0906d81f66c2..2fe0dc2575c5 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2061,6 +2061,11 @@ static struct memsize_rgn_struct memsize_rgn[CONFIG_MAX_MEMBLOCK_MEMSIZE] __init static int memsize_rgn_count __initdata_memblock; static const char *memblock_memsize_name __initdata_memblock; static long memsize_kinit __initdata_memblock; +static long memsize_memap __initdata_memblock; +static unsigned long memsize_code __initdata_memblock; +static unsigned long memsize_data __initdata_memblock; +static unsigned long memsize_ro __initdata_memblock; +static unsigned long memsize_bss __initdata_memblock; static bool memblock_memsize_tracking __initdata_memblock = true; void __init memblock_memsize_enable_tracking(void) @@ -2073,11 +2078,25 @@ void __init memblock_memsize_disable_tracking(void) memblock_memsize_tracking = false; } +void __init memblock_memsize_mod_memmap_size(long size) +{ + memsize_memap += size; +} + void memblock_memsize_mod_kernel_size(long size) { memsize_kinit += size; } +void __init memblock_memsize_kernel_code_data(unsigned long code, unsigned long data, + unsigned long ro, unsigned long bss) +{ + memsize_code = code; + memsize_data = data; + memsize_ro = ro; + memsize_bss = bss; +} + static void __init_memblock memsize_get_valid_name(char *valid_name, const char *name) { char *head, *tail, *found; @@ -2691,6 +2710,11 @@ 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 etc; + + etc = memsize_kinit; + etc -= memsize_code + memsize_data + memsize_ro + memsize_bss + + memsize_memap; sort(memsize_rgn, memsize_rgn_count, sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); @@ -2723,6 +2747,18 @@ static int memblock_memsize_show(struct seq_file *m, void *private) DIV_ROUND_UP(memsize_kinit + reserved, SZ_1K)); seq_printf(m, " .kernel : %7lu KB\n", DIV_ROUND_UP(memsize_kinit, SZ_1K)); + seq_printf(m, " .text : %7lu KB\n" + " .rwdata : %7lu KB\n" + " .rodata : %7lu KB\n" + " .bss : %7lu KB\n" + " .memmap : %7lu KB\n" + " .etc : %7lu KB\n", + DIV_ROUND_UP(memsize_code, SZ_1K), + DIV_ROUND_UP(memsize_data, SZ_1K), + DIV_ROUND_UP(memsize_ro, SZ_1K), + DIV_ROUND_UP(memsize_bss, SZ_1K), + DIV_ROUND_UP(memsize_memap, 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/mm_init.c b/mm/mm_init.c index f72b852bd5b8..45187904db49 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1587,8 +1587,10 @@ void __init *memmap_alloc(phys_addr_t size, phys_addr_t align, MEMBLOCK_ALLOC_ACCESSIBLE, nid); - if (ptr && size > 0) + if (ptr && size > 0) { page_init_poison(ptr, size); + memblock_memsize_mod_memmap_size((long)size); + } return ptr; } @@ -2679,6 +2681,8 @@ static void __init mem_init_print_info(void) init_data_size = __init_end - __init_begin; init_code_size = _einittext - _sinittext; + memblock_memsize_kernel_code_data(codesize, datasize, rosize, bss_size); + /* * Detect special cases and adjust section sizes accordingly: * 1) .init.* may be embedded into .data sections From patchwork Tue May 21 02:39:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13668806 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 F3A1FC25B7B for ; Tue, 21 May 2024 02:40:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20BC06B0083; Mon, 20 May 2024 22:40:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9AD46B0099; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 457B26B0098; Mon, 20 May 2024 22:40:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C98006B0088 for ; Mon, 20 May 2024 22:40:16 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 84F281A0B05 for ; Tue, 21 May 2024 02:40:16 +0000 (UTC) X-FDA: 82140848832.09.DF6E152 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf05.hostedemail.com (Postfix) with ESMTP id BA30E10000A for ; Tue, 21 May 2024 02:40:13 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="bP52x+/A"; spf=pass (imf05.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716259214; a=rsa-sha256; cv=none; b=sPRdgaLR5iKk1uUzqNqlnxpNaCFc8Gu0ANr/KxUH6lfcydEFhPTMLJ4MATfHikeS3Bgz1N 30CZvJEH721iWbgrdekPph4PA546HC8Xud3HPvq6mx1N/WmTEme2XUldHaygLjOeQTP6WZ 5uKqcttkvNa1GP2DWyIZ4aSSIgEsWQ0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b="bP52x+/A"; spf=pass (imf05.hostedemail.com: domain of jaewon31.kim@samsung.com designates 203.254.224.34 as permitted sender) smtp.mailfrom=jaewon31.kim@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716259214; 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=yVf68Cj1nmtMbTxmkx6CIgy96BRosJN2TQP/FPuQu/8=; b=lXUvj++ztLHzM9or8/AwSNsDumZ/Cv5OIE71Wx8fR921hYW+NMgTRtJ/Y744MgDGnXz7C9 YlRQnkAadRbEb1s3XJEnMQvkOqHSiEjbks+jUZltEHdYO3f56sx6ZJUMMoSxRrLJ5+FgQQ yazvGr/Qe9Ije5ZVbv7ial9zNlGc6bI= Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epoutp04a613696e1d32133585549f7b8c49b075~RYKi2zzGt1821818218epoutp04r for ; Tue, 21 May 2024 02:40:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20240521024010epoutp04a613696e1d32133585549f7b8c49b075~RYKi2zzGt1821818218epoutp04r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1716259210; bh=yVf68Cj1nmtMbTxmkx6CIgy96BRosJN2TQP/FPuQu/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bP52x+/ApNVHBIzFM/4oYwo//UvPFD67XoOXBDj31FTLgcP111sQ/RlcWu9Fkgyam W9WMEnnmdph6iZBCEI0t1tEnA6mabO7o9BBdeeLew/1v/dSIjx07amZdjIlN/FXUQv ZbFtnW6NTHxOJtXyygLGARqqE3L9NVbhm6hM/BKM= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20240521024010epcas1p495284369abe490f8d94fdd6adcef2e70~RYKiZSNF71520715207epcas1p4A; Tue, 21 May 2024 02:40:10 +0000 (GMT) Received: from epsmgec1p1.samsung.com (unknown [182.195.38.240]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4VjzDn6DFBz4x9Q7; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmgec1p1.samsung.com (Symantec Messaging Gateway) with SMTP id B1.13.09696.9890C466; Tue, 21 May 2024 11:40:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20240521024009epcas1p15a3290b675ee66339033c185a5a8c00b~RYKhv5DeV2349123491epcas1p1d; Tue, 21 May 2024 02:40:09 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240521024009epsmtrp29f58dea47f5a6d9d50601a9ccaf99022~RYKhvKn8k2496224962epsmtrp2m; Tue, 21 May 2024 02:40:09 +0000 (GMT) X-AuditID: b6c32a36-7a9f9700000025e0-4b-664c09895e29 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 9A.54.08390.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 20240521024009epsmtip29f70c066144ebfba9efa858ec7c443e2~RYKhlFy_t1233912339epsmtip2F; 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 10/10] memblock: support memsize reusable to consider as reusable Date: Tue, 21 May 2024 11:39:57 +0900 Message-Id: <20240521023957.2587005-11-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+NgFupgk+LIzCtJLcpLzFFi42LZdlhTT7eT0yfN4OR9PYs569ewWXRvnslo 0fv+FZPF5V1z2CzurfnPanFk/XYmi9mNfYwO7B47Z91l99i0qpPNY9OnSeweJ2b8ZvHo27KK 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzvi0YCZ7QZdURc/uC2wNjG9Euxg5OSQETCSmL5/N0sXIxSEksINRYtrt 24wQzidGiSOn5rJBON8YJQ7un88O03LxWTMrRGIvUGLlNqiqz4wSB6Y+B6tiE9CWeL9gEiuI LSJgJ/Ft9gEwm1mgVOLtmxPMXYwcHMICURKn95uAhFkEVCXeXD7CCGLzCjhIdH+5wAaxTF5i 5qXvYCM5geLzpyxmh6gRlDg58wkLxEh5ieats5lBbpAQ+MkusfrYRUaIZheJS2+7oa4Wlnh1 fAuULSXx+d1eqAX5EhcuvmICuUdCoEZi4URDiLC9xK6vM1hBwswCmhLrd+lDrOKTePe1hxWi mleio00IolpNouXZV1YIW0bi779nUCUeElNXJ0ECZzKjxPxJv5knMMrPQvLALCQPzEJYtoCR eRWjWGpBcW56arFhgRE8TpPzczcxgpOkltkOxklvP+gdYmTiYDzEKMHBrCTCu2mLZ5oQb0pi ZVVqUX58UWlOavEhRlNg8E5klhJNzgem6bySeEMTSwMTMyMTC2NLYzMlcd4zV8pShQTSE0tS s1NTC1KLYPqYODilGpiyXid0FS/8yMKXGpXhGrjzy5WMqfI+xne2Jfg8WCJ0+bNMx7JJNzQ0 L7Fa7r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+gn2Vn1E26eipm0sofLYNHSxV8f5BTLOVvPe7Ox9M7EhMgHxQtcbrYx7kpzndD5 zOlbEpP45Jc8MYFq0+o3rmNK6zP2Kti5ckdV6z4d0cfF7sYR22zXZQiw5Uw4VHTkodwi8W3J p17IGvi1bfz84qZTcVRL2t8pHZO/C6RduL/9VN7tj9w/5EpKHhbXXLj2YIKMw+KZhUosxRmJ hlrMRcWJAAbDn7PiAgAA X-CMS-MailID: 20240521024009epcas1p15a3290b675ee66339033c185a5a8c00b X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240521024009epcas1p15a3290b675ee66339033c185a5a8c00b References: <20240521023957.2587005-1-jaewon31.kim@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BA30E10000A X-Stat-Signature: 8bebh1srkagmqoxtdinu8pktiaazfa6z X-HE-Tag: 1716259213-633073 X-HE-Meta: U2FsdGVkX1/c+CAr0wFAknoTRZuqMFi3TIPJkFPY9BNaPb7eLbnYlSYinib5kzGue7m01p/NdKRE+f2t9MP37Zb2Q9GR9O8RS5isjl8/n3RV3KyoQcEar3Iyusz19owkzjk9kSztIdL9lFwGLFbxPYhHsymovsqGltTXl8BBUI2q1vLuJdYtsSDh1aTx+9LnUeKA51dXYcCjaPejilf/Hdf2D2oZbS4her6/XcyOuQey7/MdXi/KQUQft6bsgTaCn2Me+TFGSxs2YOf5Bn9t/zLXQzPzfJehlwnm8vz7VFB0HK0vHMRmhywxEvLaAJj7lWanxFKg/3zg9bI6IcH8knODTaijtT5V5ggRA9KqXbHjtDPrEOEu3oxZ2nPueT6FJGfsNxdP/1iskF0ky+rMm+JC8QkBVJ94vigHQDnvj7IvTZwQ68xSbhPeLNtQAfq7PnJW4axL6PVfpU+Azp1mBaTzEX7Ie32DdNM9Na7MZd+nbuTdvxlALU+JX5Y+hQz4OAcKthgX7ca3NNnou5gbFzw0dyu1UGTaCqCNP/52Z5gfZlN0fnrlntJjPvk27167Q0jV1CUTRR6qR7idOVs52p2mFYtU3FHcP6f54iegSHTaVRiBMxH/nqq8rn9RZ56yDRXl/OU5whwe8yASd3lvwR9Guj549rDj2Lciv0CLRvX+VoVCsoIuA8YvtoWWDmIT0BVRMBHyGFpGB3gjobyBEFuK9RlrIUg2CHCN8dBCJWV5Rs+bcRIuZx+rkr9/lpHFiZN6LUugFC+ebp0jwhgvoiA5HOE6XAQaJq9yXNvi7RclubEdgxVRVo+t6qAUzHJz28YuUVH7GjYU7FifVRMr7f6GUkJQyNtfnxSPJ5f7SWRbjAk3JflZAYYJesPlGOZDabBhjrRBwXKe6VhnYFuZ7QVTnAeJ2RlCMmdQc5i4p7vvxMe0xGBK8IanHyTdgUOB1tomD2kRtirGMLlViHb Yb761bwt S2BMFXspaFE/o08zyequiio33VTYChQdWrNcC6n8tLd2b+wvo+tFBDpHr5bcHjBTfagNH+HTwJ45m26aHEFJnUpw/QB5YaS9D4r/vgS9S7GvdTnaGo0hM2DyflajgHehDE8iVWN+G9DWQ3OPjzOdt2lCdw/O3xngQaZl4 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: Sometimes we'd like to include some memory region as reusable even though it is actually not CMA type. In that case, add reusable in its device tree description, then memsize will consider it is reusuable and add its size to the system total memory size. Signed-off-by: Jaewon Kim --- drivers/of/of_reserved_mem.c | 3 +++ include/linux/memblock.h | 2 ++ mm/memblock.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index ece678e07304..7aedac213995 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -468,6 +468,9 @@ void __init fdt_init_reserved_mem(void) memblock_memsize_record(rmem->name, rmem->base, rmem->size, nomap, reusable); + if (reusable && + !of_flat_dt_is_compatible(node, "shared-dma-pool")) + memblock_memsize_mod_reusable_size(rmem->size); } } } diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 7ab8b59bfbc1..0aa6202a7a6a 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -626,6 +626,7 @@ extern void memblock_memsize_mod_kernel_size(long size); extern void memblock_memsize_mod_memmap_size(long size); extern void memblock_memsize_kernel_code_data(unsigned long code, unsigned long data, unsigned long ro, unsigned long bss); +extern void memblock_memsize_mod_reusable_size(long size); #else static inline void memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, @@ -639,6 +640,7 @@ static inline void memblock_memsize_mod_kernel_size(long size) { } static inline void memblock_memsize_mod_memmap_size(long size) { } static inline void memblock_memsize_kernel_code_data(unsigned long code, unsigned long data, unsigned long ro, unsigned long bss) { } +static inline void memblock_memsize_mod_reusable_size(long size) { } #endif #endif /* _LINUX_MEMBLOCK_H */ diff --git a/mm/memblock.c b/mm/memblock.c index 2fe0dc2575c5..a20d60d3bb40 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2066,6 +2066,7 @@ static unsigned long memsize_code __initdata_memblock; static unsigned long memsize_data __initdata_memblock; static unsigned long memsize_ro __initdata_memblock; static unsigned long memsize_bss __initdata_memblock; +static long memsize_reusable_size __initdata_memblock; static bool memblock_memsize_tracking __initdata_memblock = true; void __init memblock_memsize_enable_tracking(void) @@ -2117,6 +2118,11 @@ static void __init_memblock memsize_get_valid_name(char *valid_name, const char valid_name[val_size] = '\0'; } +void memblock_memsize_mod_reusable_size(long size) +{ + memsize_reusable_size += size; +} + static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void) { if (memsize_rgn_count == ARRAY_SIZE(memsize_rgn)) { @@ -2716,6 +2722,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private) etc -= memsize_code + memsize_data + memsize_ro + memsize_bss + memsize_memap; + system += memsize_reusable_size; sort(memsize_rgn, memsize_rgn_count, sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); for (i = 0; i < memsize_rgn_count; i++) {