diff mbox series

[RFC,2/5] mm/unmapped_alloc: add debugfs file similar to /proc/pagetypeinfo

Message ID 20230308094106.227365-3-rppt@kernel.org (mailing list archive)
State New
Headers show
Series Prototype for direct map awareness in page allocator | expand

Commit Message

Mike Rapoport March 8, 2023, 9:41 a.m. UTC
From: "Mike Rapoport (IBM)" <rppt@kernel.org>

Present statistics about unmapped_alloc in debugfs

Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
---
 mm/unmapped-alloc.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/mm/unmapped-alloc.c b/mm/unmapped-alloc.c
index fb2d54204a3c..f74640e9ce9f 100644
--- a/mm/unmapped-alloc.c
+++ b/mm/unmapped-alloc.c
@@ -3,6 +3,7 @@ 
 #include <linux/gfp.h>
 #include <linux/mmzone.h>
 #include <linux/printk.h>
+#include <linux/debugfs.h>
 #include <linux/spinlock.h>
 #include <linux/set_memory.h>
 
@@ -213,3 +214,37 @@  int unmapped_alloc_init(void)
 
 	return 0;
 }
+
+static int unmapped_alloc_debug_show(struct seq_file *m, void *private)
+{
+	int order;
+
+	seq_printf(m, "MAX_ORDER: %d\n", MAX_ORDER);
+	seq_putc(m, '\n');
+
+	seq_printf(m, "%-10s", "Order:");
+	for (order = 0; order < MAX_ORDER; ++order)
+		seq_printf(m, "%5d ", order);
+	seq_putc(m, '\n');
+
+	seq_printf(m, "%-10s", "Free:");
+	for (order = 0; order < MAX_ORDER; ++order)
+		seq_printf(m, "%5lu ", free_area[order].nr_free);
+	seq_putc(m, '\n');
+
+	seq_printf(m, "%-10s", "Cached:");
+	for (order = 0; order < MAX_ORDER; ++order)
+		seq_printf(m, "%5lu ", free_area[order].nr_cached);
+	seq_putc(m, '\n');
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(unmapped_alloc_debug);
+
+static int __init unmapped_alloc_init_late(void)
+{
+	debugfs_create_file("unmapped_alloc", 0444, NULL,
+			    NULL, &unmapped_alloc_debug_fops);
+	return 0;
+}
+late_initcall(unmapped_alloc_init_late);