Setting Up Linux Cgroups
January 18, 2011
Last week's column introduced Linux Control Groups (or cgroups), a feature initially developed to limit resource usage in the Linux kernel. But it can do much more, including tweak memory, bandwidth and CPU usage of system processes as well as deny access to system resources. This week, let's delve a bit deeper and actually set up and manage a cgroup.
One of the reasons I'm writing about this topic is that, while useful, it seems vastly under-used and definitely could be simpler. Right now it's as user friendly as SELinux. But if more folks use the feature, it will get more attention -- and likely improve.
On Fedora 14, you'll want the
Simple Configuration of Cgroups
Let's start by confirming that the service starts as advertised. On F14, run
There's more than that, but you get the idea. If you want to create a limit for maximum memory usage, it's stored in a file called
Let's say you want to limit the memory provided to a daemon and all the processes it spawns. How about Apache? First you'll create a group statement in
Next, add this to the
You should be good to go. Just start the
I could write much more about cgroups, and I may return to the topic again if there's sufficient interest -- let me know in the comments. In the meantime, the Fedora wiki is a good source of info on the topic, despite being written ahead of the Fedora 11 release (as of this writing, anyway), so some bits may be slightly out of date.
Joe 'Zonker' Brockmeier is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at email@example.com and follow him on Twitter.