Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to understand cgroups better and would like to understand the use-cases for applying cgroups.

Are cgroups a good way for prioritizing different applications (i.e, giving higher priority to specific types of applications like web servers)?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There are several uses for cgroups. From the system administration probably the most important one is limiting resources - the classical example here being is the cpu access. If you create a group for e.g. sshd and give it some non-negligible CPU time share (compared to other groups or the default under which fall all unsorted processes), you are guaranteed to being able to login even in times when the machine will be running a CPU-intensive tasks.

More interestingly, if you give this "remote access" processes much higher CPU share then the rest, you will be able to log in almost instantly (because the ssh daemon will be prioritised over the rest of running processes) while you won't hurt the overall computation strength of the machine, since the resources are allocated only on a per-need basis. You usually want to do this together with I/O (including network) prioritisation. However, as John correctly points out in the comment below, one doesn't want to do these things carelessly (since it might fire back in an unexpected way). Important thing to bear in mind is, that the groups are inherited by default - i.e. one doesn't want to start a memory/CPU hog from such an ssh session. Yet for this there are mechanisms that can assign processes to cgroups as they start.

Another use is isolating the processes from each other - in combination with other features (namespace isolation) in recent Linux kernels they are used to create OS-level virtualization like the LXC (Linux Containers).

Other than that you can do various accounting and control stuff (freezing some processes groups, assigning them to specific CPU cores etc.).

The two links here, should be a reasonable starting place if you are looking for more information. You may also want to check Documentation/cgroups directory in the Linux kernel source tree.

share|improve this answer
    
thank you. the sshd example is interesting and brings up another related thought. one aspect i hadn't considered is ensuring other resources are allocated appropriately - i'm assuming that someone with incomplete knowledge of the profile of an application can wreak havoc by only allocating resources for CPU (in this example) and no allocation for I/O (say network). If so - are there well known profiles for cgroups published anywhere? –  Johnnie Nov 24 '12 at 20:21
    
@John interesting question indeed. You might want to check distributions which have systemd, which (ab)uses cgroups for its own purposes - the systemd unit files for services might give some clues about what might be reasonable. But in the end it's always up to the system administrator to learn the hard way, what really is not the "Good Idea (TM)". –  peterph Nov 24 '12 at 20:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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