Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
elearning:workbooks:debian:10:avance:l101 [2022/05/02 08:14] – created adminelearning:workbooks:debian:10:avance:l101 [2022/05/04 09:35] (Version actuelle) admin
Ligne 54: Ligne 54:
       * 4.1 - ulimit       * 4.1 - ulimit
       * 4.2 - Groupes de Contrôle       * 4.2 - Groupes de Contrôle
-        * La Limitation de la Mémoire +        * CGroups v1 
-        * La Commande cgcreate +          * Préparation 
-        * La Commande cgdelete +          * Présentation 
-        * Le Fichier /etc/cgconfig.conf +          * Limitation de la Mémoire 
-        * La Commande cgconfigparser+          * La Commande cgcreate 
 +          * La Commande cgdelete 
 +          * Le Fichier /etc/cgconfig.conf 
 +          * La Commande cgconfigparser
  
 =====Présentation des Fichiers Spéciaux===== =====Présentation des Fichiers Spéciaux=====
Ligne 2390: Ligne 2393:
  
 ====4.2 - Groupes de Contrôle==== ====4.2 - Groupes de Contrôle====
 +
 +===CGroups v1===
 +
 +==Préparation==
 +
 +Debian 11 utilise CGroups v2 par défault. Pour revenir à l'utilisation de CGroups v1, éditez le fichier **/etc/boot/grub** et ajoutez la directive **systemd.unified_cgroup_hierarchy=0** à la ligne **GRUB_CMDLINE_LINUX_DEFAULT** :
 +
 +<code>
 +root@debian11:~# vi /etc/default/grub
 +root@debian11:~# cat /etc/default/grub
 +# If you change this file, run 'update-grub' afterwards to update
 +# /boot/grub/grub.cfg.
 +# For full documentation of the options in this file, see:
 +#   info -f grub -n 'Simple configuration'
 +
 +GRUB_DEFAULT=0
 +GRUB_TIMEOUT=5
 +GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
 +GRUB_CMDLINE_LINUX_DEFAULT="quiet systemd.unified_cgroup_hierarchy=0"
 +GRUB_CMDLINE_LINUX=""
 +
 +# Uncomment to enable BadRAM filtering, modify to suit your needs
 +# This works with Linux (no patch required) and with any kernel that obtains
 +# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
 +#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
 +
 +# Uncomment to disable graphical terminal (grub-pc only)
 +#GRUB_TERMINAL=console
 +
 +# The resolution used on graphical terminal
 +# note that you can use only modes which your graphic card supports via VBE
 +# you can see them in real GRUB with the command `vbeinfo'
 +#GRUB_GFXMODE=640x480
 +
 +# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
 +#GRUB_DISABLE_LINUX_UUID=true
 +
 +# Uncomment to disable generation of recovery mode menu entries
 +#GRUB_DISABLE_RECOVERY="true"
 +
 +# Uncomment to get a beep at grub start
 +#GRUB_INIT_TUNE="480 440 1"
 +
 +root@debian11:~# grub-mkconfig -o /boot/grub/grub.cfg 
 +Generating grub configuration file ...
 +Found background image: /usr/share/images/desktop-base/desktop-grub.png
 +Found linux image: /boot/vmlinuz-5.10.0-13-amd64
 +Found initrd image: /boot/initrd.img-5.10.0-13-amd64
 +done
 +</code>
 +
 +Redémarrez ensuite votre VM :
 +
 +<code>
 +root@debian11:~# reboot
 +</code>
 +
 +==Présentation==
  
 Les **Groupes de Contrôles** (//Control Groups//) aussi appelés **CGroups**, sont une façon de contrôler et de limiter des ressources. Les groupes de contrôle permettent l'allocation de ressources, même d'une manière dynamique pendant que le système fonctionne, telles le temps processeur, la mémoire système, la bande réseau, ou une combinaison de ces ressources parmi des groupes de tâches (processus) définis par l'utilisateur et exécutés sur un système. Les **Groupes de Contrôles** (//Control Groups//) aussi appelés **CGroups**, sont une façon de contrôler et de limiter des ressources. Les groupes de contrôle permettent l'allocation de ressources, même d'une manière dynamique pendant que le système fonctionne, telles le temps processeur, la mémoire système, la bande réseau, ou une combinaison de ces ressources parmi des groupes de tâches (processus) définis par l'utilisateur et exécutés sur un système.
Ligne 2395: Ligne 2456:
 Les groupes de contrôle sont organisés de manière hiérarchique, comme des processus. Par contre, la comparaison entre les deux démontre que tandis que les processus se trouvent dans une arborescence unique descandant tous du processus init et héritant de l'environnement de leurs parents, les contrôles groupes peuvent être multiples donnant lieu à des arborescences ou **hiérarchies** multiples qui héritent de certains attributs de leurs groupes de contrôle parents. Les groupes de contrôle sont organisés de manière hiérarchique, comme des processus. Par contre, la comparaison entre les deux démontre que tandis que les processus se trouvent dans une arborescence unique descandant tous du processus init et héritant de l'environnement de leurs parents, les contrôles groupes peuvent être multiples donnant lieu à des arborescences ou **hiérarchies** multiples qui héritent de certains attributs de leurs groupes de contrôle parents.
  
-Ces hiérarchies multiples et séparés sont necéssaires parce que chaque hiérarchie est attaché à un ou plusieurs **sous-système(s)** aussi appelés des **Contrôleurs de Ressources** ou simplement des **Contrôleurs**. Les contrôleurs disponibles sous RHEl/CentOS 7 sont :+Ces hiérarchies multiples et séparés sont necéssaires parce que chaque hiérarchie est attaché à un ou plusieurs **sous-système(s)** aussi appelés des **Contrôleurs de Ressources** ou simplement des **Contrôleurs**. Les contrôleurs disponibles sous Debian 11 sont :
  
   * **blkio** - utilisé pour établir des limites sur l'accès des entrées/sorties à partir et depuis des périphériques blocs,   * **blkio** - utilisé pour établir des limites sur l'accès des entrées/sorties à partir et depuis des périphériques blocs,
Ligne 2408: Ligne 2469:
   * **hugetlb** - utilisé pour limiter des ressources sur des pages de mémoire virtuelle de grande taille.   * **hugetlb** - utilisé pour limiter des ressources sur des pages de mémoire virtuelle de grande taille.
  
-Pour visualiser les hiérarchies, il convient d'utiliser la commande **lssubsys** :+Commencez par installer le paquet **cgroup-tools** :
  
 <code> <code>
-root@debian11:~# lssubsys -am 
--bash: lssubsys: command not found 
- 
 root@debian11:~# apt -y install cgroup-tools root@debian11:~# apt -y install cgroup-tools
 +</code>
  
 +Pour visualiser les hiérarchies, il convient d'utiliser la commande **lssubsys** :
 +
 +<code>
 root@debian11:~# lssubsys -am root@debian11:~# lssubsys -am
-cpuset +cpuset /sys/fs/cgroup/cpuset 
-cpu +cpu,cpuacct /sys/fs/cgroup/cpu,cpuacct 
-cpuacct +blkio /sys/fs/cgroup/blkio 
-blkio +memory /sys/fs/cgroup/memory 
-memory +devices /sys/fs/cgroup/devices 
-devices +freezer /sys/fs/cgroup/freezer 
-freezer +net_cls,net_prio /sys/fs/cgroup/net_cls,net_prio 
-net_cls +perf_event /sys/fs/cgroup/perf_event 
-perf_event +hugetlb /sys/fs/cgroup/hugetlb 
-net_prio +pids /sys/fs/cgroup/pids 
-hugetlb +rdma /sys/fs/cgroup/rdma
-pids +
-rdma+
 </code>  </code> 
  
Ligne 2451: Ligne 2511:
   UNIT                               LOAD   ACTIVE SUB    DESCRIPTION   UNIT                               LOAD   ACTIVE SUB    DESCRIPTION
   -.slice                            loaded active active Root Slice   -.slice                            loaded active active Root Slice
-  system-apache2.slice               loaded active active system-apache2.slice 
   system-getty.slice                 loaded active active system-getty.slice   system-getty.slice                 loaded active active system-getty.slice
   system-lvm2\x2dpvscan.slice        loaded active active system-lvm2\x2dpvscan.slice   system-lvm2\x2dpvscan.slice        loaded active active system-lvm2\x2dpvscan.slice
   system-modprobe.slice              loaded active active system-modprobe.slice   system-modprobe.slice              loaded active active system-modprobe.slice
-  system-ssh.slice                   loaded active active system-ssh.slice 
   system-systemd\x2dcryptsetup.slice loaded active active Cryptsetup Units Slice   system-systemd\x2dcryptsetup.slice loaded active active Cryptsetup Units Slice
-  system-systemd\x2dfsck.slice       loaded active active system-systemd\x2dfsck.slice 
   system.slice                       loaded active active System Slice   system.slice                       loaded active active System Slice
   user-1000.slice                    loaded active active User Slice of UID 1000   user-1000.slice                    loaded active active User Slice of UID 1000
Ligne 2465: Ligne 2522:
 ACTIVE = The high-level unit activation state, i.e. generalization of SUB. ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
 SUB    = The low-level unit activation state, values depend on unit type. SUB    = The low-level unit activation state, values depend on unit type.
-11 loaded units listed. Pass --all to see loaded but inactive units, too.+loaded units listed. Pass --all to see loaded but inactive units, too.
 To show all installed unit files use 'systemctl list-unit-files'. To show all installed unit files use 'systemctl list-unit-files'.
 </code> </code>
Ligne 2480: Ligne 2537:
 │   │ ├─app.slice  │   │ ├─app.slice 
 │   │ │ ├─pulseaudio.service  │   │ │ ├─pulseaudio.service 
-│   │ │ │ └─46798 /usr/bin/pulseaudio --daemonize=no --log-target=journal+│   │ │ │ └─974 /usr/bin/pulseaudio --daemonize=no --log-target=journal
 │   │ │ ├─pipewire.service  │   │ │ ├─pipewire.service 
-│   │ │ │ ├─46797 /usr/bin/pipewire +│   │ │ │ ├─973 /usr/bin/pipewire 
-│   │ │ │ └─46808 /usr/bin/pipewire-media-session+│   │ │ │ └─984 /usr/bin/pipewire-media-session
 │   │ │ └─dbus.service  │   │ │ └─dbus.service 
-│   │ │   └─46806 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only+│   │ │   └─982 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
 │   │ └─init.scope  │   │ └─init.scope 
-│   │   ├─46780 /lib/systemd/systemd --user +│   │   ├─958 /lib/systemd/systemd --user 
-│   │   └─46782 (sd-pam) +│   │   └─959 (sd-pam) 
-│   ─session-180.scope  +│   ─session-3.scope  
-│     ├─46777 sshd: trainee [priv] +│   │ ├─ 993 sshd: trainee [priv] 
-│     ├─46804 sshd: trainee@pts/+│   │ ├─ 999 sshd: trainee@pts/
-│     ├─46805 -bash +│   │ ├─1000 -bash 
-│     ├─46812 su - +│   │ ├─1003 su - 
-│     ├─46813 -bash +│   │ ├─1004 -bash 
-│     ├─58896 systemd-cgls +│   │ ├─1010 systemd-cgls 
-│     └─58897 less+│   │ └─1011 less 
 +│   └─session-1.scope  
 +│     ├─578 /bin/login -p -- 
 +│     ├─975 -bash 
 +│     ├─986 su - 
 +│     └─987 -bash
 ├─init.scope  ├─init.scope 
 │ └─1 /sbin/init │ └─1 /sbin/init
 └─system.slice  └─system.slice 
   ├─apache2.service    ├─apache2.service 
-  │ ├─57689 /usr/sbin/apache2 -k start +  │ ├─595 /usr/sbin/apache2 -k start 
-  │ ├─57690 /usr/sbin/apache2 -k start +  │ ├─597 /usr/sbin/apache2 -k start 
-  │ └─57691 /usr/sbin/apache2 -k start +  │ └─598 /usr/sbin/apache2 -k start
-  ├─packagekit.service  +
-  │ └─56363 /usr/libexec/packagekitd+
   ├─systemd-udevd.service    ├─systemd-udevd.service 
-  │ └─244 /lib/systemd/systemd-udevd+  │ └─317 /lib/systemd/systemd-udevd
   ├─cron.service    ├─cron.service 
-  │ └─55347 /usr/sbin/cron -f +  │ └─491 /usr/sbin/cron -f
-  ├─apache-htcacheclean.service  +
-  │ └─56135 /usr/bin/htcacheclean -d 120 -p /var/cache/apache2/mod_cache_disk -l 300M -n+
   ├─polkit.service    ├─polkit.service 
-  │ └─55364 /usr/libexec/polkitd --no-debug+  │ └─495 /usr/libexec/polkitd --no-debug 
 +  ├─rtkit-daemon.service  
 +  │ └─979 /usr/libexec/rtkit-daemon
   ├─auditd.service    ├─auditd.service 
-  │ └─55353 /sbin/auditd+  │ └─460 /sbin/auditd
   ├─wpa_supplicant.service    ├─wpa_supplicant.service 
-  │ └─55368 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant+  │ └─498 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
   ├─ModemManager.service    ├─ModemManager.service 
-  │ └─55569 /usr/sbin/ModemManager+  │ └─515 /usr/sbin/ModemManager 
 +  ├─inetd.service  
 +  │ └─694 /usr/sbin/inetd
   ├─systemd-journald.service    ├─systemd-journald.service 
-  │ └─214 /lib/systemd/systemd-journald+  │ └─296 /lib/systemd/systemd-journald 
 +  ├─mdmonitor.service  
 +  │ └─432 /sbin/mdadm --monitor --scan
   ├─ssh.service    ├─ssh.service 
-lines 1-50+  │ └─580 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups 
 +lines 1-58
 [q] [q]
 </code> </code>
Ligne 2536: Ligne 2601:
   * **CPUQuota** - utilisé pour limiter le temps CPU, même quand le système ne fait rien.   * **CPUQuota** - utilisé pour limiter le temps CPU, même quand le système ne fait rien.
  
-===Limitation de la Mémoire===+==Limitation de la Mémoire==
  
 Commencez par créer le script **hello-world.sh** qui servira à générer un processus pour travailler avec les CGroups : Commencez par créer le script **hello-world.sh** qui servira à générer un processus pour travailler avec les CGroups :
Ligne 2554: Ligne 2619:
 <code> <code>
 root@debian11:~# chmod u+x hello-world.sh root@debian11:~# chmod u+x hello-world.sh
-root@debian11:~# ./hello-world.sh+root@debian11:~# ./hello-world.sh 
 hello world hello world
 ^C ^C
Ligne 2562: Ligne 2627:
  
 <code> <code>
-root@debian11:~# mkdir /sys/fs/cgroup/helloworld +root@debian11:~# mkdir /sys/fs/cgroup/memory/helloworld
-root@debian11:~# ls -l  /sys/fs/cgroup/helloworld +
-total 0 +
--r--r--r-- 1 root root 0 Apr 30 17:13 cgroup.controllers +
--r--r--r-- 1 root root 0 Apr 30 17:13 cgroup.events +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.freeze +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.max.depth +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.max.descendants +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.procs +
--r--r--r-- 1 root root 0 Apr 30 17:13 cgroup.stat +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.subtree_control +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.threads +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cgroup.type +
--rw-r--r-- 1 root root 0 Apr 30 17:13 cpu.pressure +
--r--r--r-- 1 root root 0 Apr 30 17:13 cpu.stat +
--rw-r--r-- 1 root root 0 Apr 30 17:13 io.pressure +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.current +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.events +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.events.local +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.high +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.low +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.max +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.min +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.numa_stat +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.oom.group +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.pressure +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.stat +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.swap.current +
--r--r--r-- 1 root root 0 Apr 30 17:13 memory.swap.events +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.swap.high +
--rw-r--r-- 1 root root 0 Apr 30 17:13 memory.swap.max +
--r--r--r-- 1 root root 0 Apr 30 17:13 pids.current +
--r--r--r-- 1 root root 0 Apr 30 17:13 pids.events +
--rw-r--r-- 1 root root 0 Apr 30 17:13 pids.max+
 </code> </code>
- 
-HERE 
  
 Par défaut, ce CGroup héritera de l'ensemble de la mémoire disponible. Pour éviter cela, créez maintenant une limite de **40000000** octets pour ce CGroup : Par défaut, ce CGroup héritera de l'ensemble de la mémoire disponible. Pour éviter cela, créez maintenant une limite de **40000000** octets pour ce CGroup :
  
 <code> <code>
-[root@centos8 ~]# echo 40000000 > /sys/fs/cgroup/helloworld/memory.max +root@debian11:~# echo 40000000 > /sys/fs/cgroup/memory/helloworld/memory.limit_in_bytes 
-[root@centos8 ~]# cat /sys/fs/cgroup/memory/helloworld/memory.limit_in_bytes+root@debian11:~# cat /sys/fs/cgroup/memory/helloworld/memory.limit_in_bytes
 39997440 39997440
 </code> </code>
Ligne 2615: Ligne 2645:
  
 <code> <code>
-[root@centos8 ~]# ./hello-world.sh & +root@debian11:~# ./hello-world.sh & 
-[1] 35148 +[1] 1073 
- +root@debian11:~# hello world
-[root@centos8 ~]# hello world+
 [Entrée] [Entrée]
  
-[root@centos8 ~]# ps aux | grep hello-world +root@debian11:~# ps aux | grep hello-world 
-root       35148  0.0  0.0  12724  2980 pts/      08:48   0:00 /bin/bash ./hello-world.sh +root        1073  0.0  0.0   6756  3100 pts/      06:33   0:00 /bin/bash ./hello-world.sh 
-root       35151  0.0  0.0  12136  1044 pts/   S+   08:48   0:00 grep --color=auto hello-world+root        1077  0.0  0.0   6180   712 pts/   R+   06:34   0:00 grep hello-world
 </code> </code>
  
Ligne 2629: Ligne 2658:
  
 <code> <code>
-[root@centos8 ~]# ps -ww -o cgroup 35148+root@debian11:~# ps -ww -o cgroup 1073
 CGROUP CGROUP
-12:memory:/user.slice/user-1000.slice/session-7.scope,7:devices:/user.slice,4:pids:/user.slice/user-1000.slice/session-7.scope,2:blkio:/user.slice,1:name=systemd:/user.slice/user-1000.slice/session-7.scope+8:devices:/user.slice,7:pids:/user.slice/user-1000.slice/session-3.scope,5:memory:/user.slice/user-1000.slice/session-3.scope,1:name=systemd:/user.slice/user-1000.slice/session-3.scope,0::/user.slice/user-1000.slice/session-3.scope
 </code> </code>
  
Ligne 2637: Ligne 2666:
  
 <code> <code>
-[root@centos8 ~]# echo 35148 > /sys/fs/cgroup/memory/helloworld/cgroup.procs+root@debian11:~# echo 1073 > /sys/fs/cgroup/memory/helloworld/cgroup.procs
 </code> </code>
  
-Notez maintenant l'héritage de la limitation de la mémoire - **12:memory:/helloworld** :+Notez maintenant l'héritage de la limitation de la mémoire - **5:memory:/helloworld** :
  
 <code> <code>
-[root@centos8 ~]# ps -ww -o cgroup 35148+root@debian11:~# ps -ww -o cgroup 1073
 CGROUP CGROUP
-12:memory:/helloworld,7:devices:/user.slice,4:pids:/user.slice/user-1000.slice/session-7.scope,2:blkio:/user.slice,1:name=systemd:/user.slice/user-1000.slice/session-7.scope+8:devices:/user.slice,7:pids:/user.slice/user-1000.slice/session-3.scope,5:memory:/helloworld,1:name=systemd:/user.slice/user-1000.slice/session-3.scope,0::/user.slice/user-1000.slice/session-3.scope
 </code> </code>
  
Ligne 2651: Ligne 2680:
  
 <code> <code>
-[root@centos8 ~]# cat /sys/fs/cgroup/memory/helloworld/memory.usage_in_bytes+root@debian11:~# cat /sys/fs/cgroup/memory/helloworld/memory.usage_in_bytes
 274432 274432
 </code> </code>
Ligne 2658: Ligne 2687:
  
 <code> <code>
-[root@centos8 ~]# kill 35148 +root@debian11:~# kill 1073 
-[root@centos8 ~]# ps aux | grep hello-world +root@debian11:~# ps aux | grep hello-world 
-root       35307  0.0  0.0  12136  1112 pts/   S+   08:55   0:00 grep --color=auto hello-world+root        1086  0.0  0.0   6180   716 pts/   S+   06:37   0:00 grep hello-world
 [1]+  Terminated              ./hello-world.sh [1]+  Terminated              ./hello-world.sh
 </code> </code>
Ligne 2667: Ligne 2696:
  
 <code> <code>
-[root@centos8 ~]# mkdir /sys/fs/cgroup/memory/helloworld1 +root@debian11:~# mkdir /sys/fs/cgroup/memory/helloworld1 
-[root@centos8 ~]# echo 6000 > /sys/fs/cgroup/memory/helloworld1/memory.limit_in_bytes +root@debian11:~# echo 6000 > /sys/fs/cgroup/memory/helloworld1/memory.limit_in_bytes 
-[root@centos8 ~]# cat /sys/fs/cgroup/memory/helloworld1/memory.limit_in_bytes+root@debian11:~# cat /sys/fs/cgroup/memory/helloworld1/memory.limit_in_bytes
 4096 4096
 </code> </code>
Ligne 2676: Ligne 2705:
  
 <code> <code>
-[root@centos8 ~]# ./hello-world.sh & +root@debian11:~# ./hello-world.sh & 
-[1] 35389+[1] 1089
  
-[root@centos8 ~]# hello world+root@debian11:~# hello world
 [Entrée] [Entrée]
  
-[root@centos8 ~]# echo 35389 > /sys/fs/cgroup/memory/helloworld1/cgroup.procs+root@debian11:~# echo 1089 > /sys/fs/cgroup/memory/helloworld1/cgroup.procs
 </code> </code>
  
Ligne 2688: Ligne 2717:
  
 <code> <code>
-[root@centos8 ~]# hello world +root@debian11:~# ps aux | grep hello-world 
-[Entrée]+root        1100  0.0  0.0   6180   720 pts/0    S+   06:45   0:00 grep hello-world
 [1]+  Killed                  ./hello-world.sh [1]+  Killed                  ./hello-world.sh
 </code> </code>
  
-===La Commande cgcreate===+Notez la trace dans le fichier **/var/log/messages** : 
 + 
 +<code> 
 +root@debian11:~# tail /var/log/messages 
 +May  4 06:44:43 debian11 kernel: [  994.012423] workingset_nodereclaim 0 
 +May  4 06:44:43 debian11 kernel: [  994.012423] pgfault 0 
 +May  4 06:44:43 debian11 kernel: [  994.012423] pgmajfault 0 
 +May  4 06:44:43 debian11 kernel: [  994.012423] pgrefill 0 
 +May  4 06:44:43 debian11 kernel: [  994.012423] pgscan 0 
 +May  4 06:44:43 debian11 kernel: [  994.012423] pgsteal 0 
 +May  4 06:44:43 debian11 kernel: [  994.012425] Tasks state (memory values in pages): 
 +May  4 06:44:43 debian11 kernel: [  994.012426] [  pid  ]   uid  tgid total_vm      rss pgtables_bytes swapents oom_score_adj name 
 +May  4 06:44:43 debian11 kernel: [  994.012428] [   1089]      1089     1689      780    53248        0             0 hello-world.sh 
 +May  4 06:44:43 debian11 kernel: [  994.012430] oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=/,mems_allowed=0,oom_memcg=/helloworld1,task_memcg=/helloworld1,task=hello-world.sh,pid=1089,uid=0 
 +</code> 
 + 
 +==La Commande cgcreate==
  
 Cette commande permet la création d'un CGroup : Cette commande permet la création d'un CGroup :
  
 <code> <code>
-[root@centos8 ~]# cgcreate -g memory:helloworld2 +root@debian11:~# cgcreate -g memory:helloworld2 
-[root@centos8 ~]# ls -l /sys/fs/cgroup/memory/helloworld2/+ 
 +root@debian11:~# ls -l /sys/fs/cgroup/memory/helloworld2/
 total 0 total 0
--rw-rw-r--1 root root 0 Jul 13 10:39 cgroup.clone_children +-rw-r--r-- 1 root root 0 May  4 06:47 cgroup.clone_children 
---w--w----. 1 root root 0 Jul 13 10:39 cgroup.event_control +--w--w--w- 1 root root 0 May  4 06:47 cgroup.event_control 
--rw-rw-r--1 root root 0 Jul 13 10:39 cgroup.procs +-rw-r--r-- 1 root root 0 May  4 06:47 cgroup.procs 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.failcnt +-rw-r--r-- 1 root root 0 May  4 06:47 memory.failcnt 
---w--w----1 root root 0 Jul 13 10:39 memory.force_empty +--w------1 root root 0 May  4 06:47 memory.force_empty 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.failcnt +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:39 memory.kmem.slabinfo +-r--r--r-- 1 root root 0 May  4 06:47 memory.kmem.slabinfo 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.tcp.failcnt +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.tcp.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.tcp.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.tcp.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.kmem.tcp.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.kmem.tcp.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:39 memory.kmem.tcp.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:47 memory.kmem.tcp.usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:39 memory.kmem.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:47 memory.kmem.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.max_usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.memsw.failcnt +-rw-r--r-- 1 root root 0 May  4 06:47 memory.memsw.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.memsw.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.memsw.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.memsw.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.memsw.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:39 memory.memsw.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:47 memory.memsw.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.move_charge_at_immigrate +-rw-r--r-- 1 root root 0 May  4 06:47 memory.move_charge_at_immigrate 
--r--r--r--1 root root 0 Jul 13 10:39 memory.numa_stat +-r--r--r-- 1 root root 0 May  4 06:47 memory.numa_stat 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.oom_control +-rw-r--r-- 1 root root 0 May  4 06:47 memory.oom_control 
-----------1 root root 0 Jul 13 10:39 memory.pressure_level +---------- 1 root root 0 May  4 06:47 memory.pressure_level 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.soft_limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:47 memory.soft_limit_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:39 memory.stat +-r--r--r-- 1 root root 0 May  4 06:47 memory.stat 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.swappiness +-rw-r--r-- 1 root root 0 May  4 06:47 memory.swappiness 
--r--r--r--1 root root 0 Jul 13 10:39 memory.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:47 memory.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:39 memory.use_hierarchy +-rw-r--r-- 1 root root 0 May  4 06:47 memory.use_hierarchy 
--rw-rw-r--1 root root 0 Jul 13 10:39 notify_on_release +-rw-r--r-- 1 root root 0 May  4 06:47 notify_on_release 
--rw-rw-r--1 root root 0 Jul 13 10:39 tasks+-rw-r--r-- 1 root root 0 May  4 06:47 tasks
 </code> </code>
  
Ligne 2737: Ligne 2783:
  
 <code> <code>
-[root@centos8 ~]# echo 40000000 > /sys/fs/cgroup/memory/helloworld2/memory.limit_in_bytes+root@debian11:~# echo 40000000 > /sys/fs/cgroup/memory/helloworld2/memory.limit_in_bytes
 </code> </code>
  
Ligne 2745: Ligne 2791:
  
 <code> <code>
-[root@centos8 ~]# cgexec -g memory:helloworld2 ./hello-world.sh & +root@debian11:~# cgexec -g memory:helloworld2 ./hello-world.sh & 
-[1] 37670+[1] 1106
  
-[root@centos8 ~]# hello world+root@debian11:~# hello world
 [Entrée] [Entrée]
  
-[root@centos8 ~]+root@debian11:~# cat /sys/fs/cgroup/memory/helloworld2/cgroup.procs  
 +1106 
 +1107 
 +root@debian11:~# ps aux | grep 110 
 +root        1106  0.0  0.0   6756  3060 pts/0    S    06:48   0:00 /bin/bash ./hello-world.sh 
 +root        1107  0.0  0.0   5304   508 pts/0    S    06:48   0:00 sleep 360 
 +root        1108  0.0  0.0      0     0 ?        I    06:49   0:00 [kworker/1:0-events_freezable] 
 +root        1113  0.0  0.0   6180   652 pts/0    S+   06:50   0:00 grep 110
 </code> </code>
  
Ligne 2759: Ligne 2812:
  
 <code> <code>
-[root@centos8 ~]# ps aux | grep *.sh +root@debian11:~# kill 1106 
-root       37670  0.0  0.0  12724  3112 pts/      10:41   0:00 /bin/bash ./hello-world.sh +root@debian11:~# ps aux | grep 110 
-root       37685  0.0  0.0  12136  1148 pts/1    S+   10:42   0:00 grep --color=auto hello-world.sh +root        1107  0.0  0.0   5304   508 pts/      06:48   0:00 sleep 360 
- +root        1108  0.0  0.0          0 ?        I    06:49   0:00 [kworker/1:0-mm_percpu_wq
-[root@centos8 ~]# kill 37670 +root        1115  0.0  0.0   6180   716 pts/   R+   06:51   0:00 grep 110
- +
-root@centos8 ~]# ps aux | grep *.sh +
-root       37726  0.0  0.0  12136  1156 pts/   R+   10:43   0:00 grep --color=auto hello-world.sh+
 [1]+  Terminated              cgexec -g memory:helloworld2 ./hello-world.sh [1]+  Terminated              cgexec -g memory:helloworld2 ./hello-world.sh
  
-[root@centos8 ~]# cgdelete memory:helloworld2+root@debian11:~# cgdelete memory:helloworld2
  
-[root@centos8 ~]# ls -l /sys/fs/cgroup/memory/helloworld2/+root@debian11:~# ls -l /sys/fs/cgroup/memory/helloworld2/
 ls: cannot access '/sys/fs/cgroup/memory/helloworld2/': No such file or directory ls: cannot access '/sys/fs/cgroup/memory/helloworld2/': No such file or directory
 </code> </code>
Ligne 2780: Ligne 2830:
  
 <code> <code>
-[root@centos8 ~]# vi /etc/cgconfig.conf +root@debian11:~# vi /etc/cgconfig.conf 
-[root@centos8 ~]# cat /etc/cgconfig.conf +root@debian11:~# cat /etc/cgconfig.conf
-+
-#  Copyright IBM Corporation. 2007 +
-+
-#  Authors:     Balbir Singh <balbir@linux.vnet.ibm.com> +
-#  This program is free software; you can redistribute it and/or modify it +
-#  under the terms of version 2.1 of the GNU Lesser General Public License +
-#  as published by the Free Software Foundation. +
-+
-#  This program is distributed in the hope that it would be useful, but +
-#  WITHOUT ANY WARRANTY; without even the implied warranty of +
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +
-+
-+
-# By default, we expect systemd mounts everything on boot, +
-# so there is not much to do. +
-# See man cgconfig.conf for further details, how to create groups +
-# on system boot using this file.+
 group helloworld2 { group helloworld2 {
         cpu {         cpu {
Ligne 2816: Ligne 2849:
  
 <code> <code>
-[root@centos8 ~]# cgcreate -g memory:helloworld2 +root@debian11:~# cgcreate -g memory:helloworld2 
-[root@centos8 ~]# ls -l /sys/fs/cgroup/memory/helloworld2/+ 
 +root@debian11:~# ls -l /sys/fs/cgroup/memory/helloworld2/
 total 0 total 0
--rw-rw-r--1 root root 0 Jul 13 10:46 cgroup.clone_children +-rw-r--r-- 1 root root 0 May  4 06:53 cgroup.clone_children 
---w--w----. 1 root root 0 Jul 13 10:46 cgroup.event_control +--w--w--w- 1 root root 0 May  4 06:53 cgroup.event_control 
--rw-rw-r--1 root root 0 Jul 13 10:46 cgroup.procs +-rw-r--r-- 1 root root 0 May  4 06:53 cgroup.procs 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.failcnt +-rw-r--r-- 1 root root 0 May  4 06:53 memory.failcnt 
---w--w----1 root root 0 Jul 13 10:46 memory.force_empty +--w------1 root root 0 May  4 06:53 memory.force_empty 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.failcnt +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:46 memory.kmem.slabinfo +-r--r--r-- 1 root root 0 May  4 06:53 memory.kmem.slabinfo 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.tcp.failcnt +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.tcp.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.tcp.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.tcp.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.kmem.tcp.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.kmem.tcp.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:46 memory.kmem.tcp.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:53 memory.kmem.tcp.usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:46 memory.kmem.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:53 memory.kmem.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.max_usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.memsw.failcnt +-rw-r--r-- 1 root root 0 May  4 06:53 memory.memsw.failcnt 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.memsw.limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.memsw.limit_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.memsw.max_usage_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.memsw.max_usage_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:46 memory.memsw.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:53 memory.memsw.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.move_charge_at_immigrate +-rw-r--r-- 1 root root 0 May  4 06:53 memory.move_charge_at_immigrate 
--r--r--r--1 root root 0 Jul 13 10:46 memory.numa_stat +-r--r--r-- 1 root root 0 May  4 06:53 memory.numa_stat 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.oom_control +-rw-r--r-- 1 root root 0 May  4 06:53 memory.oom_control 
-----------1 root root 0 Jul 13 10:46 memory.pressure_level +---------- 1 root root 0 May  4 06:53 memory.pressure_level 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.soft_limit_in_bytes +-rw-r--r-- 1 root root 0 May  4 06:53 memory.soft_limit_in_bytes 
--r--r--r--1 root root 0 Jul 13 10:46 memory.stat +-r--r--r-- 1 root root 0 May  4 06:53 memory.stat 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.swappiness +-rw-r--r-- 1 root root 0 May  4 06:53 memory.swappiness 
--r--r--r--1 root root 0 Jul 13 10:46 memory.usage_in_bytes +-r--r--r-- 1 root root 0 May  4 06:53 memory.usage_in_bytes 
--rw-rw-r--1 root root 0 Jul 13 10:46 memory.use_hierarchy +-rw-r--r-- 1 root root 0 May  4 06:53 memory.use_hierarchy 
--rw-rw-r--1 root root 0 Jul 13 10:46 notify_on_release +-rw-r--r-- 1 root root 0 May  4 06:53 notify_on_release 
--rw-rw-r--1 root root 0 Jul 13 10:46 tasks+-rw-r--r-- 1 root root 0 May  4 06:53 tasks
 </code> </code>
  
 <code> <code>
-[root@centos8 ~]# cgcreate -g cpu:helloworld2 +root@debian11:~# cgcreate -g cpu:helloworld2 
-[root@centos8 ~]# ls -l /sys/fs/cgroup/cpu/helloworld2/+ 
 +root@debian11:~# ls -l /sys/fs/cgroup/cpu/helloworld2/
 total 0 total 0
--rw-rw-r--1 root root 0 Jul 13 10:47 cgroup.clone_children +-rw-r--r-- 1 root root 0 May  4 06:54 cgroup.clone_children 
--rw-rw-r--1 root root 0 Jul 13 10:47 cgroup.procs +-rw-r--r-- 1 root root 0 May  4 06:54 cgroup.procs 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.stat +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.stat 
--rw-rw-r--1 root root 0 Jul 13 10:47 cpuacct.usage +-rw-r--r-- 1 root root 0 May  4 06:54 cpuacct.usage 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_all +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_all 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_percpu +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_percpu 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_percpu_sys +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_percpu_sys 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_percpu_user +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_percpu_user 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_sys +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_sys 
--r--r--r--1 root root 0 Jul 13 10:47 cpuacct.usage_user +-r--r--r-- 1 root root 0 May  4 06:54 cpuacct.usage_user 
--rw-rw-r--1 root root 0 Jul 13 10:47 cpu.cfs_period_us +-rw-r--r-- 1 root root 0 May  4 06:54 cpu.cfs_period_us 
--rw-rw-r--. 1 root root 0 Jul 13 10:47 cpu.cfs_quota_us +-rw-r--r-- 1 root root 0 May  4 06:54 cpu.cfs_quota_us 
--rw-rw-r--1 root root 0 Jul 13 10:47 cpu.rt_period_us +-rw-r--r-- 1 root root 0 May  4 06:54 cpu.shares 
--rw-rw-r--. 1 root root 0 Jul 13 10:47 cpu.rt_runtime_us +-r--r--r-- 1 root root 0 May  4 06:54 cpu.stat 
--rw-rw-r--1 root root 0 Jul 13 10:47 cpu.shares +-rw-r--r-- 1 root root 0 May  4 06:54 notify_on_release 
--r--r--r--1 root root 0 Jul 13 10:47 cpu.stat +-rw-r--r-- 1 root root 0 May  4 06:54 tasks
--rw-rw-r--1 root root 0 Jul 13 10:47 notify_on_release +
--rw-rw-r--1 root root 0 Jul 13 10:47 tasks+
 </code> </code>
  
Ligne 2881: Ligne 2914:
  
 <code> <code>
-[root@centos8 ~]# cgconfigparser -l /etc/cgconfig.conf +root@debian11:~# cgconfigparser -l /etc/cgconfig.conf 
-[root@centos8 ~]# cat /sys/fs/cgroup/memory/helloworld2/memory.limit_in_bytes+ 
 +root@debian11:~# cat /sys/fs/cgroup/memory/helloworld2/memory.limit_in_bytes
 36864 36864
-[root@centos8 ~]# cat /sys/fs/cgroup/cpu/helloworld2/cpu.shares+ 
 +root@debian11:~# cat /sys/fs/cgroup/cpu/helloworld2/cpu.shares
 100 100
 </code> </code>
 +
  
 ----- -----
 Copyright © 2022 Hugh Norris. Copyright © 2022 Hugh Norris.
Menu