skip to Main Content

We are trying to install cgroup v2 to our centOS 8 virtual servers but after all configs we can limit memory bu we can’t limit cpu. We can’t see the cpu.max (sys/fs/cgroup/user.slice)

Has cgroup v2 got full support on CentOS 8 ? , we don’t have any idea on this. (We must use centOS 8 , can’t be Rhel 8)

Do you have any idea or solution about how cgroup V2 works on CentOS 8 without CWP ?

Thank You for All

2

Answers


  1. ##https://www.redhat.com/en/authors/marc-richter
    #https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/pdf/managing_monitoring_and_updating_the_kernel/Red_Hat_Enterprise_Linux-8-Managing_monitoring_and_updating_the_kernel-en-US.pdf

    1. GRUB

    grubby --update-kernel=/boot/vmlinuz-$(uname -r) --args="cgroup_no_v1=all"
    reboot
    
    1. /usr/bin/configure_cgroups.sh

    #!/bin/bash
    
    touch /var/tmp/configure_cgroups.sh.ok
    
    mkdir -p /mnt/cgroupv2
    
    if [ ! -f /mnt/cgroupv2/cgroup.subtree_control ]
    then
        mount -t cgroup2 none /mnt/cgroupv2
        echo "+cpu" > /mnt/cgroupv2/cgroup.subtree_control
        echo "+cpuset" > /mnt/cgroupv2/cgroup.subtree_control
        echo "+memory" > /mnt/cgroupv2/cgroup.subtree_control
    fi
    
    ##cpuNo=0
    numberfCpus=$(nproc --all)
    numberOfUsers=$(ls /home| wc -l)
    cpuShare=$((numberfCpus*100000/numberOfUsers))
    totalMemory=$(cat /proc/meminfo | grep MemTotal| awk '{print $2}')
    memoryShare=$((totalMemory/numberOfUsers*1024))
    for username in $(ls /home)
    do
      if [ ! -d /mnt/cgroupv2/user.$username ]
      then
          mkdir -p /mnt/cgroupv2/user.$username
          ##echo "$cpuNo" > /mnt/cgroupv2/user.$username/cpuset.cpus
          ##echo "$cpuNo" > /mnt/cgroupv2/user.$username/cpuset.mems
          echo "$cpuShare 100000" > /mnt/cgroupv2/user.$username/cpu.max
          echo "$memoryShare" > /mnt/cgroupv2/user.$username/memory.max
          ##cpuNo=$((cpuNo+1))
      fi
    
    done
    
    for username in $(ls /home)
    do
          for pid in $(ps -ef |  grep -i "^$username" | awk '{print $2}')
          do
             grep $pid /mnt/cgroupv2/user.$username/cgroup.procs >/dev/null
             if [ $? != 0 ]
             then
                 echo $pid > /mnt/cgroupv2/user.$username/cgroup.procs
             fi
          done
    done
    
    1. SERVICE : /usr/lib/systemd/system/configure-cgroupsv2.service

    [Unit]
    Description=Configure CGroups V2
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/configure_cgroups.sh
    

    1. SERVICE : /usr/lib/systemd/system/configure-cgroupsv2.timer

    [Unit]
    Description=Configure CGroups V2 Timer
    
    [Timer]
    OnUnitActiveSec=10s
    OnBootSec=10s
    
    [Install]
    WantedBy=timers.target
    

    systemctl daemon-reload
    systemctl enable configure-cgroupsv2.timer
    systemctl start configure-cgroupsv2.timer
    
    systemctl list-timers --all| grep configure
    
    systemctl start configure-cgroupsv2.service
    systemctl status configure-cgroupsv2.service
    journalctl -xe
    
    1. Testing :

    CPU: "while true; do   echo > /dev/null; done"  then  top
                                                       
    RAM :  "cat /dev/zero | head -c 20000M | tail " then top
    
    Login or Signup to reply.
  2. Also , you must do the following to be able to run your docker images :

    1. yum install crun -y
    
    2. cp  /usr/share/containers/containers.conf /etc/containers/
    
    3. edit  /etc/containers/containers.conf 
       cgroups="disabled"
       runtime="crun"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search