The following provides the procedure for configuring and using resource groups under Linux:
1. To use cgroups, you must install the “libcgroup” package on your system:
# yum install libcgroup
2. Create a config file for cgroups:
# vi /etc/cgconfig.conf mount { cpu = /cgroup/cpumem; cpuset = /cgroup/cpumem; memory = /cgroup/cpumem; } # High priority group group mysqldb { cpu { # Allocate the relative share of CPU resources equal to 75% cpu.shares="750"; } cpuset { # No alternate memory nodes if the system is not NUMA cpuset.mems="0"; # Allocate CPU cores 2 through 5 to tasks in the cgroup cpuset.cpus="2-5"; } memory { # Allocate at most 8 GB of memory to tasks memory.limit_in_bytes="8G"; # Allocate at most 16 GB of memory+swap to tasks memory.memsw.limit_in_bytes="16G"; # Apply a soft limit of 4 GB to tasks memory.soft_limit_in_bytes="4G"; } }
3. Create a cgroup rules definition file:
# vi /etc/cgrules.conf # Assign tasks run by the mysql user to mysqldb mysql cpu,cpuset,memory mysqldb
4. Start the cgconfig service and configure it to start when the system is booted.
$ service cgconfig start $ chkconfig cgconfig on
5. At this point, the resource group for mysql is ready and in place. Restart mysqld and it will be allowed resources according to the config and rules provided above.
6. You can find and change the resource group limits during runtime as well.
– To find resource limits:
$ cgget -r memory.stat mysqldb
– To set resource limits:
$ cgset -r blkio.throttle.read_bps_device="8:1 0" iocap1
– To save the current modified config for future use:
$ cgsnapshot -s > current_cgconfig.conf