| From: Igor Belousov <igor.b@beldev.am> |
| Subject: mm/zblock: add debugfs |
| Date: Mon, 28 Apr 2025 08:49:24 +0200 |
| |
| Add debugfs entry to monitor number of blocks allocated for different |
| block sizes. |
| |
| Link: https://lkml.kernel.org/r/20250428064924.53496-1-igor.b@beldev.am |
| Signed-off-by: Igor Belousov <igor.b@beldev.am> |
| |
| Cc: David Hildenbrand <david@redhat.com> |
| Cc: Johannes Weiner <hannes@cmpxchg.org> |
| Cc: Nhat Pham <nphamcs@gmail.com> |
| Cc: Shakeel Butt <shakeel.butt@linux.dev> |
| Cc: Vitaly Wool <vitaly.wool@konsulko.se> |
| Cc: Yosry Ahmed <yosry.ahmed@linux.dev> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| mm/zblock.c | 24 ++++++++++++++++++++++++ |
| 1 file changed, 24 insertions(+) |
| |
| --- a/mm/zblock.c~mm-zblock-add-debugfs |
| +++ a/mm/zblock.c |
| @@ -17,6 +17,7 @@ |
| #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| |
| #include <linux/atomic.h> |
| +#include <linux/debugfs.h> |
| #include <linux/list.h> |
| #include <linux/mm.h> |
| #include <linux/module.h> |
| @@ -27,6 +28,7 @@ |
| #include "zblock.h" |
| |
| static struct rb_root block_desc_tree = RB_ROOT; |
| +static struct dentry *zblock_debugfs_root; |
| |
| /* Encode handle of a particular slot in the pool using metadata */ |
| static inline unsigned long metadata_to_handle(struct zblock_block *block, |
| @@ -111,6 +113,22 @@ static struct zblock_block *alloc_block( |
| return block; |
| } |
| |
| +static int zblock_blocks_show(struct seq_file *s, void *v) |
| +{ |
| + struct zblock_pool *pool = s->private; |
| + int i; |
| + |
| + for (i = 0; i < ARRAY_SIZE(block_desc); i++) { |
| + struct block_list *block_list = &pool->block_lists[i]; |
| + |
| + seq_printf(s, "%d: %ld blocks of %d pages (total %ld pages)\n", |
| + i, block_list->block_count, 1 << block_desc[i].order, |
| + block_list->block_count << block_desc[i].order); |
| + } |
| + return 0; |
| +} |
| +DEFINE_SHOW_ATTRIBUTE(zblock_blocks); |
| + |
| /***************** |
| * API Functions |
| *****************/ |
| @@ -139,6 +157,9 @@ static struct zblock_pool *zblock_create |
| INIT_LIST_HEAD(&block_list->active_list); |
| block_list->block_count = 0; |
| } |
| + |
| + debugfs_create_file("blocks", S_IFREG | 0444, zblock_debugfs_root, |
| + pool, &zblock_blocks_fops); |
| return pool; |
| } |
| |
| @@ -425,12 +446,15 @@ static int __init init_zblock(void) |
| return ret; |
| |
| zpool_register_driver(&zblock_zpool_driver); |
| + |
| + zblock_debugfs_root = debugfs_create_dir("zblock", NULL); |
| return 0; |
| } |
| |
| static void __exit exit_zblock(void) |
| { |
| zpool_unregister_driver(&zblock_zpool_driver); |
| + debugfs_remove_recursive(zblock_debugfs_root); |
| delete_rbtree(); |
| } |
| |
| _ |