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 0ePMgiPsHp83yQWwR2XbZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoq ufgE6Lpl5gAdpKRQlphTChQKSCwuVtK3synKLy1JVcjILy6xVUotSMkpMCvQK07MLS7NS9fL Sy2xMjQwMDIFKkzIzpiy8BlzwRWtigs3lrE0MJ5U6mLk5JAQMJGYd7yXpYuRi0NIYAejxKeZ E6GcT4wSP2dOZgWpAnOmTfaE6Xi+awcTRHwno8TJ/UIQDZ8ZJSZuO8IIkmAT0JZ4v2ASWLOI gJ3Et9kHwGxmgVKJt29OMIPYwgJOErfnnWYHsVkEVCX+fPrJAmLzCjhI3Dzyhx1imbzEzEvf wWxOoPj8KYvZIWoEJU7OfMICMVNeonnrbGaQIyQEPrJLzFt0AWgZB5DjIjHjuDrEHGGJV8e3 QM2UknjZ3wZl50tcuPiKCaK8RmLhREOIsL3Erq8zwKYwC2hKrN+lD7GJT+Ld1x6o4bwSHW1C ENVqEi3PvrJ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sZl6//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