• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to configure Linux Resource Groups (cgroups) for MySQL

by admin

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 (/etc/cgconfig.conf) and add below configuration.

# 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 – /etc/cgrules.conf with below configuration:

# 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:

a. To find resource limits:

$ cgget -r memory.stat mysqldb

b. To set resource limits:

$ cgset -r blkio.throttle.read_bps_device="8:1 0" iocap1

c. To save the current modified config for future use:

$ cgsnapshot -s > current_cgconfig.conf

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. How to use auditd to monitor a file deletion in Linux
  2. Linux OS Service ‘NetworkManager’
  3. Difference between the Java heap and native C heap
  4. poweroff Command Examples in Linux
  5. How to install CentOS / RHEL 7 on RAID Partition
  6. Understanding /etc/group file
  7. pvcreate Fails With Error: “Device /dev/mapper/mpatha Not Found (or Ignored By Filtering).”
  8. sesearch: command not found
  9. CentOS / RHEL 7 : How to start / Stop or enable / disable Firewalld
  10. runlevel Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright