Skip to contentSkip to conversation

mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jul 4, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: shrinkers: introduce debugfs interface for memory shrinkers
has been removed from the -mm tree. Its filename was
mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Roman Gushchin <[email protected]>
Subject: mm: shrinkers: introduce debugfs interface for memory shrinkers
Date: Tue, 31 May 2022 20:22:23 -0700

This commit introduces the /sys/kernel/debug/shrinker debugfs interface which provides an ability to observe the state of individual kernel memory shrinkers.

Because the feature adds some memory overhead (which shouldn't be large unless there is a huge amount of registered shrinkers), it's guarded by a config option (enabled by default).

This commit introduces the "count" interface for each shrinker registered in the system.

The output is in the following format:
<cgroup inode id> <nr of objects on node 0> <nr of objects on node 1>... <cgroup inode id> <nr of objects on node 0> <nr of objects on node 1>...
...

To reduce the size of output on machines with many thousands cgroups, if the total number of objects on all nodes is 0, the line is omitted.

If the shrinker is not memcg-aware or CONFIG_MEMCG is off, 0 is printed as cgroup inode id. If the shrinker is not numa-aware, 0's are printed for all nodes except the first one.

This commit gives debugfs entries simple numeric names, which are not very convenient. The following commit in the series will provide shrinkers with more meaningful names.

---

 include/linux/shrinker.h |   19 +++-
 lib/Kconfig.debug        |    9 +
 mm/Makefile              |    1 
 mm/shrinker_debug.c      |  168 +++++++++++++++++++++++++++++++++++++
 mm/vmscan.c              |    6 -
 5 files changed, 200 insertions(+), 3 deletions(-)
include/linux/shrinker.h renamed from include/linux/shrinker.h~mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers +18 -1
@@ -73,6 +73,10 @@ struct shrinker {
 	/* ID in shrinker_idr */
 	int id;
 #endif
+#ifdef CONFIG_SHRINKER_DEBUG
+	int debugfs_id;
+	struct dentry *debugfs_entry;
+#endif
 	/* objs pending delete, per node */
 	atomic_long_t *nr_deferred;
 };
@@ -94,4 +98,17 @@ extern int register_shrinker(struct shri
 extern void unregister_shrinker(struct shrinker *shrinker);
 extern void free_prealloced_shrinker(struct shrinker *shrinker);
 extern void synchronize_shrinkers(void);
-#endif
+
+#ifdef CONFIG_SHRINKER_DEBUG
+extern int shrinker_debugfs_add(struct shrinker *shrinker);
+extern void shrinker_debugfs_remove(struct shrinker *shrinker);
+#else /* CONFIG_SHRINKER_DEBUG */
+static inline int shrinker_debugfs_add(struct shrinker *shrinker)
+{
+	return 0;
+}
+static inline void shrinker_debugfs_remove(struct shrinker *shrinker)
+{
+}
+#endif /* CONFIG_SHRINKER_DEBUG */
+#endif /* _LINUX_SHRINKER_H */
lib/Kconfig.debug renamed from lib/Kconfig.debug~mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers +9 -0
@@ -699,6 +699,15 @@ config DEBUG_OBJECTS_ENABLE_DEFAULT
 	help
 	  Debug objects boot parameter default value
 
+config SHRINKER_DEBUG
+	default y
+	bool "Enable shrinker debugging support"
+	depends on DEBUG_FS
+	help
+	  Say Y to enable the shrinker debugfs interface which provides
+	  visibility into the kernel memory shrinkers subsystem.
+	  Disable it to avoid an extra memory footprint.
+
 config HAVE_DEBUG_KMEMLEAK
 	bool
 
mm/Makefile renamed from mm/Makefile~mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers +1 -0
@@ -133,3 +133,4 @@ obj-$(CONFIG_PAGE_REPORTING) += page_rep
 obj-$(CONFIG_IO_MAPPING) += io-mapping.o
 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
+obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
mm/shrinker_debug.c new file +168 -0

168 lines not on this page · raw message

mm/vmscan.c renamed from mm/vmscan.c~mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers +4 -2
@@ -190,8 +190,8 @@ static void set_task_reclaim_state(struc
 	task->reclaim_state = rs;
 }
 
-static LIST_HEAD(shrinker_list);
-static DECLARE_RWSEM(shrinker_rwsem);
+LIST_HEAD(shrinker_list);
+DECLARE_RWSEM(shrinker_rwsem);
 
 #ifdef CONFIG_MEMCG
 static int shrinker_nr_max;
@@ -650,6 +650,7 @@ void register_shrinker_prepared(struct s
 	down_write(&shrinker_rwsem);
 	list_add_tail(&shrinker->list, &shrinker_list);
 	shrinker->flags |= SHRINKER_REGISTERED;
+	shrinker_debugfs_add(shrinker);
 	up_write(&shrinker_rwsem);
 }
 
@@ -677,6 +678,7 @@ void unregister_shrinker(struct shrinker
 	shrinker->flags &= ~SHRINKER_REGISTERED;
 	if (shrinker->flags & SHRINKER_MEMCG_AWARE)
 		unregister_memcg_shrinker(shrinker);
+	shrinker_debugfs_remove(shrinker);
 	up_write(&shrinker_rwsem);
 
 	kfree(shrinker->nr_deferred);

_

Patches currently in -mm which might be from [email protected] are

mm-shrinkers-provide-shrinkers-with-names.patch mm-docs-document-shrinker-debugfs.patch tools-add-memcg_shrinkerpy.patch mm-shrinkers-add-scan-interface-for-shrinker-debugfs.patch mm-memcontrol-do-not-miss-memcg_max-events-for-enforced-allocations.patch