memblock: Add flags and nid info in memblock debugfs
PATCH v3 1/1 memblock: Add flags and nid info in memblock debugfs
Currently, the memblock debugfs can display the count of memblock_type and the base and end of the reg. However, when memblock_mark_*() or memblock_set_node() is executed on some range, the information in the existing debugfs cannot make it clear why the address is not consecutive.
For example,
cat /sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff
1: 0x0000000090200000..0x00000000905fffff
2: 0x0000000090600000..0x0000000092ffffff
3: 0x0000000093000000..0x00000000973fffff
4: 0x0000000097400000..0x00000000b71fffff
5: 0x00000000c0000000..0x00000000dfffffff
6: 0x00000000e2500000..0x00000000f87fffff
7: 0x00000000f8800000..0x00000000fa7fffff
8: 0x00000000fa800000..0x00000000fd3effff
9: 0x00000000fd3f0000..0x00000000fd3fefff
10: 0x00000000fd3ff000..0x00000000fd7fffff
11: 0x00000000fd800000..0x00000000fd901fff
12: 0x00000000fd902000..0x00000000fd909fff
13: 0x00000000fd90a000..0x00000000fd90bfff
14: 0x00000000fd90c000..0x00000000ffffffff
15: 0x0000000880000000..0x0000000affffffff
So we can add flags and nid to this debugfs.
For example,
cat /sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff NONE 0 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 2: 0x0000000090600000..0x0000000092ffffff NONE 0 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 4: 0x0000000097400000..0x00000000b71fffff NONE 0 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 15: 0x0000000880000000..0x0000000affffffff NONE 0
---
v3:
- show string value for each memblock flag
--- mm/memblock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
mm/memblock.c +11 -1
@@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private)struct memblock_region *reg;int i;phys_addr_t end; +static const char flagname[BITS_PER_LONG ][8 ] = { + [0 ... (BITS_PER_LONG -1 )] ="?" , + + [ilog2 (MEMBLOCK_HOTPLUG )] ="HOTPLUG" , + [ilog2 (MEMBLOCK_MIRROR )] ="MIRROR" , + [ilog2 (MEMBLOCK_NOMAP )] ="NOMAP" , + [ilog2 (MEMBLOCK_DRIVER_MANAGED )] ="DRV_MNG" , + };for (i =0 ; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size -1 ;seq_printf (m,"%4d: " , i); -seq_printf (m,"%pa..%pa\n" , ®->base, &end); +seq_printf (m,"%pa..%pa " , ®->base, &end); +seq_printf (m,"%8s " , reg->flags ? flagname[ilog2 (reg->flags)] :"NONE" ); +seq_printf (m,"%4d\n" ,memblock_get_region_node (reg)); }return 0 ; }
Signature · 1 line
2.34.1
Quoted 28 lines · Yuwei Guan
Currently, the memblock debugfs can display the count of
memblock_typeand the base and end of the reg. However, when memblock_mark_*() ormemblock_set_node()is executed on some range, the information in the existing debugfs cannot make it clear why the address is not consecutive.For example,
cat/sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff
1: 0x0000000090200000..0x00000000905fffff
2: 0x0000000090600000..0x0000000092ffffff
3: 0x0000000093000000..0x00000000973fffff
4: 0x0000000097400000..0x00000000b71fffff
5: 0x00000000c0000000..0x00000000dfffffff
6: 0x00000000e2500000..0x00000000f87fffff
7: 0x00000000f8800000..0x00000000fa7fffff
8: 0x00000000fa800000..0x00000000fd3effff
9: 0x00000000fd3f0000..0x00000000fd3fefff
10: 0x00000000fd3ff000..0x00000000fd7fffff
11: 0x00000000fd800000..0x00000000fd901fff
12: 0x00000000fd902000..0x00000000fd909fff
13: 0x00000000fd90a000..0x00000000fd90bfff
14: 0x00000000fd90c000..0x00000000ffffffff
15: 0x0000000880000000..0x0000000affffffffSo we can add flags and nid to this debugfs.
For example,
cat/sys/kernel/debug/memblock/memory
Quoted 16 lines
0: 0x0000000080000000..0x00000000901fffff NONE 0 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 2: 0x0000000090600000..0x0000000092ffffff NONE 0 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 4: 0x0000000097400000..0x00000000b71fffff NONE 0 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 15: 0x0000000880000000..0x0000000affffffff NONE 0
Although, Mike had suggested to keep these flags print last, above format looks good as well.
Quoted 14 lines
Signed-off-by Yuwei Guan <[email protected]>---
v3:
- show string value for each memblock flag--- mm/memblock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)mm/memblock.c +0
-0
mm/memblock.c static int memblock_debug_show(struct seq_file *m, void *private) · line 2147
Quoted 5 lines
mm/memblock.c +2
-0@@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private)struct memblock_region *reg;int i;phys_addr_t end; +static const char flagname[BITS_PER_LONG ][8 ] = { + [0 ... (BITS_PER_LONG -1 )] ="?" ,
Minor nit -
Although checkpatch does not complain, should there be spaces between the operator and operands e.g (BITS_PER_LONG - 1).
mm/memblock.c static int memblock_debug_show(struct seq_file *m, void *private) · line 2153
Quoted 6 lines
mm/memblock.c +6
-0+ + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + };
Also, BITS_PER_LONG sized array is really required here ? as there are just four available memblock flags.
Quoted 13 lines
mm/memblock.c +3
-1for (i =0 ; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size -1 ;seq_printf (m,"%4d: " , i); -seq_printf (m,"%pa..%pa\n" , ®->base, &end); +seq_printf (m,"%pa..%pa " , ®->base, &end); +seq_printf (m,"%8s " , reg->flags ? flagname[ilog2 (reg->flags)] :"NONE" ); +seq_printf (m,"%4d\n" ,memblock_get_region_node (reg)); }return 0 ; }
Quoted 84 lines · Anshuman Khandual <[email protected]> 于2023年5月18日周四 18:12写道:
Quoted 28 lines · Yuwei Guan
Currently, the memblock debugfs can display the count of
memblock_typeand the base and end of the reg. However, when memblock_mark_*() ormemblock_set_node()is executed on some range, the information in the existing debugfs cannot make it clear why the address is not consecutive.For example,
cat/sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff
1: 0x0000000090200000..0x00000000905fffff
2: 0x0000000090600000..0x0000000092ffffff
3: 0x0000000093000000..0x00000000973fffff
4: 0x0000000097400000..0x00000000b71fffff
5: 0x00000000c0000000..0x00000000dfffffff
6: 0x00000000e2500000..0x00000000f87fffff
7: 0x00000000f8800000..0x00000000fa7fffff
8: 0x00000000fa800000..0x00000000fd3effff
9: 0x00000000fd3f0000..0x00000000fd3fefff
10: 0x00000000fd3ff000..0x00000000fd7fffff
11: 0x00000000fd800000..0x00000000fd901fff
12: 0x00000000fd902000..0x00000000fd909fff
13: 0x00000000fd90a000..0x00000000fd90bfff
14: 0x00000000fd90c000..0x00000000ffffffff
15: 0x0000000880000000..0x0000000affffffffSo we can add flags and nid to this debugfs.
For example,
cat/sys/kernel/debug/memblock/memoryQuoted 16 lines
0: 0x0000000080000000..0x00000000901fffff NONE 0 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 2: 0x0000000090600000..0x0000000092ffffff NONE 0 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 4: 0x0000000097400000..0x00000000b71fffff NONE 0 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 15: 0x0000000880000000..0x0000000affffffff NONE 0Although, Mike had suggested to keep these flags print last, above format looks good as well.
Quoted 14 lines
Signed-off-by Yuwei Guan <[email protected]>---
v3:
- show string value for each memblock flag--- mm/memblock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)mm/memblock.c +0
-0mm/memblock.c static int memblock_debug_show(struct seq_file *m, void *private) · line 2147
Quoted 5 lines
mm/memblock.c +2
-0@@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private)struct memblock_region *reg;int i;phys_addr_t end; +static const char flagname[BITS_PER_LONG ][8 ] = { + [0 ... (BITS_PER_LONG -1 )] ="?" ,Minor nit -
Although checkpatch does not complain, should there be spaces between the operator and operands e.g (
BITS_PER_LONG- 1).mm/memblock.c static int memblock_debug_show(struct seq_file *m, void *private) · line 2153
Quoted 6 lines
mm/memblock.c +6
-0+ + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + };
Quoted 3 lines
Also,
BITS_PER_LONGsized array is really required here ? as there are just four available memblock flags.
Hi Anshuman,
The main reason to use BITS_PER_LONG is to reserve.
If the flagname buffer is (ilog2(MEMBLOCK_DRIVER_MANAGED) + 1), memblock_flags adds a new attribute and does not add its name in debugfs, it will cause an overflow.
But BITS_PER_LONG is too wasteful, so I implement a new solution. Please help to check it.
struct memblock_type *type = m->private;
struct memblock_region *reg;
- int i;
+ int i, j;
phys_addr_t end;
+ static const char *flagname[] = {
+ [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG",
+ [ilog2(MEMBLOCK_MIRROR)] = "MIRROR",
+ [ilog2(MEMBLOCK_NOMAP)] = "NOMAP",
+ [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG",+ };
for (i = 0; i < type->cnt; i++) {
reg = &type->regions[i];
end = reg->base + reg->size - 1;
seq_printf(m, "%4d: ", i);
- seq_printf(m, "%pa..%pa\n", ®->base, &end);
+ seq_printf(m, "%pa..%pa ", ®->base, &end);
+ seq_printf(m, "%4d ", memblock_get_region_node(reg));
+ if (reg->flags) {+ for (j = 0; j < ARRAY_SIZE(flagname); j++) {
+ if (reg->flags & (1U << j)) {
+ seq_printf(m, "%s\n", flagname[j]);
+ break;
+ }
+ }
+ if (j == ARRAY_SIZE(flagname))
+ seq_printf(m, "%s\n", "UNKNOWN");
+ } else {
+ seq_printf(m, "%s\n", "NONE");
+ }
}
Quoted 13 lines
Quoted 13 lines
mm/memblock.c +3
-1for (i =0 ; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size -1 ;seq_printf (m,"%4d: " , i); -seq_printf (m,"%pa..%pa\n" , ®->base, &end); +seq_printf (m,"%pa..%pa " , ®->base, &end); +seq_printf (m,"%8s " , reg->flags ? flagname[ilog2 (reg->flags)] :"NONE" ); +seq_printf (m,"%4d\n" ,memblock_get_region_node (reg)); }return 0 ; }
Quoted 85 lines · Yuwei Guan
Quoted 84 lines · Anshuman Khandual <[email protected]> 于2023年5月18日周四 18:12写道:
Quoted 28 lines · Yuwei Guan
Currently, the memblock debugfs can display the count of
memblock_typeand the base and end of the reg. However, when memblock_mark_*() ormemblock_set_node()is executed on some range, the information in the existing debugfs cannot make it clear why the address is not consecutive.For example,
cat/sys/kernel/debug/memblock/memory
0: 0x0000000080000000..0x00000000901fffff
1: 0x0000000090200000..0x00000000905fffff
2: 0x0000000090600000..0x0000000092ffffff
3: 0x0000000093000000..0x00000000973fffff
4: 0x0000000097400000..0x00000000b71fffff
5: 0x00000000c0000000..0x00000000dfffffff
6: 0x00000000e2500000..0x00000000f87fffff
7: 0x00000000f8800000..0x00000000fa7fffff
8: 0x00000000fa800000..0x00000000fd3effff
9: 0x00000000fd3f0000..0x00000000fd3fefff
10: 0x00000000fd3ff000..0x00000000fd7fffff
11: 0x00000000fd800000..0x00000000fd901fff
12: 0x00000000fd902000..0x00000000fd909fff
13: 0x00000000fd90a000..0x00000000fd90bfff
14: 0x00000000fd90c000..0x00000000ffffffff
15: 0x0000000880000000..0x0000000affffffffSo we can add flags and nid to this debugfs.
For example,
cat/sys/kernel/debug/memblock/memoryQuoted 16 lines
0: 0x0000000080000000..0x00000000901fffff NONE 0 1: 0x0000000090200000..0x00000000905fffff NOMAP 0 2: 0x0000000090600000..0x0000000092ffffff NONE 0 3: 0x0000000093000000..0x00000000973fffff NOMAP 0 4: 0x0000000097400000..0x00000000b71fffff NONE 0 5: 0x00000000c0000000..0x00000000dfffffff NONE 0 6: 0x00000000e2500000..0x00000000f87fffff NONE 0 7: 0x00000000f8800000..0x00000000fa7fffff NOMAP 0 8: 0x00000000fa800000..0x00000000fd3effff NONE 0 9: 0x00000000fd3f0000..0x00000000fd3fefff NOMAP 0 10: 0x00000000fd3ff000..0x00000000fd7fffff NONE 0 11: 0x00000000fd800000..0x00000000fd901fff NOMAP 0 12: 0x00000000fd902000..0x00000000fd909fff NONE 0 13: 0x00000000fd90a000..0x00000000fd90bfff NOMAP 0 14: 0x00000000fd90c000..0x00000000ffffffff NONE 0 15: 0x0000000880000000..0x0000000affffffff NONE 0Although, Mike had suggested to keep these flags print last, above format looks good as well.
Quoted 14 lines
Signed-off-by Yuwei Guan <[email protected]>---
v3:
- show string value for each memblock flag--- mm/memblock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)mm/memblock.c +0
-0mm/memblock.c static int memblock_debug_show(struct seq_file *m, void *private) · line 2147
Quoted 5 lines
mm/memblock.c +2
-0@@ -2143,13 +2143,23 @@ static int memblock_debug_show(struct seq_file *m, void *private)struct memblock_region *reg;int i;phys_addr_t end; +static const char flagname[BITS_PER_LONG ][8 ] = { + [0 ... (BITS_PER_LONG -1 )] ="?" ,Minor nit -
Although checkpatch does not complain, should there be spaces between the operator and operands e.g (
BITS_PER_LONG- 1).Quoted 6 lines
mm/memblock.c +6
-0+ + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + };
Quoted 8 lines
Quoted 3 lines
Also,
BITS_PER_LONGsized array is really required here ? as there are just four available memblock flags.Hi Anshuman,
The main reason to useBITS_PER_LONGis to reserve.
If the flagname buffer is (ilog2(MEMBLOCK_DRIVER_MANAGED)+ 1),memblock_flagsadds a new attribute and does not add its name in debugfs, it will cause an overflow.
Agreed.
Quoted 26 lines
But
BITS_PER_LONGis too wasteful, so I implement a new solution. Please help to check it.struct memblock_type *type = m->private; struct memblock_region *reg;(quoted diff) +12
-2- int i; + int i, j; phys_addr_t end; + static const char *flagname[] = { + [ilog2(MEMBLOCK_HOTPLUG)] = "HOTPLUG", + [ilog2(MEMBLOCK_MIRROR)] = "MIRROR", + [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", + [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", + }; for (i = 0; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size - 1; seq_printf(m, "%4d: ", i); - seq_printf(m, "%pa..%pa\n", ®->base, &end); + seq_printf(m, "%pa..%pa ", ®->base, &end); + seq_printf(m, "%4d ", memblock_get_region_node(reg)); + if (reg->flags) { + for (j = 0; j < ARRAY_SIZE(flagname); j++) { + if (reg->flags & (1U << j)) {
Review
Quoted 10 lines
(quoted diff) +9
-0+ seq_printf(m, "%s\n", flagname[j]); + break; + } + } + if (j == ARRAY_SIZE(flagname)) + seq_printf(m, "%s\n", "UNKNOWN"); + } else { + seq_printf(m, "%s\n", "NONE"); + } }
Please move the static array outside, just before this function and capture ARRAY_SIZE(flagname) in a local variable to make it compact.
Rest looks good.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
mm/memblock.c +3
-1for (i =0 ; i < type->cnt; i++) { reg = &type->regions[i]; end = reg->base + reg->size -1 ;seq_printf (m,"%4d: " , i); -seq_printf (m,"%pa..%pa\n" , ®->base, &end); +seq_printf (m,"%pa..%pa " , ®->base, &end); +seq_printf (m,"%8s " , reg->flags ? flagname[ilog2 (reg->flags)] :"NONE" ); +seq_printf (m,"%4d\n" ,memblock_get_region_node (reg)); }return 0 ; }