[RFC PATCH v2 03/16] mm: Define the caches for the structs req_alloc and page_alloc

From: Juan Yescas

Date: Wed Aug 05 2026 - 21:14:36 EST


This change defines and initializes the caches for the structs req_alloc
and page_alloc.

Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---

Changes in v2:
- Use static for the kmem_cache variables.
- Use \n for the pr_err messages.

mm/page_alloc_hogger.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index caeb2e5e8579..175f479c487b 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -85,9 +85,12 @@

#include <linux/errno.h>
#include <linux/debugfs.h>
+#include <linux/gfp.h>
+#include <linux/gfp_types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/printk.h>
+#include <linux/slab.h>

static struct dentry *mmdir;

@@ -119,20 +122,55 @@ struct page_alloc {
struct dentry *alloc_dentry;
};

+static struct kmem_cache *req_alloc_cache;
+static struct kmem_cache *page_alloc_cache;
+
static int __init page_alloc_hogger_debugfs_init(void)
{
+ int ret;
+
+ req_alloc_cache = kmem_cache_create(
+ "req_alloc_cache", sizeof(struct req_alloc), 0,
+ SLAB_HWCACHE_ALIGN, NULL);
+ if (!req_alloc_cache) {
+ pr_err("The req_alloc_cache couldn't be created\n");
+ ret = -ENOMEM;
+ goto error_exit;
+ }
+
+ page_alloc_cache = kmem_cache_create(
+ "page_alloc_cache", sizeof(struct page_alloc), 0,
+ SLAB_HWCACHE_ALIGN, NULL);
+ if (!page_alloc_cache) {
+ pr_err("The page_alloc_cache couldn't be created\n");
+ ret = -ENOMEM;
+ goto clean_req_alloc_cache;
+ }
+
mmdir = debugfs_create_dir("mm", NULL);
if (IS_ERR(mmdir)) {
pr_err("Unable to create mm directory\n");
- return PTR_ERR(mmdir);
+ ret = PTR_ERR(mmdir);
+ goto clean_page_alloc_cache;
}

return 0;
+
+clean_page_alloc_cache:
+ kmem_cache_destroy(page_alloc_cache);
+
+clean_req_alloc_cache:
+ kmem_cache_destroy(req_alloc_cache);
+
+error_exit:
+ return ret;
}

static void __exit page_alloc_hogger_debugfs_exit(void)
{
debugfs_remove_recursive(mmdir);
+ kmem_cache_destroy(req_alloc_cache);
+ kmem_cache_destroy(page_alloc_cache);
}

module_init(page_alloc_hogger_debugfs_init);
--
2.55.0.629.g250fe7f194-goog