• 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

CentOS / RHEL 6 : How to limit memory resources for a specific user using cgroups

by admin

Control groups (strong>cgroups) enable you to allocate computing resources to specific processes or tasks. You can assign a set of CPU and memory to a specific group of tasks or even to a specific user. The post here details out the steps to allocate a defined memory resource to a specific use. Ulimit won’t be able to achieve this goal as ulimit limits user memory consumption per process. The best possible option is to use cgroups. With cgroups users can be limited not only to meomry resources but as well CPU/IO. Let’s see an example to limit the memory used by user “john” to 100mb.

Limiting the memory for a specific user

1. Edit the cgroups configuration file /etc/cgconfig.conf and add the below lines

# vi /etc/cgconfig.conf
group memlimit {
	memory {
		memory.limit_in_bytes = 104857600;    #### limit memory to 100MB
	}
}

Above peice of code will create cgroup called memlimit where limit is 100mb.

2. Now edit another file /etc/cgrules.conf and add below line:

# vi /etc/cgrules.conf
john memory memlimit

This will tell cgroups that user john will be added to memlimit cgroup and will be able to take only 100mb from the system.

3. Once you are done with editing the configuration files, restart the services cgred and cgconfig.

# service cgred restart
# service cgconfig restart
cgconfig(control group config) service – used to create cgroups and manage subsystems
cgred (control group rules engine daemon) service – used to moves tasks into cgroups according to parameters set in the /etc/cgrules.conf file.

4. Enable both the services to start on system boot. With this we make sure the configuration files /etc/cgconfig.conf and /etc/cgrules.conf are readt at boot time and cgroups are created.

# chkconfig cgred on
# chkconfig cgconfig on

Filed Under: Linux

Some more articles you might also be interested in …

  1. What is the difference between the -i and -U options used in rpm command in Linux
  2. CentOS / RHEL 5 : How to Configure kdump
  3. cpuid Command Examples in Linux
  4. lrzuntar: command not found
  5. How to audit all Commands run on OEL 5,6 using auditd
  6. dir Command Examples in Linux
  7. csplit Command Examples in Linux
  8. Linux / UNIX : How to send mails with attachments using mailx command
  9. How to persistently set nr_requests using UDEV rules
  10. fcrackzip Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright