cgroup简介

介绍
cgroup是control group的简称,cgroup是Linux下的一种将进程按组进行管理的机制。

组成

  • subsystem 一个subsystem就是一个内核模块,他被关联到一颗cgroup树之后,就会在树的每个节点(进程组)上做具体的操作。Linux支持12种subsystem,比如限制CPU的使用时间,限制使用的内存,统计CPU的使用情况,冻结和恢复一组进程等。
  • hierarchy 一个hierarchy可以理解为一棵cgroup树,树的每个节点就是一个进程组,每棵树都会与零到多个subsystem关联。

查看系统支持的subsystem

# cat /proc/cgroups
subsys_name    hierarchy       num_cgroups     enabled
cpuset      11         1                1
cpu         5         3          1
cpuacct       5         3          1
blkio         9         25            1
memory      7         473            1
devices      3         23             1
freezer      12         1              1
net_cls      6         1                1
perf_event    2         1                1
net_prio      6         1                1
hugetlb       4         1                1
pids        8         63              1
rdma       10          1               1                
  • cpu  用来限制cgroup的CPU使用率。
  • cpuacct  统计cgroup的CPU的使用率。
  • cpuset  绑定cgroup到指定CPUs和NUMA节点。
  • memory  统计和限制cgroup的内存的使用率,包括process memory, kernel memory, 和swap。
  • devices  限制cgroup创建(mknod)和访问设备的权限。
  • freezer  suspend和restore一个cgroup中的所有进程。
  • net_cls  将一个cgroup中进程创建的所有网络包加上一个classid标记,用于tc和iptables。 只对发出去的网络包生效,对收到的网络包不起作用。
  • blkio  限制cgroup访问块设备的IO速度。
  • perf_event  对cgroup进行性能监控
  • net_prio  针对每个网络接口设置cgroup的访问优先级。
  • hugetlb  限制cgroup的huge pages的使用量。
  • pids  限制一个cgroup及其子孙cgroup中的总进程数。

创建和删除cgroup
在对应的目录下创建或删除对应的子目录即可。

# ll /sys/fs/cgroup/
dr-xr-xr-x 4 root root 0 Jan 13 2021 blkio
lrwxrwxrwx 1 root root 11 Jan 13 2021 cpu -> cpu,cpuacct
lrwxrwxrwx 1 root root 11 Jan 13 2021 cpuacct -> cpu,cpuacct
dr-xr-xr-x 4 root root 0 Jan 13 2021 cpu,cpuacct
dr-xr-xr-x 2 root root 0 Jan 13 2021 cpuset
dr-xr-xr-x 4 root root 0 Jan 13 2021 devices
dr-xr-xr-x 2 root root 0 Jan 13 2021 freezer
dr-xr-xr-x 2 root root 0 Jan 13 2021 hugetlb
dr-xr-xr-x 5 root root 0 Jan 13 2021 memory
lrwxrwxrwx 1 root root 16 Jan 13 2021 net_cls -> net_cls,net_prio
dr-xr-xr-x 2 root root 0 Jan 13 2021 net_cls,net_prio
lrwxrwxrwx 1 root root 16 Jan 13 2021 net_prio -> net_cls,net_prio
dr-xr-xr-x 2 root root 0 Jan 13 2021 perf_event
dr-xr-xr-x 4 root root 0 Jan 13 2021 pids
dr-xr-xr-x 2 root root 0 Jan 13 2021 rdma
dr-xr-xr-x 5 root root 0 Jan 13 2021 systemd

 

posted @ 2022-04-17 12:13  Krill_ss  阅读(571)  评论(0编辑  收藏  举报