About ulimit/setrlimit and cgroup

ulimit/setrlimit/getrlimit

The ulimit shell command (executable program) is a wrapper around the setrlimit system call (function provided by the kernel), and the underlying data structure which contains the limit information is called rlimit.

ulimit shell command controls the soft and hard limits over the resources available to the shell and to processes started by it.

getrlimit() and setrlimit() system calls get and set resources limits respectively, where the assicoated soft and hard limits are defined by the rlimit structure.

For more information, use: man 1 ulimit and man 2 setrlimit

Cgroups

Cgroups (Control Groups) allow you to allocate resources — such as CPU time, system memory, network bandwidth, or combinations of these resources — among user-defined groups of tasks (processes) running on a system.

D.M. ulimit has nothing to do with per-process settings or anything related to throttling velocities. This is what cgroups kernel extension is capable of and is used for. To mention one of the other features it provides, we can say it can even allow hierarchies of settings to be defined.

N.B. I recommend you read this article for a quick vision on ulimit/setrlimit. And for cgroups (Control Groups), I recommend you read RedHat official documentation.


All limits apply independently. When a process makes a request that would require going over some limit, the request is denied. This holds whether the limit is for a cgroup, per process, or per user.

Since cgroup sets limits per groups of processes, and setrlimit sets limits per user or per process, the mechanisms are generally not redundant. It's possible for a given request to exceed both cgroup and setrlimit limits, or only one of them.

Keep in mind that all limits are maximum allowed values, not guaranteed minimums. For example, if there's a limit to 1GB of memory per process, a process with 200MB of memory may still get its request to allocate 100MB denied if there's no more available memory in the system, regardless of any applicable limits. If a setrlimit and a cgroup limit both apply, then that's at least three maximums that can be exceeded: the setrlimit maximum, the cgroup maximum, and the currently available resource maximum.