4

I know those two mechanisms (let's call them A and B) limit the resource for a process.

I want to know the cooperation of those two.

If A limits a resource for a process, then what happens when B also limits the same resource?

2

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.

6

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.

  • what happen if process "one" started by a shell and limit with ulimit and also this "one" be added to a cgroup and it limited by a cgroup policy? – lovespring Aug 12 '16 at 12:50
  • The question you ask, is like saying "what will happen if we set both attributes and ACLs on a file or directory? What if we also add some special restrictions for each user?" The answer is, we're just adding more layers, and use each for some that the other is not available of performing. In fact, ulimit has nothing to do with per-process settings or anything related to throttling velocities. This is what cgroups kernel extension is capable of. It can even allow hierarchies of settings to be defined. (it's just one of the features it has) – FarazX Aug 12 '16 at 13:16
  • In other words, you may think they both do the same job, no they are not, but I agree that's similar. In fact, we should say cgroups are considered for allocate resources among groups of tasks, while ulimit only works on a process level. – FarazX Aug 12 '16 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.