Skip to contentSkip to conversation

mm/vmstat: add header line to /proc/buddyinfo output

PATCH In review Ye Liu 3 participants 8 messages Sep 18, 2025

Subsystems (2)
lore
Share & tools
lore

Ye Liu

author
#0 lore raw

PATCH 1/1 mm/vmstat: add header line to /proc/buddyinfo output

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:

Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

After:

Free pages per order       0      1      2      3      4      5      6 ...
Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

---
 mm/vmstat.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/vmstat.c +7 -0
index bb09c032eecf..e9606457ab91 100644
@@ -1574,7 +1574,14 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  */
 static int frag_show(struct seq_file *m, void *arg)
 {
+	int order;
 	pg_data_t *pgdat = (pg_data_t *)arg;
+	/* Print header */
+	seq_printf(m, "%-21s ", "Free pages per 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, frag_show_print);
 	return 0;
 }
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 8 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:

Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...
Quoted 7 lines

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

After:

Free pages per order       0      1      2      3      4      5      6 ...
Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Quoted 28 lines
---
 mm/vmstat.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/vmstat.c +7 -0
index bb09c032eecf..e9606457ab91 100644
@@ -1574,7 +1574,14 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  */
 static int frag_show(struct seq_file *m, void *arg)
 {
+	int order;
 	pg_data_t *pgdat = (pg_data_t *)arg;
+	/* Print header */
+	seq_printf(m, "%-21s ", "Free pages per 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, frag_show_print);
 	return 0;
 }
Signature · 1 line
2.43.0
Signature · 2 lines
Michal Hocko
SUSE Labs
author
#2 lore raw
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:

Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

Quoted 9 lines
Quoted 5 lines

After:

Free pages per order       0      1      2      3      4      5      6 ...
Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

Page block order: 9
Pages per block: 512

Free pages count per migrate type at order 0 1 2 3 ...
Node 0, zone DMA, type Unmovable 0 0 0 ...

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

Quoted 29 lines
Quoted 28 lines
---
 mm/vmstat.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/vmstat.c +7 -0
index bb09c032eecf..e9606457ab91 100644
@@ -1574,7 +1574,14 @@ static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  */
 static int frag_show(struct seq_file *m, void *arg)
 {
+	int order;
 	pg_data_t *pgdat = (pg_data_t *)arg;
+	/* Print header */
+	seq_printf(m, "%-21s ", "Free pages per 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, frag_show_print);
 	return 0;
 }
Signature · 1 line
2.43.0
Signature · 2 lines
Thanks,
Ye Liu
#3 lore raw
Quoted 33 lines · Ye Liu
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:

Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

Quoted 9 lines
Quoted 5 lines

After:

Free pages per order       0      1      2      3      4      5      6 ...
Node 0, zone      DMA      0      0      0      0      0      0      0 ...
Node 0, zone    DMA32      5      8      6      6      7      5      8 ...

Node 0, zone Normal 1113 351 138 65 38 31 25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

Page block order: 9
Pages per block: 512

Quoted 8 lines

Free pages count per migrate type at order 0 1 2 3 ...
Node 0, zone DMA, type Unmovable 0 0 0 ...

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

What if there is a single one out there that has hardcoded to skip the first line only?

Signature · 3 lines
Cheers

David / dhildenb
author
#4 lore raw
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Ye Liu
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:
Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Quoted 9 lines
Quoted 5 lines

After:
Free pages per order       0      1      2      3      4      5      6 ... Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

   Page block order: 9
   Pages per block: 512

   Free pages count per migrate type at order   0 1 2 3 ... Node 0, zone DMA, type Unmovable             0 0 0 ...

Quoted 7 lines
Quoted 5 lines

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

What if there is a single one out there that has hardcoded to skip the first line only?

I understand there may be no way to be fully compatible with all existing parsers. However, /proc/buddyinfo is essentially raw data intended for human and tool consumption, and parsers are expected to be robust against format changes.

Adding a '#' prefix to the header would allow most parsers to skip it, but it still changes the file output and cannot fully guarantee that no external tool will be affected.

Quoted 1 line
Signature · 2 lines
Thanks,
Ye Liu
reviewer
#5 lore raw
Quoted 46 lines · Ye Liu
Quoted 43 lines · David Hildenbrand
Quoted 41 lines · Ye Liu
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:
Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Quoted 9 lines
Quoted 5 lines

After:
Free pages per order       0      1      2      3      4      5      6 ... Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

   Page block order: 9
   Pages per block: 512

   Free pages count per migrate type at order   0 1 2 3 ... Node 0, zone DMA, type Unmovable             0 0 0 ...

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

Quoted 6 lines
Quoted 1 line

What if there is a single one out there that has hardcoded to skip the first line only?

I understand there may be no way to be fully compatible with all existing parsers. However, /proc/buddyinfo is essentially raw data intended for human and tool consumption, and parsers are expected to be robust against format changes.

I am pretty sure you can create a trivial wrapper to print that header, right?

Quoted 3 lines

Adding a '#' prefix to the header would allow most parsers to skip it, but it still changes the file output and cannot fully guarantee that no external tool will be affected.

That still assumes that they expect something like that.
We are trying really hard to not break existing userspace even if it is not written in a robust way. That is simply how Linux kernel handles all the existing interfaces. There must be a very serious reason to add a change that might _theoretically_ breaker existing userspace. What you are proposing here is not such a reason as it is trivial to achieve what you want from the userspace.

NAK to the change.

Signature · 2 lines
Michal Hocko
SUSE Labs
author
#6 lore raw
Quoted 69 lines · Michal Hocko
Quoted 46 lines · Ye Liu
Quoted 43 lines · David Hildenbrand
Quoted 41 lines · Ye Liu
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:
Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Quoted 9 lines
Quoted 5 lines

After:
Free pages per order       0      1      2      3      4      5      6 ... Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

   Page block order: 9
   Pages per block: 512

   Free pages count per migrate type at order   0 1 2 3 ... Node 0, zone DMA, type Unmovable             0 0 0 ...

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

Quoted 6 lines
Quoted 1 line

What if there is a single one out there that has hardcoded to skip the first line only?

I understand there may be no way to be fully compatible with all existing parsers. However, /proc/buddyinfo is essentially raw data intended for human and tool consumption, and parsers are expected to be robust against format changes.

I am pretty sure you can create a trivial wrapper to print that header, right?

Quoted 3 lines

Adding a '#' prefix to the header would allow most parsers to skip it, but it still changes the file output and cannot fully guarantee that no external tool will be affected.

That still assumes that they expect something like that.
We are trying really hard to not break existing userspace even if it is not written in a robust way. That is simply how Linux kernel handles all the existing interfaces. There must be a very serious reason to add a change that might _theoretically_ breaker existing userspace. What you are proposing here is not such a reason as it is trivial to achieve what you want from the userspace.

Quoted 1 line

NAK to the change.

I’ll drop this change.

Signature · 2 lines
Thanks,
Ye Liu
#7 lore raw
In reply to Ye Liu
Quoted 46 lines · Ye Liu
Quoted 43 lines · David Hildenbrand
Quoted 41 lines · Ye Liu
Quoted 11 lines · Michal Hocko
Quoted 10 lines · Ye Liu

From: Ye Liu <[email protected]>

Add a header line to /proc/buddyinfo that shows the order numbers for better readability and clarity.

Before:
Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Quoted 9 lines
Quoted 5 lines

After:
Free pages per order       0      1      2      3      4      5      6 ... Node 0, zone      DMA      0      0      0      0      0      0      0 ... Node 0, zone    DMA32      5      8      6      6      7      5      8 ... Node 0, zone   Normal   1113    351    138     65     38     31     25 ...

Why is this needed? And have you considered tha this might break existing parsers of the file?

Thanks for the review.

The reason for this change is simply to make /proc/buddyinfo self-describing. Right now you have to know which column is which order; with a header it’s obvious. This is similar to what /proc/pagetypeinfo already does, e.g.:

   Page block order: 9
   Pages per block: 512

   Free pages count per migrate type at order   0 1 2 3 ... Node 0, zone DMA, type Unmovable             0 0 0 ...

Regarding existing parsers: the patch does not change any of the existing “Node … zone …” lines, it only adds a single header line before them. Most parsers match “Node” lines and ignore everything else, so the risk should be low. If you know of any existing parser that this would break, please let me know so I can address it.

Quoted 6 lines
Quoted 1 line

What if there is a single one out there that has hardcoded to skip the first line only?

I understand there may be no way to be fully compatible with all existing parsers. However, /proc/buddyinfo is essentially raw data intended for human and tool consumption, and parsers are expected to be robust against format changes.

Let's take a look at a random one: pcp-buddyinfo.

Reading the source code [1] of the /proc/buddyinfo parser in refresh_proc_buddyinfo() I have my doubts:

    if ((fp = linux_statsfile("/proc/buddyinfo", buf, sizeof(buf))) == NULL)
        return -oserror();

    while (fgets(buf,sizeof(buf),fp) != NULL) {
        char node_name[128];
        char *zone_name;
        unsigned int values[SPLIT_MAX];

        i = read_node_name(buf, node_name);
        i+=6; /* erase ", zone" */
        read_buddyinfo(buf+i, read_buf, MAX_ORDER+1); /* read zone name and page order */
        zone_name=read_buf[0];
        for (i=0; i < MAX_ORDER; i++)
            values[i] = strtoul(read_buf[i+1], NULL, 10);
        for (i=0; i < proc_buddyinfo->nbuddys; i++) {
            if (strcmp(proc_buddyinfo->buddys[i].node_name, node_name)==0 &&
		strcmp(proc_buddyinfo->buddys[i].zone_name, zone_name)==0)
                break;
        }

Do you think that one would survive your changes?

https://github.com/performancecopilot/pcp/blob/main/src/pmdas/linux/proc_buddyinfo.c

Signature · 3 lines
Cheers

David / dhildenb