Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino()

Patch series "mm: introduce shrinker debugfs interface", v5.

The only existing debugging mechanism is a couple of tracepoints in
do_shrink_slab(): mm_shrink_slab_start and mm_shrink_slab_end. They
aren't covering everything though: shrinkers which report 0 objects will
never show up, there is no support for memcg-aware shrinkers. Shrinkers
are identified by their scan function, which is not always enough (e.g.
hard to guess which super block's shrinker it is having only
"super_cache_scan").

To provide a better visibility and debug options for memory shrinkers this
patchset introduces a /sys/kernel/debug/shrinker interface, to some extent
similar to /sys/kernel/slab.

For each shrinker registered in the system a directory is created. As
now, the directory will contain only a "scan" file, which allows to get
the number of managed objects for each memory cgroup (for memcg-aware
shrinkers) and each numa node (for numa-aware shrinkers on a numa
machine). Other interfaces might be added in the future.

To make debugging more pleasant, the patchset also names all shrinkers, so
that debugfs entries can have meaningful names.


This patch (of 5):

Shrinker debugfs requires a way to represent memory cgroups without using
full paths, both for displaying information and getting input from a user.

Cgroup inode number is a perfect way, already used by bpf.

This commit adds a couple of helper functions which will be used to handle
memcg-aware shrinkers.

Link: https://lkml.kernel.org/r/20220601032227.4076670-1-roman.gushchin@linux.dev
Link: https://lkml.kernel.org/r/20220601032227.4076670-2-roman.gushchin@linux.dev
Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Muchun Song <songmuchun@bytedance.com>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Roman Gushchin and committed by
akpm
c15187a4 000eca5d

+44
+21
include/linux/memcontrol.h
··· 837 837 } 838 838 struct mem_cgroup *mem_cgroup_from_id(unsigned short id); 839 839 840 + #ifdef CONFIG_SHRINKER_DEBUG 841 + static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) 842 + { 843 + return memcg ? cgroup_ino(memcg->css.cgroup) : 0; 844 + } 845 + 846 + struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino); 847 + #endif 848 + 840 849 static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) 841 850 { 842 851 return mem_cgroup_from_css(seq_css(m)); ··· 1351 1342 /* XXX: This should always return root_mem_cgroup */ 1352 1343 return NULL; 1353 1344 } 1345 + 1346 + #ifdef CONFIG_SHRINKER_DEBUG 1347 + static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) 1348 + { 1349 + return 0; 1350 + } 1351 + 1352 + static inline struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) 1353 + { 1354 + return NULL; 1355 + } 1356 + #endif 1354 1357 1355 1358 static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) 1356 1359 {
+23
mm/memcontrol.c
··· 5088 5088 return idr_find(&mem_cgroup_idr, id); 5089 5089 } 5090 5090 5091 + #ifdef CONFIG_SHRINKER_DEBUG 5092 + struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) 5093 + { 5094 + struct cgroup *cgrp; 5095 + struct cgroup_subsys_state *css; 5096 + struct mem_cgroup *memcg; 5097 + 5098 + cgrp = cgroup_get_from_id(ino); 5099 + if (!cgrp) 5100 + return ERR_PTR(-ENOENT); 5101 + 5102 + css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys); 5103 + if (css) 5104 + memcg = container_of(css, struct mem_cgroup, css); 5105 + else 5106 + memcg = ERR_PTR(-ENOENT); 5107 + 5108 + cgroup_put(cgrp); 5109 + 5110 + return memcg; 5111 + } 5112 + #endif 5113 + 5091 5114 static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) 5092 5115 { 5093 5116 struct mem_cgroup_per_node *pn;