How important are the machine resources? How important is the correct usage of the machine resources? In spite of the computational capacity growth over the history due to the technology improvement, we still come up against the same problem: limited resources. Even in large quantities? Yes. It still happens because growth of the computational capacity is directly proportional to the complexity of the processes running concurrently. For a single user, resources are less important than other factors, but for a server who receive a high load of requests, having the resources available to meet the demand is indispensable and critical.
Today, there is a huge amount of servers running many Linux distributions: paid or not. Considering resources management, the Kernel Linux has an interesting feature since the version 2.6.24 called Control Groups. Popularly known as CGroups.
Basically, CGroups insert processes into groups and controls them. Each group, has its own rules for resources allocation/limitation. Further, the groups are called “control groups” and they provide three basic characteristics: limitation of available resources to one or more processes; isolation of the policies of the processes that are not part of the same group; control of the groups and processes.
So, considering the first item limitation of resources, the system can have a varied number of control groups. Each groups can limit the following machine’s resources: CPU, memory, disk I/O and/or network I/O.
About isolation, each group has its own rules and policies, in which a process inside a group is surrendered only to the policies of that particular group. Moreover, CGroups extends the rules and policies using an hierarchical approach. Whenever a process from a particular group creates a child process, this new process and its children automatically become part of the group.
Lastly, considering control, the system administrator can reorganize the processes between the groups, remove and create new groups, add processes inside groups and change or define new groups policies for existing groups.
According to the figure, lets suppose a Linux system that uses CGroups and has two groups, one called “CPU Bound” and another one called “Disk I/O Bound”. The first group contains critical processes who demands CPU usage. A “Process A” inside this group can only require up to 40% of CPU usage and 20% of Memory usage. In the second group, only critical processes who demands Disk I/O. A “Process B” was added inside this group and it can requires up to 40% of Disk usage and 10% of Memory usage. A “Process C” is not part of any group and it does not follow any rule or policy, the process is free to allocate resources.
Besides, if the “Process A” uses only 5% of CPU usage, the “Process C” can require 95% or more, according the current usage of “Process A”. This model avoids a critical process waiting for an unavailable resource that is being used by an ordinary process. Considering the hierarchy of CGroups, if “Process A” forks a child process called “Process A'”, this process will follow the same rules and policies of “Process A”.
Until now, it is clear what it the main purpose of CGroups design: limit the available resources of a system/machine. But, in the new era of Cloud Computing and dynamic allocation, it does not make sense to limit resources. If a set of application running in the cloud are using 100% of CPU usage, it would be enough to allocate more cores to free CPU usage. This approach can be more expensive. Maybe, an study to qualify which applications is critical and apply rules to limit resources can prevent extra costs.
For this reason, CGroups are related to Cloud Computing. OpenStack uses it to keep the quota resources of the virtual machines, for example. On the other hand, Cloud who runs Containers such as Docker and LXC uses CGroups exactly to limit the resources available for a Container.
In conclusion, CGroups can ensure the right usage of the system resources, providing ways to manage and plan them to obtain a better performance with the lowest loss.
The original text is in Portuguese and can be accessed here.