[RFC PATCH 01/16] mm: Page Alloc Hogger module
From: Juan Yescas
Date: Thu Jul 23 2026 - 03:51:20 EST
This patch contains the skeleton for the Pagei Alloc Hogger. It creates the
"mm" dir that will be the base directory that will contain the "free" file
and the "node-<x>" dirs.
Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---
mm/Kconfig.debug | 12 +++++
mm/Makefile | 1 +
mm/page_alloc_hogger.c | 115 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+)
create mode 100644 mm/page_alloc_hogger.c
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 7638d75b27db..c8fcecdca6ac 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -309,3 +309,15 @@ config PER_VMA_LOCK_STATS
overhead in the page fault path.
If in doubt, say N.
+
+config PAGEALLOC_HOGGER
+ bool "Alloc pages from different nodes, zones, migrate types and orders"
+ depends on DEBUG_FS
+ help
+ Say Y to alloc pages from different nodes, zones, migrate type and
+ orders using the debug fs filesystem. This helps to generate memory
+ pressure easily. This is useful to debug memory reclaims issues,
+ OOM triggers, page migration issues, etc.
+
+ If in doubt, say N.
+
diff --git a/mm/Makefile b/mm/Makefile
index 2d0570a16e5b..b48f2ac6ee80 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -133,6 +133,7 @@ obj-$(CONFIG_IDLE_PAGE_TRACKING) += page_idle.o
obj-$(CONFIG_DEBUG_PAGEALLOC) += debug_page_alloc.o
obj-$(CONFIG_DEBUG_PAGE_REF) += debug_page_ref.o
obj-$(CONFIG_DAMON) += damon/
+obj-$(CONFIG_PAGEALLOC_HOGGER) += page_alloc_hogger.o
obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o
obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o
obj-$(CONFIG_ZONE_DEVICE) += memremap.o
diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
new file mode 100644
index 000000000000..dfdc2ee2eafe
--- /dev/null
+++ b/mm/page_alloc_hogger.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Page allocator DebugFS Interface
+ * Author: Juan Yescas <jyescas@xxxxxxxxxx>
+ *
+ * This module allows to make page allocs per node, zone, migrate type
+ * and order using the DebugFS filesystem.
+ *
+ * When this module is installed and the debugfs is mounted, the "mm" directory
+ " will be created in <debugfs mount point>/mm" directory. Under this directory,
+ * there will be subdirs to select the nodes, zones, orders and migrate type.
+ *
+ * For example:
+ *
+ * /sys/kernel/debug/mm/
+ * |-- free
+ * `-- node-0
+ * |-- zone-DMA
+ * | |-- order-0
+ * | | |-- migrate-HighAtomic
+ * | | | `-- nr_pages_allocs
+ * | | |-- migrate-Movable
+ * | | | `-- nr_pages_allocs
+ * | | |-- migrate-Reclaimable
+ * | | | `-- nr_pages_allocs
+ * | | `-- migrate-Unmovable
+ * | | `-- nr_pages_allocs
+ * | |-- ...
+ * | |
+ * | `-- order-9
+ * | |-- migrate-HighAtomic
+ * | | `-- nr_pages_allocs
+ * | |-- migrate-Movable
+ * | | `-- nr_pages_allocs
+ * | |-- migrate-Reclaimable
+ * | | `-- nr_pages_allocs
+ * | `-- migrate-Unmovable
+ * | `-- nr_pages_allocs
+ * `-- zone-Normal
+ * |-- order-0
+ * | |-- migrate-HighAtomic
+ * | | `-- nr_pages_allocs
+ * | |-- migrate-Movable
+ * | | `-- nr_pages_allocs
+ * | |-- migrate-Reclaimable
+ * | | `-- nr_pages_allocs
+ * | `-- migrate-Unmovable
+ * | `-- nr_pages_allocs
+ * |-- ....
+ * |
+ * `-- order-9
+ * |-- migrate-HighAtomic
+ * | `-- nr_pages_allocs
+ * |-- migrate-Movable
+ * | `-- nr_pages_allocs
+ * |-- migrate-Reclaimable
+ * | `-- nr_pages_allocs
+ * `-- migrate-Unmovable
+ * `-- nr_pages_allocs
+ *
+ * Usage:
+ *
+ * 1. To trigger the allocation, navigate to the debugfs path corresponding
+ * to your target node, memory zone, allocation order, and migration type,
+ * then write the requested allocation count to nr_pages_allocs.
+ *
+ * For example, to make 3 allocs of order 9, Migrate Type Movable,
+ * Zone Normal and Node 0, run:
+ *
+ * $ echo 3 > /sys/kernel/debug/mm/node-0/zone-Normal/order-9/migrate-Movable/nr_pages_allocs
+ *
+ * 2. For each allocation created, a corresponding file named sequentially
+ * (1, 2, n) will appear in that directory.
+ *
+ * $ ls /sys/kernel/debug/mm/node-0/zone-Normal/order-9/migrate-Movable/
+ * 1 2 3 nr_pages_allocs
+ *
+ * 3. To free the allocation, write the allocation file name in /sys/kernel/debug/mm/free.
+ * For example, to release the 2nd allocation run:
+ *
+ * $ echo 2 > /sys/kernel/debug/mm/free
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/errno.h>
+#include <linux/debugfs.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/printk.h>
+
+struct dentry *mmdir;
+
+static int __init page_alloc_hogger_debugfs_init(void)
+{
+ mmdir = debugfs_create_dir("mm", NULL);
+ if (IS_ERR(mmdir)) {
+ pr_err("Unable to create mm directory");
+ return PTR_ERR(mmdir);
+ }
+
+ return 0;
+}
+
+static void __exit page_alloc_hogger_debugfs_exit(void)
+{
+ debugfs_remove_recursive(mmdir);
+}
+
+module_init(page_alloc_hogger_debugfs_init);
+module_exit(page_alloc_hogger_debugfs_exit);
+
+MODULE_AUTHOR("Juan Yescas");
+MODULE_DESCRIPTION("Module to alloc pages to generate memory pressure");
+MODULE_LICENSE("GPL");
--
2.55.0.229.g6434b31f56-goog