Question: How to limit user “testme” memory resources, for example, the user “testme” will be only able to get 100mb of memory from the System.
ulimit won’t be able to achieve this goal as ulimit limit user memory consumption per process – in this case, the customer would like to set user “testme” memory quota to 100mb.
1. To achieve simple solution of limiting users memory resources is to do:
# vi /etc/cgconfig.conf
Add there:
group memlimit { memory { memory.limit_in_bytes = 104857600; } }
Above will create cgroup called memlimit where limit is 100mb
2. Now edit another file:
# vi /etc/cgrules.conf
Add there:
testme memory memlimit/
This will tell cgroups that user testme will be added to memlimit cgroup and will be able to take only 100mb from the system.
3. Restart the cgred and cgconfig service and enable them to start at boot with chkconfig:
# service cgred restart # service cgconfig restart
# chkconfig cgred on # chkconfig cgconfig on
Above commands will start cgred/cgconfig and make sure that they will also start on boot of the system. Now user testme should be able to take only 100mb from memory resources.