Le 22/04/2022 à 22:26, Roman Gushchin a écrit :
This commit introduces the /sys/kernel/debug/shrinker debugfs
interface which provides an ability to observe the state and interact
with individual kernel memory shrinkers.
Because the feature is oriented on kernel developers and 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
(disabled by default).
This commit introduces "count" and "scan" interfaces for each
shrinker registered in the system.
Basic usage:
1) Get the number of objects
$ cat count
2) Try to reclaim 500 objects
$ echo "500" > scan
Following commits in the series will add memcg- and numa-specific
features.
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.
Signed-off-by: Roman Gushchin <roman.gushchin@xxxxxxxxx>
---
include/linux/shrinker.h | 19 +++-
lib/Kconfig.debug | 9 ++
mm/Makefile | 1 +
mm/shrinker_debug.c | 214 +++++++++++++++++++++++++++++++++++++++
mm/vmscan.c | 6 +-
5 files changed, 246 insertions(+), 3 deletions(-)
create mode 100644 mm/shrinker_debug.c
[...]
diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
new file mode 100644
index 000000000000..4df7382a0737
--- /dev/null
+++ b/mm/shrinker_debug.c
[...]
+int shrinker_debugfs_add(struct shrinker *shrinker)
+{
+ struct dentry *entry;
+ char buf[256];
Later, this buffer is filled with a "%s-%d". (patch 5/7)
The %s is generated out of a max 64 bytes long string.
To be consistent with the 2 buffers sizes, maybe this one could be
reduced a bit to save some stack?
CJ
+ int id;
+
+ lockdep_assert_held(&shrinker_rwsem);
+
+ /* debugfs isn't initialized yet, add debugfs entries later. */
+ if (!shrinker_debugfs_root)
+ return 0;
+
+ id = ida_alloc(&shrinker_debugfs_ida, GFP_KERNEL);
+ if (id < 0)
+ return id;
+ shrinker->debugfs_id = id;
+
+ snprintf(buf, sizeof(buf), "%d", id);
+
+ /* create debugfs entry */
+ entry = debugfs_create_dir(buf, shrinker_debugfs_root);
+ if (IS_ERR(entry)) {
+ ida_free(&shrinker_debugfs_ida, id);
+ return PTR_ERR(entry);
+ }
[...]