cgroup

1、查看进程或者线程cgroup

cat /proc/$process_pid/task/$thread_pid/cgroup 

2、查看系统cgroup 整体配置

cat /etc/cgroup.conf

3、把进程添加到某cgroup

echo 1734  > /sys/fs/cgroup/cpuset/TestCgroup/tasks

4、查看cgroup 版本

//查看 cgroup 版本如果包含有cgroup2 的就是安装了的
grep cgroup /proc/filesystems
nodev cgroup
nodev cgroup2

 5、cgroup 中有哪些文件

[root@localhost ~]# ls -lah /sys/fs/cgroup/
total 0
drwxr-xr-x 13 root root 340 Dec  7 16:01 .
drwxr-xr-x  8 root root   0 Dec  7 16:01 ..
drwxr-xr-x  5 root root   0 Dec  7 16:01 blkio
lrwxrwxrwx  1 root root  11 Dec  7 16:01 cpu -> cpu,cpuacct
lrwxrwxrwx  1 root root  11 Dec  7 16:01 cpuacct -> cpu,cpuacct
drwxr-xr-x  5 root root   0 Dec  7 16:01 cpu,cpuacct
drwxr-xr-x  2 root root   0 Dec  7 16:01 cpuset
drwxr-xr-x  5 root root   0 Dec  7 16:01 devices
drwxr-xr-x  2 root root   0 Dec  7 16:01 freezer
drwxr-xr-x  2 root root   0 Dec  7 16:01 hugetlb
drwxr-xr-x  5 root root   0 Dec  7 16:01 memory
lrwxrwxrwx  1 root root  16 Dec  7 16:01 net_cls -> net_cls,net_prio
drwxr-xr-x  2 root root   0 Dec  7 16:01 net_cls,net_prio
lrwxrwxrwx  1 root root  16 Dec  7 16:01 net_prio -> net_cls,net_prio
drwxr-xr-x  2 root root   0 Dec  7 16:01 perf_event
drwxr-xr-x  5 root root   0 Dec  7 16:01 pids
drwxr-xr-x  5 root root   0 Dec  7 16:01 systemd

 

6、cpu,cpuacct

6.1 V1 的cpu,cpuacct

[root@localhost ~]# ls -lah /sys/fs/cgroup/cpu/
total 0
drwxr-xr-x  5 root root   0 Dec  7 16:01 .
drwxr-xr-x 13 root root 340 Dec  7 16:01 ..
-rw-r--r--  1 root root   0 Dec  7 16:01 cgroup.clone_children
--w--w--w-  1 root root   0 Dec  7 16:01 cgroup.event_control
-rw-r--r--  1 root root   0 Dec  7 16:01 cgroup.procs
-r--r--r--  1 root root   0 Dec  7 16:01 cgroup.sane_behavior
-r--r--r--  1 root root   0 Dec  7 16:01 cpuacct.stat
-rw-r--r--  1 root root   0 Dec  7 16:01 cpuacct.usage
-r--r--r--  1 root root   0 Dec  7 16:01 cpuacct.usage_percpu
-rw-r--r--  1 root root   0 Dec  7 16:01 cpu.cfs_period_us
-rw-r--r--  1 root root   0 Dec  7 16:01 cpu.cfs_quota_us
-rw-r--r--  1 root root   0 Dec  7 16:01 cpu.shares
-r--r--r--  1 root root   0 Dec  7 16:01 cpu.stat
drwxr-xr-x  2 root root   0 Dec  7 16:02 machine.slice
-rw-r--r--  1 root root   0 Dec  7 16:01 notify_on_release
-rw-r--r--  1 root root   0 Dec  7 16:01 release_agent
drwxr-xr-x 97 root root   0 Dec  7 16:03 system.slice
-rw-r--r--  1 root root   0 Dec  7 16:01 tasks
drwxr-xr-x  2 root root   0 Dec  7 16:02 user.slice

 

6.2 V2 的cpu,cpuacct

bash-4.4# ls /sys/fs/cgroup/cpu,cpuacct/ -lah
total 0
dr-xr-xr-x  3 root root   0 Jan  1  1970 .
dr-xr-xr-x 12 root root 240 Jan  1  1970 ..
drwxrwxrwx 10 root root   0 Jan  1  1970 0
-rw-r--r--  1 root root   0 Dec  7 16:03 cgroup.clone_children
-rw-r--r--  1 root root   0 Dec  7 16:03 cgroup.procs
-r--r--r--  1 root root   0 Dec  7 16:03 cgroup.sane_behavior
-rw-r--r--  1 root root   0 Dec  7 16:03 cpu.shares
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.stat
-rw-r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_all
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_percpu
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_percpu_sys
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_percpu_user
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_sys
-r--r--r--  1 root root   0 Dec  7 16:03 cpuacct.usage_user
-rw-r--r--  1 root root   0 Dec  7 16:03 notify_on_release
-rw-r--r--  1 root root   0 Dec  7 16:03 release_agent
-rw-r--r--  1 root root   0 Dec  7 16:03 tasks

6.3 cgroup v1 和v2 区别

The cgroupfs files described in this section are only applicable to cgroup v1. For cgroup v2, see Documentation/admin-guide/cgroup-v2.rst.

cpu.cfs_quota_us: run-time replenished within a period (in microseconds)
cpu.cfs_period_us: the length of a period (in microseconds)
cpu.stat: exports throttling statistics [explained further below]
cpu.cfs_burst_us: the maximum accumulated run-time (in microseconds)

 

参考:

https://docs.kernel.org/scheduler/sched-bwc.html

https://www.man7.org/linux/man-pages/man7/cgroups.7.html

http://arthurchiao.art/blog/cgroupv2-zh/

posted on 2023-12-09 10:17  红旗kernel  阅读(18)  评论(0编辑  收藏  举报

导航