Skip to main content
Asked a question recently

How do I set per-user resource limits with Cgroups?

Where am I?

In Bright Computing, Inc. you can ask and answer questions and share your experience with others!

How do I set per-user resource limits with Cgroups?

You can use cgroups to set various resource limits for users. For example, you might add an entry like this to /etc/cgconfig.conf for restricting memory usage by users:


group memlimit {
   memory {
       memory.limit_in_bytes = 4294967296;
   }
}
 

That creates a memlimit cgroup with a memory limit of about 4 GB. 

In /etc/cgrules.conf, you will need to add entries that map users to that memlimit cgroup. Here's an example of adding an individual user entry:


sean memory memlimit/

Now all of user sean's processes will run in the memlimit cgroups and be bound to its memory limit. For details on how to add groups or other types of entries, you may refer to the man page for cgrules.conf:


# man 5 cgrules.conf