mm/memblock: show memblock reserved with size information

Tested on RV1106 EVB:
cat /sys/kernel/debug/memblock/reserved_size

   0: 0x00004000..0x00007fff (        16 KiB)
   1: 0x000081c0..0x0052e9c7 (      5274 KiB)
   2: 0x00c00000..0x00c08fff (        36 KiB)
   3: 0x0369c000..0x036bbfff (       128 KiB)
   4: 0x036bd8c0..0x036bdcc3 (         1 KiB)
   5: 0x036bdcc8..0x036d5ffb (        96 KiB)
   6: 0x036d6000..0x037fefff (      1188 KiB)
   7: 0x037ff240..0x037ff79b (         1 KiB)
   8: 0x037ff7c0..0x037ff837 (       120 Bytes)
   9: 0x037ff840..0x037ff843 (         4 Bytes)
  10: 0x037ff880..0x037ff883 (         4 Bytes)
  11: 0x037ff8c0..0x037ff8c3 (         4 Bytes)
  12: 0x037ff900..0x037ffa69 (       362 Bytes)
  13: 0x037ffa80..0x037ffbe9 (       362 Bytes)
  14: 0x037ffc00..0x037ffc03 (         4 Bytes)
  15: 0x037ffc1c..0x037ffc7e (        99 Bytes)
  16: 0x037ffc80..0x037ffc9a (        27 Bytes)
  17: 0x037ffc9c..0x037ffcb6 (        27 Bytes)
  18: 0x037ffcb8..0x037ffcd2 (        27 Bytes)
  19: 0x037ffcd4..0x037ffcee (        27 Bytes)
  20: 0x037ffcf0..0x037ffd0a (        27 Bytes)
  21: 0x037ffd0c..0x037ffe2c (       289 Bytes)
  22: 0x037ffe30..0x037ffe48 (        25 Bytes)
  23: 0x037ffe4c..0x037ffe64 (        25 Bytes)
  24: 0x037ffe68..0x037ffe80 (        25 Bytes)
  25: 0x037ffe84..0x037ffe9c (        25 Bytes)
  26: 0x037ffea0..0x037ffebc (        29 Bytes)
  27: 0x037ffec0..0x037ffedc (        29 Bytes)
  28: 0x037ffee0..0x037ffefc (        29 Bytes)
  29: 0x037fff00..0x037fff9c (       157 Bytes)
  30: 0x037fffa0..0x07ffffff (     73728 KiB)
Total: 80470 KiB

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
Change-Id: If98946c9f2a70fa2816f2f1434a14198e2156d96
This commit is contained in:
Jianqun Xu 2022-03-25 09:26:22 +08:00 committed by Tao Huang
parent f9e5397c76
commit 1fc0ecb55f
3 changed files with 60 additions and 0 deletions

View File

@ -63,6 +63,13 @@ config SPARSEMEM_MANUAL
endchoice
config MEMBLOCK_DEBUGFS
bool "Memblock debugfs for reserved memory"
depends on DEBUG_FS && ARCH_KEEP_MEMBLOCK
help
Extend memblock debugfs to show size of each memblock, and shows the
result of total size by KiB format.
config DISCONTIGMEM
def_bool y
depends on (!SELECT_MEMORY_MODEL && ARCH_DISCONTIGMEM_ENABLE) || DISCONTIGMEM_MANUAL

View File

@ -62,6 +62,7 @@ CFLAGS_page_alloc.o += -DDYNAMIC_DEBUG_MODULE
obj-y += page-alloc.o
obj-y += init-mm.o
obj-y += memblock.o
obj-$(CONFIG_MEMBLOCK_DEBUGFS) += memblock_debugfs.o
ifdef CONFIG_MMU
obj-$(CONFIG_ADVISE_SYSCALLS) += madvise.o

52
mm/memblock_debugfs.c Normal file
View File

@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Debugfs for reserved memory blocks.
*
* Copyright (C) 2022 Rockchip Electronics Co. Ltd.
*/
#include <linux/init.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/memblock.h>
#define K(size) ((unsigned long)((size) >> 10))
static int memblock_debugfs_show(struct seq_file *m, void *private)
{
struct memblock_type *type = m->private;
struct memblock_region *reg;
int i;
phys_addr_t end;
unsigned long z = 0, t = 0;
for (i = 0; i < type->cnt; i++) {
reg = &type->regions[i];
end = reg->base + reg->size - 1;
z = (unsigned long)reg->size;
t += z;
seq_printf(m, "%4d: ", i);
seq_printf(m, "%pa..%pa (%10lu %s)\n", &reg->base, &end,
(z >= 1024) ? (K(z)) : z,
(z >= 1024) ? "KiB" : "Bytes");
}
seq_printf(m, "Total: %lu KiB\n", K(t));
return 0;
}
DEFINE_SHOW_ATTRIBUTE(memblock_debugfs);
static int __init memblock_debugfs_init(void)
{
struct dentry *root = debugfs_lookup("memblock", NULL);
if (!root)
return -EPROBE_DEFER;
debugfs_create_file("reserved_size", 0444, root,
&memblock.reserved, &memblock_debugfs_fops);
return 0;
}
late_initcall(memblock_debugfs_init);