# 找到cgroup的挂载点 [root@localhost ~]# mount | grep cgroup tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb) cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,rdma) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,memory) cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,net_cls,net_prio) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,freezer) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,pids) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,devices) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event) # 查看虚拟文件系统下的文件 [root@localhost ~]# cd /sys/fs/cgroup/ [root@localhost cgroup]# ls -l drwxr-xr-x. 2 root root 40 12月 15 02:45 blkio lrwxrwxrwx. 1 root root 11 12月 15 02:45 cpu -> cpu,cpuacct lrwxrwxrwx. 1 root root 11 12月 15 02:45 cpuacct -> cpu,cpuacct drwxr-xr-x. 2 root root 40 12月 15 02:45 cpu,cpuacct dr-xr-xr-x. 2 root root 0 12月 15 02:45 cpuset dr-xr-xr-x. 3 root root 0 12月 15 02:45 devices dr-xr-xr-x. 2 root root 0 12月 15 02:45 freezer dr-xr-xr-x. 2 root root 0 12月 15 02:45 hugetlb dr-xr-xr-x. 6 root root 0 12月 15 02:45 memory lrwxrwxrwx. 1 root root 16 12月 15 02:45 net_cls -> net_cls,net_prio dr-xr-xr-x. 2 root root 0 12月 15 02:45 net_cls,net_prio lrwxrwxrwx. 1 root root 16 12月 15 02:45 net_prio -> net_cls,net_prio dr-xr-xr-x. 2 root root 0 12月 15 02:45 perf_event dr-xr-xr-x. 6 root root 0 12月 15 02:45 pids dr-xr-xr-x. 2 root root 0 12月 15 02:45 rdma dr-xr-xr-x. 6 root root 0 12月 15 02:45 systemd # 查看cpu子系统,注意顶层下有个“test”目录,这是我创建的子层。 [root@localhost cpu]# ls -l -rw-r--r--. 1 root root 0 12月 15 06:07 cgroup.clone_children -rw-r--r--. 1 root root 0 12月 15 06:03 cgroup.procs -r--r--r--. 1 root root 0 12月 15 06:07 cgroup.sane_behavior -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.stat -rw-r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_all -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_percpu -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_percpu_sys -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_percpu_user -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_sys -r--r--r--. 1 root root 0 12月 15 06:07 cpuacct.usage_user -rw-r--r--. 1 root root 0 12月 15 06:07 cpu.cfs_period_us -rw-r--r--. 1 root root 0 12月 15 06:07 cpu.cfs_quota_us -rw-r--r--. 1 root root 0 12月 15 06:07 cpu.rt_period_us -rw-r--r--. 1 root root 0 12月 15 06:07 cpu.rt_runtime_us -rw-r--r--. 1 root root 0 12月 15 06:07 cpu.shares -r--r--r--. 1 root root 0 12月 15 06:07 cpu.stat -rw-r--r--. 1 root root 0 12月 15 06:07 notify_on_release -rw-r--r--. 1 root root 0 12月 15 06:07 release_agent -rw-r--r--. 1 root root 0 12月 15 06:07 tasks drwxr-xr-x. 2 yz yz 0 12月 15 06:10 test # 切换到test组 [root@localhost cpu]# cd test/ # 查看CPU使用率限制: [root@localhost test]# cat cpu.cfs_period_us 100000 [root@localhost test]# cat cpu.cfs_quota_us -1 # 假设这个系统上只有一个CPU核。修改CPU使用率限制为50%。 [root@localhost test]# echo 50000 > cpu.cfs_quota_us [root@localhost test]# cat cpu.cfs_quota_us 50000 # 将被限制进程的PID加入cgroup.procs,这样进程45992的CPU使用率将被限制为不超过50%。 [root@localhost test]# echo 45992 > cgroup.procs [root@localhost test]# cat cgroup.procs 45992