[PATCH 7/8] memblock: print memsize summary information

Jaewon Kim
2022-03-24T06:59:47Z

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 <jaewon31.kim@samsung.com>
---
mm/memblock.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 597ec7fb5bb2..ef8cec6242d2 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2492,7 +2492,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
{
int i;
struct memsize_rgn_struct *rgn;
- unsigned long reserved = 0, reusable = 0;
+ unsigned long reserved = 0, reusable = 0, total;
+ unsigned long system = totalram_pages() << PAGE_SHIFT;

sort(memsize_rgn, memsize_rgn_count,
sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL);
@@ -2518,13 +2519,24 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
reserved += (unsigned long)rgn->size;
}

+ total = kernel_init_size + reserved + system;
+
seq_printf(m, "\n");
+ seq_printf(m, "Reserved : %7lu KB\n",
+ DIV_ROUND_UP(kernel_init_size + reserved, SZ_1K));
seq_printf(m, " .kernel : %7lu KB\n",
DIV_ROUND_UP(kernel_init_size, SZ_1K));
seq_printf(m, " .unusable : %7lu KB\n",
DIV_ROUND_UP(reserved, SZ_1K));
+ seq_printf(m, "System : %7lu KB\n",
+ DIV_ROUND_UP(system, SZ_1K));
+ seq_printf(m, " .common : %7lu KB\n",
+ DIV_ROUND_UP(system - reusable, SZ_1K));
seq_printf(m, " .reusable : %7lu KB\n",
DIV_ROUND_UP(reusable, SZ_1K));
+ seq_printf(m, "Total : %7lu KB ( %5lu.%02lu MB )\n",
+ DIV_ROUND_UP(total, SZ_1K),
+ total >> 20, ((total % SZ_1M) * 100) >> 20);
return 0;
}

--
2.17.1