3 # Copyright (C) 2022 Roman Gushchin <roman.gushchin@linux.dev>
4 # Copyright (C) 2022 Meta
11 def scan_cgroups(cgroup_root):
14 for root, subdirs, _ in os.walk(cgroup_root):
15 for cgroup in subdirs:
16 path = os.path.join(root, cgroup)
17 ino = os.stat(path).st_ino
24 def scan_shrinkers(shrinker_debugfs):
27 for root, subdirs, _ in os.walk(shrinker_debugfs):
28 for shrinker in subdirs:
29 count_path = os.path.join(root, shrinker, "count")
30 with open(count_path) as f:
31 for line in f.readlines():
32 items = line.split(' ')
34 # (count, shrinker, memcg ino)
35 shrinkers.append((int(items[1]), shrinker, ino))
40 parser = argparse.ArgumentParser(description='Display biggest shrinkers')
41 parser.add_argument('-n', '--lines', type=int, help='Number of lines to print')
43 args = parser.parse_args()
45 cgroups = scan_cgroups("/sys/fs/cgroup/")
46 shrinkers = scan_shrinkers("/sys/kernel/debug/shrinker/")
47 shrinkers = sorted(shrinkers, reverse = True, key = lambda x: x[0])
51 count, name, ino = (s[0], s[1], s[2])
55 if ino == 0 or ino == 1:
61 cg = "unknown (%d)" % ino
63 print("%-8s %-20s %s" % (count, name, cg))
66 if args.lines and n >= args.lines:
70 if __name__ == '__main__':