内核版本:5.14
ubuntu版本:20.04
参考:
在开机时,会自动挂载cgroup文件系统,可以通过cat /proc/cgroups
来查看当前在用的cgroup子系统。
root@ubuntu-vm:~# cat /proc/cgroups #subsys_name hierarchy num_cgroups enabled cpuset 8 1 1 cpu 7 1 1 cpuacct 7 1 1 blkio 6 1 1 memory 4 52 1 devices 12 23 1 freezer 13 1 1 perf_event 11 1 1 hugetlb 3 1 1 pids 10 29 1 rdma 5 1 1 misc 9 1 1 debug 2 1 1 root@ubuntu-vm:~# cat /proc/cgroups | wc -l 14
上面cpu和cpuacct的hierarchy是相同的,表示这两个子系统是一同挂载的,即:mount -t cgroup -o cpu,cpuacct
,这里的log是通过proc_cgroupstats_show
输出的:
**/* Display information about each subsystem and each hierarchy */ int proc_cgroupstats_show(struct seq_file *m, void *v) { struct cgroup_subsys *ss; int i; seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); /* * ideally we don't want subsystems moving around while we do this. * cgroup_mutex is also necessary to guarantee an atomic snapshot of * subsys/hierarchy state. */ mutex_lock(&cgroup_mutex); for_each_subsys(ss, i) seq_printf(m, "%s\t%d\t%d\t%d\n", ss->legacy_name, ss->root->hierarchy_id, atomic_read(&ss->root->nr_cgrps), cgroup_ssid_enabled(i)); mutex_unlock(&cgroup_mutex); return 0; }
当mount -t cgroup -o memory,xxx
时,如果memory子系统还没有cgroup_root的话,会创建新的cgroup_root结构,并将其加入到全局cgroup_roots链表中,下面用crash工具的list命令
来遍历这个链表,输出每个cgroup_root的信息。
- 获取cgroup_roots的地址
crash> sym cgroup_roots ffffffffb7f509a0 (D) cgroup_roots
- 遍历1
crash> list -o cgroup_root.root_list -H ffffffffb7f509a0 | wc -l 14 crash> list -o cgroup_root.root_list -H ffffffffb7f509a0 ffffa3b7802cc000 ffffa3b7802ca000 ffffa3b7802c8000 ffffa3b782b8e000 ffffa3b782b8c000 ffffa3b782b8a000 ffffa3b782b88000 ffffa3b780bf6000 ffffa3b780bf4000 ffffa3b780bf2000 ffffa3b780bf0000 ffffa3b781696000 ffffa3b781694000 ffffffffb7f509c0
- 查看具体每个cgroup_root的hierarchy:
crash> list -o cgroup_root.root_list -s cgroup_root.hierarchy_id -H ffffffffb7f509a0 -r ffffffffb7f509c0 hierarchy_id = 0, # 默认cgroup_root ffffa3b781694000 hierarchy_id = 1, ffffa3b781696000 hierarchy_id = 2, ffffa3b780bf0000 hierarchy_id = 3, ffffa3b780bf2000 hierarchy_id = 4, ffffa3b780bf4000 hierarchy_id = 5, ffffa3b780bf6000 hierarchy_id = 6, ffffa3b782b88000 hierarchy_id = 7, ffffa3b782b8a000 hierarchy_id = 8, ffffa3b782b8c000 hierarchy_id = 9, ffffa3b782b8e000 hierarchy_id = 10, ffffa3b7802c8000 hierarchy_id = 11, ffffa3b7802ca000 hierarchy_id = 12, ffffa3b7802cc000 hierarchy_id = 13,
- 查看具体每个cgroup_root的更多信息:
crash> list -o cgroup_root.root_list -s cgroup_root.hierarchy_id,subsys_mask,nr_cgrps -H ffffffffb7f509a0 -rx ffffffffb7f509c0 hierarchy_id = 0x0, subsys_mask = 0x0, nr_cgrps = { counter = 0x1f }, ffffa3b781694000 hierarchy_id = 0x1, subsys_mask = 0x0, nr_cgrps = { counter = 0x1f }, ffffa3b781696000 hierarchy_id = 0x2, subsys_mask = 0x1000, nr_cgrps = { counter = 0x1 }, ffffa3b780bf0000 hierarchy_id = 0x3, subsys_mask = 0x100, nr_cgrps = { counter = 0x1 }, ffffa3b780bf2000 hierarchy_id = 0x4, subsys_mask = 0x10, nr_cgrps = { counter = 0x34 }, ffffa3b780bf4000 hierarchy_id = 0x5, subsys_mask = 0x400, nr_cgrps = { counter = 0x1 }, ffffa3b780bf6000 hierarchy_id = 0x6, subsys_mask = 0x8, nr_cgrps = { counter = 0x1 }, ffffa3b782b88000 hierarchy_id = 0x7, subsys_mask = 0x6, nr_cgrps = { counter = 0x1 }, ffffa3b782b8a000 hierarchy_id = 0x8, subsys_mask = 0x1, nr_cgrps = { counter = 0x1 }, ffffa3b782b8c000 hierarchy_id = 0x9, subsys_mask = 0x800, nr_cgrps = { counter = 0x1 }, ffffa3b782b8e000 hierarchy_id = 0xa, subsys_mask = 0x200, nr_cgrps = { counter = 0x1d }, ffffa3b7802c8000 hierarchy_id = 0xb, subsys_mask = 0x80, nr_cgrps = { counter = 0x1 }, ffffa3b7802ca000 hierarchy_id = 0xc, subsys_mask = 0x20, nr_cgrps = { counter = 0x17 }, ffffa3b7802cc000 hierarchy_id = 0xd, subsys_mask = 0x40, nr_cgrps = { counter = 0x1 },
完。