This change creates the "free" file and defines its file_operations to release the previously allocated pages. To release an allocation, the user will run: echo > /sys/kernel/debug/mm/free Signed-off-by: Juan Yescas --- mm/page_alloc_hogger.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index e65aac881ec7..5fe9c545e884 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -83,6 +83,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -94,6 +95,7 @@ #include #include #include +#include struct dentry *mmdir; @@ -331,6 +333,37 @@ static const struct file_operations req_page_alloc_fops = { .write = req_page_alloc_write, }; +/** + * free_page_alloc_write() - free the previously allocated pages. + * @file: File where the user is writing. + * @ubuf: Contains the name of the file the user wants to delete and have the + * memory associated with that file freed. + * @cnt: Size of @ubuf. + * @ppos: Current position in the file. + */ +static ssize_t free_page_alloc_write(struct file *file, + const char __user *ubuf, size_t cnt, + loff_t *ppos) +{ + int ret; + unsigned long alloc_id; + + ret = kstrtoul_from_user(ubuf, cnt, 10, &alloc_id); + if (ret) + return ret; + + ret = free_alloc_helper(alloc_id); + if (ret) + return ret; + + return cnt; +} + +static const struct file_operations free_page_alloc_fops = { + .owner = THIS_MODULE, + .write = free_page_alloc_write, +}; + /** * create_nr_pages_allocs_file() - Creates the file "nr_pages_allocs". * @@ -501,6 +534,7 @@ static inline int create_nodes_subdirs(struct dentry *mmdir) static int __init page_alloc_hogger_debugfs_init(void) { + struct dentry *free_file; int ret; req_alloc_cache = kmem_cache_create( @@ -532,6 +566,13 @@ static int __init page_alloc_hogger_debugfs_init(void) if (ret) goto clean_dir; + free_file = debugfs_create_file("free", 0644, mmdir, NULL, + &free_page_alloc_fops); + if (IS_ERR(free_file)) { + ret = PTR_ERR(free_file); + goto clean_dir; + } + return 0; clean_dir: -- 2.55.0.229.g6434b31f56-goog