[v2] mm/vmstat: Add order's information for extfrag_index and unusable_index

Message ID 20240229141443.99408-1-gehao@kylinos.cn
State New
Headers
Series [v2] mm/vmstat: Add order's information for extfrag_index and unusable_index |

Commit Message

Hao Ge Feb. 29, 2024, 2:14 p.m. UTC
  Current cat /sys/kernel/debug/extfrag/extfrag_index and
/sys/kernel/debug/extfrag/unusable_index is not friendly to userspace.

We should add order's information so that users can clearly understand
the situation of each order at a glance like pagetypeinfo.

before:
cat /sys/kernel/debug/extfrag/extfrag_index:
Node 0, zone    DMA32  ...... ...... ...... ......
Node 0, zone   Normal  ...... ...... ...... ......

cat /sys/kernel/debug/extfrag/unusable_index:
Node 0, zone    DMA32 ..... ..... ..... .....
Node 0, zone   Normal ..... ..... ..... .....

after:
cat /sys/kernel/debug/extfrag/extfrag_index:
Extfrag index at order:       0      1      2      3
Node 0, zone        DMA  ...... ...... ...... ......
Node 0, zone     Normal  ...... ...... ...... ......

cat /sys/kernel/debug/extfrag/unusable_index:
Unusable index at order:     0     1     2     3
Node 0, zone         DMA ..... ..... ..... .....
Node 0, zone      Normal ..... ..... ..... .....

Signed-off-by: Hao Ge <gehao@kylinos.cn>

---
v1 -> v2: Use '.' to replace related values for commit message
---
 mm/vmstat.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
  

Comments

Andrew Morton Feb. 29, 2024, 6:40 p.m. UTC | #1
On Thu, 29 Feb 2024 22:14:43 +0800 Hao Ge <gehao@kylinos.cn> wrote:

> Current cat /sys/kernel/debug/extfrag/extfrag_index and
> /sys/kernel/debug/extfrag/unusable_index is not friendly to userspace.
> 
> We should add order's information so that users can clearly understand
> the situation of each order at a glance like pagetypeinfo.
> 
> before:
> cat /sys/kernel/debug/extfrag/extfrag_index:
> Node 0, zone    DMA32  ...... ...... ...... ......
> Node 0, zone   Normal  ...... ...... ...... ......
> 
> cat /sys/kernel/debug/extfrag/unusable_index:
> Node 0, zone    DMA32 ..... ..... ..... .....
> Node 0, zone   Normal ..... ..... ..... .....
> 
> after:
> cat /sys/kernel/debug/extfrag/extfrag_index:
> Extfrag index at order:       0      1      2      3
> Node 0, zone        DMA  ...... ...... ...... ......
> Node 0, zone     Normal  ...... ...... ...... ......
> 
> cat /sys/kernel/debug/extfrag/unusable_index:
> Unusable index at order:     0     1     2     3
> Node 0, zone         DMA ..... ..... ..... .....
> Node 0, zone      Normal ..... ..... ..... .....
> 

This may break existing parsers of this file.

And that would be allowed if these files were under debugfs.  But
they're under sysfs/debug, where the rules are less clear.

Still, it's unclear to me that the benefit is worth this risk.  What do
others think?
  
Hao Ge Feb. 29, 2024, 11:13 p.m. UTC | #2
> On Mar 1, 2024, at 02:40, Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> On Thu, 29 Feb 2024 22:14:43 +0800 Hao Ge <gehao@kylinos.cn> wrote:
> 
>> Current cat /sys/kernel/debug/extfrag/extfrag_index and
>> /sys/kernel/debug/extfrag/unusable_index is not friendly to userspace.
>> 
>> We should add order's information so that users can clearly understand
>> the situation of each order at a glance like pagetypeinfo.
>> 
>> before:
>> cat /sys/kernel/debug/extfrag/extfrag_index:
>> Node 0, zone    DMA32  ...... ...... ...... ......
>> Node 0, zone   Normal  ...... ...... ...... ......
>> 
>> cat /sys/kernel/debug/extfrag/unusable_index:
>> Node 0, zone    DMA32 ..... ..... ..... .....
>> Node 0, zone   Normal ..... ..... ..... .....
>> 
>> after:
>> cat /sys/kernel/debug/extfrag/extfrag_index:
>> Extfrag index at order:       0      1      2      3
>> Node 0, zone        DMA  ...... ...... ...... ......
>> Node 0, zone     Normal  ...... ...... ...... ......
>> 
>> cat /sys/kernel/debug/extfrag/unusable_index:
>> Unusable index at order:     0     1     2     3
>> Node 0, zone         DMA ..... ..... ..... .....
>> Node 0, zone      Normal ..... ..... ..... .....
>> 
> 
> This may break existing parsers of this file.
> 
> And that would be allowed if these files were under debugfs.  But
> they're under sysfs/debug, where the rules are less clear.
> 
> Still, it's unclear to me that the benefit is worth this risk.  What do
> others think?

Thank you for your reply. This is something I didn't expect. I think it's better to keep it in its original condition to avoid compatibility issues with some tools.
  

Patch

diff --git a/mm/vmstat.c b/mm/vmstat.c
index db79935e4a54..fe0b811e9d7f 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -2178,7 +2178,7 @@  static void unusable_show_print(struct seq_file *m,
 	int index;
 	struct contig_page_info info;
 
-	seq_printf(m, "Node %d, zone %8s ",
+	seq_printf(m, "Node %d, zone %11s ",
 				pgdat->node_id,
 				zone->name);
 	for (order = 0; order < NR_PAGE_ORDERS; ++order) {
@@ -2201,12 +2201,19 @@  static void unusable_show_print(struct seq_file *m,
  */
 static int unusable_show(struct seq_file *m, void *arg)
 {
+	int order;
 	pg_data_t *pgdat = (pg_data_t *)arg;
 
 	/* check memoryless node */
 	if (!node_state(pgdat->node_id, N_MEMORY))
 		return 0;
 
+	/* Print header */
+	seq_printf(m, "%s ", "Unusable index at order:");
+	for (order = 0; order < NR_PAGE_ORDERS; ++order)
+		seq_printf(m, "%5d ", order);
+	seq_putc(m, '\n');
+
 	walk_zones_in_node(m, pgdat, true, false, unusable_show_print);
 
 	return 0;
@@ -2230,7 +2237,7 @@  static void extfrag_show_print(struct seq_file *m,
 	/* Alloc on stack as interrupts are disabled for zone walk */
 	struct contig_page_info info;
 
-	seq_printf(m, "Node %d, zone %8s ",
+	seq_printf(m, "Node %d, zone %10s ",
 				pgdat->node_id,
 				zone->name);
 	for (order = 0; order < NR_PAGE_ORDERS; ++order) {
@@ -2247,8 +2254,15 @@  static void extfrag_show_print(struct seq_file *m,
  */
 static int extfrag_show(struct seq_file *m, void *arg)
 {
+	int order;
 	pg_data_t *pgdat = (pg_data_t *)arg;
 
+	/* Print header */
+	seq_printf(m, "%s ", "Extfrag index at order:");
+	for (order = 0; order < NR_PAGE_ORDERS; ++order)
+		seq_printf(m, "%6d ", order);
+	seq_putc(m, '\n');
+
 	walk_zones_in_node(m, pgdat, true, false, extfrag_show_print);
 
 	return 0;