[RFC PATCH v2 13/16] mm: Create the file associated with an allocation

Juan Yescas <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.kernel.mm,gmane.linux.kernel.mm
Message-ID <[email protected]>
This change creates the file associated 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 allocation when the user
requests it. The implementation will be included in a follow-up
patch of this topic.

Signed-off-by: Juan Yescas <[email protected]>
---

Changes in v2:
	- Update commit message.
	- Set file permissions to 0400 instead of 0644.

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

diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index e22247b7bd98..a70c924e4172 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -185,12 +185,26 @@ static inline void set_migrate_type_to_alloc_from(int migrate_type, gfp_t *flags
 	}
 }
 
+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[20];
+	struct dentry *new_alloc_dentry;
 	int ret;
 
 	page = alloc_pages_node_noprof(req->node_idx, flags, req->order);
@@ -205,18 +219,30 @@ 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, 0400, req->parentdir,
+			pa, &page_alloc_fops);
+		if (IS_ERR(new_alloc_dentry)) {
+			ret = PTR_ERR(new_alloc_dentry);
+			goto free_page_alloc;
+		}
+
 		pa->req_alloc = req;
 		pa->page = page;
+		pa->alloc_dentry = new_alloc_dentry;
 
 		ret = xa_insert(&allocs_xa, *alloc_id, pa, GFP_KERNEL);
 		if (ret)
-			goto free_page_alloc;
+			goto remove_alloc_dentry;
 	} else {
 		return -ENOMEM;
 	}
 
 	return 0;
 
+remove_alloc_dentry:
+	debugfs_remove(new_alloc_dentry);
+
 free_page_alloc:
 	kmem_cache_free(page_alloc_cache, pa);
 
-- 
2.55.0.629.g250fe7f194-goog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.