From 08e2d0957850ea89a03f935c72797784fa40599d Mon Sep 17 00:00:00 2001 From: Jaewon Kim Date: Tue, 30 Jun 2020 11:42:23 +0900 Subject: [PATCH] ANDROID: memblock: print kernel internal size 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 Bug: 340432773 Signed-off-by: Jaewon Kim Link: https://lore.kernel.org/linux-mm/20240521023957.2587005-10-jaewon31.kim@samsung.com/ Change-Id: I3954640772dfe1917d488440f06b671102e2c06c --- 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 6d5dbb2fdb36..5d3811b4e9aa 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -600,6 +600,9 @@ extern void __init memblock_memsize_detect_hole(void); extern void __init memblock_memsize_enable_tracking(void); extern void __init memblock_memsize_disable_tracking(void); extern void memblock_memsize_mod_kernel_size(long size); +extern void __init memblock_memsize_mod_memmap_size(long size); +extern void __init memblock_memsize_kernel_code_data(unsigned long code, + unsigned long data, unsigned long ro, unsigned long bss); #else static inline void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base, phys_addr_t size, bool nomap, bool reusable) { } @@ -607,6 +610,9 @@ static inline void __init memblock_memsize_detect_hole(void) { } static inline void __init memblock_memsize_enable_tracking(void) { } static inline void __init memblock_memsize_disable_tracking(void) { } static inline void memblock_memsize_mod_kernel_size(long size) { } +static inline void __init memblock_memsize_mod_memmap_size(long size) { } +static inline void __init 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 b0052f77b53b..df8bdd8079ea 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2079,6 +2079,11 @@ 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 long memsize_memmap; +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; void __init memblock_memsize_enable_tracking(void) { @@ -2090,11 +2095,25 @@ void __init memblock_memsize_disable_tracking(void) memblock_memsize_tracking = false; } +void __init memblock_memsize_mod_memmap_size(long size) +{ + memsize_memmap += 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; @@ -2777,6 +2796,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_memmap; sort(memsize_rgn, memsize_rgn_count, sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL); @@ -2809,6 +2833,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_memmap, 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 1c205b0a86ed..29f2a3e73b21 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1591,8 +1591,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; } @@ -2591,6 +2593,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