[PATCH v2 1/2] ref_tracker: add a top level debugfs directory for ref_tracker

Jeff Layton
2025-04-08T13:36:53Z

Add a new "ref_tracker" directory in debugfs. Each individual refcount
tracker can add a directory or files under there to display info about
currently-held references.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
include/linux/ref_tracker.h | 3 +++
lib/ref_tracker.c | 15 +++++++++++++++
2 files changed, 18 insertions(+)

diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h
index 8eac4f3d52547ccbaf9dcd09962ce80d26fbdff8..16fb6ec0cc7adc24457cfab13ee3994d85c15b39 100644
--- a/include/linux/ref_tracker.h
+++ b/include/linux/ref_tracker.h
@@ -22,6 +22,9 @@ struct ref_tracker_dir {
};

#ifdef CONFIG_REF_TRACKER
+#ifdef CONFIG_DEBUG_FS
+extern struct dentry *ref_tracker_debug_dir;
+#endif /* CONFIG_DEBUG_FS */

static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
unsigned int quarantine_count,
diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index cf5609b1ca79361763abe5a3a98484a3ee591ff2..136723eab6b17ae07132c659fd1d8b0690d8c2d9 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -12,6 +12,8 @@
#define REF_TRACKER_STACK_ENTRIES 16
#define STACK_BUF_SIZE 1024

+struct dentry *ref_tracker_debug_dir;
+
struct ref_tracker {
struct list_head head; /* anchor into dir->list or dir->quarantine */
bool dead;
@@ -273,3 +275,16 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
return 0;
}
EXPORT_SYMBOL_GPL(ref_tracker_free);
+
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+
+static int __init ref_tracker_debug_init(void)
+{
+ ref_tracker_debug_dir = debugfs_create_dir("ref_tracker", NULL);
+ if (IS_ERR(ref_tracker_debug_dir))
+ return PTR_ERR(ref_tracker_debug_dir);
+ return 0;
+}
+late_initcall(ref_tracker_debug_init);
+#endif /* CONFIG_DEBUG_FS */

--
2.49.0