Cgroup V1

最後更新: 2024-02-02

目錄

介紹

cgroups are organized hierarchically (single parent)

應用

 


設定使用 V2 還是 V1 cgroup

 

Rocky 8

/etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="... systemd.unified_cgroup_hierarchy=false"

grub2-mkconfig -o /boot/grub2/grub.cfg

reboot

cat /proc/cmdline

 


cgroup subsystem

 

/sys/fs/cgroup 內有以下目錄, 每一個都是 cgroup 的 subsystem 來

  • blkio
  • cpu
  • cpuacct
  • cpuset
  • devices
  • freezer
  • memory
  • perf_event

Kernel 支援那 cgroup 功能

cat /proc/cgroups

#subsys_name    hierarchy    num_cgroups   enabled
cpuset          1            7             1
cpu             2            7             1
cpuacct         3            7             1
memory          4            7             1
devices         5            7             1
freezer         6            7             1
blkio           7            7             1
perf_event      8            4             1

 


工具

 

  • cgroup-lite   <-- lxc 會依賴它們兩者之一, 其中 lite 只是提供基本的 mount 服務而已
  • cgroup-bin   <-- 只有 bin 才有工具

 

cgroup-lite

 

# 它們本身都是 shell script 來

/usr/bin/cgroups-mount            <--  ( /etc/init.d/cgroup-lite -- call --> /etc/init/cgroup-lite.conf )
/usr/bin/cgroups-umount

它們的功用是根據 /proc/cgroups 去 mount /sys/fs/cgroup 出來

  • libpam-cgroup - PAM module to move a user session into a cgroup

 

cgroup-bin

 

Tools

  • /etc/init.d/cgconfig                            // Proccess: cgrulesengd 的start / stop
  • /usr/bin/lscgroup                              // 查看
  • /usr/bin/lssubsys                              // 查看
  • /usr/sbin/cgconfigparser <file>         // 根據 file 去建立 cgroup 環境
  • /usr/sbin/cgrulesengd                       // 透過 cgrules.conf 內的 UID, GID 把 Proccess 放入不同 cgroup
  • /usr/sbin/create_default_cgroups     // 根據 /etc/cgrules.conf 去引用 cgcreate 建立 defaultcgroup
  • /usr/sbin/cgclear                              // moves all to root -> deletes all cgroup -> unmounts all cgroup
  • /usr/bin/cgcreate
  • /usr/bin/cgset
  • /usr/bin/cgdelete
  • /usr/bin/cgsnapshot
  • /usr/bin/cgexec
  • /usr/bin/cgclassify
  • /usr/bin/cgget

設定

  • /etc/default/cgconfig                 // CREATE_DEFAULT= yes, 開機建立 sysdefault  讀取 /etc/cgconfig.conf
  • /etc/cgconfig.conf
  • /etc/cgrules.conf                      // man 5
  • /etc/init/cgred.conf        
  • /etc/init/libvirt-cgconfig-wait.conf
  • /etc/init/cgconfig.conf

使用:

lscgroup

cpu:/
cpu:/sysdefault
cpu:/libvirt
cpu:/libvirt/lxc
cpu:/libvirt/qemu
cpu:/libvirt/qemu/centos6a
cpu:/libvirt/qemu/centos6a/vcpu0
cpu:/lxc
cpu:/lxc/myserver
cpu:/lxc/lamp
.........................................

lssubsys

cpu
cpuacct
devices
memory
freezer

 

 


找出某 process 是屬於那 cgroup

 

cat /proc/26170/cgroup

8:perf_event:/
7:blkio:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct:/
2:cpu:/
1:cpuset:/

 


 

 

 

Creative Commons license icon Creative Commons license icon