[RFC PATCH 13/16] mm: Create the file asociated with an allocation
From: Juan Yescas
Date: Thu Jul 23 2026 - 03:59:49 EST
This change creates the file asociated with an allocation. The
name of the file will be given by incrementing the atomic
long "allocs_file_seq".
This file will be used to free the alocation when the user
requests it.
Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---
mm/page_alloc_hogger.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index 7f6eebdd5197..203b71a25e64 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -186,12 +186,26 @@ inline void set_migrate_type_to_alloc_from(int migrate_type, gfp_t *flags_ptr)
}
}
+static ssize_t page_alloc_read(struct file *file, char __user *ubuf,
+ size_t cnt, loff_t *ppos)
+{
+ /* Which information should be print about the page or allocation? */
+ return 0;
+}
+
+static const struct file_operations page_alloc_fops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = page_alloc_read,
+};
+
static int make_alloc(struct req_alloc *req,
gfp_t flags, unsigned long *alloc_id)
{
struct page_alloc *pa;
struct page *page;
char new_alloc_name[12];
+ struct dentry *new_alloc_dentry;
int ret;
page = alloc_pages_node_noprof(req->node_idx, flags, req->order);
@@ -210,14 +224,26 @@ static int make_alloc(struct req_alloc *req,
snprintf(new_alloc_name, sizeof(new_alloc_name), "%lu",
*alloc_id);
+ new_alloc_dentry = debugfs_create_file(
+ new_alloc_name, 0644, req->parentdir,
+ pa, &page_alloc_fops);
+ if (IS_ERR(new_alloc_dentry)) {
+ ret = PTR_ERR(new_alloc_dentry);
+ goto erase_xa_entry;
+ }
+
pa->req_alloc = req;
pa->page = page;
+ pa->alloc_dentry = new_alloc_dentry;
} else {
return -ENOMEM;
}
return 0;
+erase_xa_entry:
+ xa_erase(&allocs_xa, *alloc_id);
+
free_page_alloc:
kmem_cache_free(page_alloc_cache, pa);
--
2.55.0.229.g6434b31f56-goog