From Fedora Project Wiki
Line 35: Line 35:


== Detailed Description ==
== Detailed Description ==
Since kernel 2.6.24, [http://kernelnewbies.org/Linux_2_6_24#head-5b7511c1e918963d347abc8ed4b75215877d3aa3 Linux has so called control groups] as a means to partition available resources between running processes. [http://libcg.sourceforge.net/ Libcgroups] makes that functionality available to programmers and contains two tools, <code>cgexec</code> and <code>cgclassify</code>, to start processes in a control group or move existing processes from one control group to another.


In Fedora there already is a package libcgroups with aforementioned tools, but the overall quality is very poor. There is almost no documentation, no man pages, no configuration file samples.
* this patr is implemented in kernel:
Resource Management/Control Groups
 
Control Groups provide a mechanism for aggregating/partitioning sets of
tasks, and all their future children, into hierarchical groups with
specialized behaviour.
 
Definitions:
A *cgroup* associates a set of tasks with a set of parameters for one
or more subsystems.
A *subsystem* is a module that makes use of the task grouping
facilities provided by cgroups to treat groups of tasks in
particular ways. A subsystem is typically a "resource controller" that
schedules a resource or applies per-cgroup limits, but it may be
anything that wants to act on a group of processes, e.g. a
virtualization subsystem.
A *hierarchy* is a set of cgroups arranged in a tree, such that
every task in the system is in exactly one of the cgroups in the
hierarchy, and a set of subsystems; each subsystem has system-specific
state attached to each cgroup in the hierarchy.  Each hierarchy has
an instance of the cgroup virtual filesystem associated with it.
At any one time there may be multiple active hierachies of task
cgroups. Each hierarchy is a partition of all tasks in the system.
User level code may create and destroy cgroups by name in an
instance of the cgroup virtual file system, specify and query to
which cgroup a task is assigned, and list the task pids assigned to
a cgroup. Those creations and assignments only affect the hierarchy
associated with that instance of the cgroup file system.
On their own, the only use for cgroups is for simple job
tracking. The intention is that other subsystems hook into the generic
cgroup support to provide new attributes for cgroups, such as
accounting/limiting the resources which processes in a cgroup can
access. For example, cpusets (see Documentation/cpusets.txt) allows
you to associate a set of CPUs and a set of memory nodes with the
tasks in each cgroup.
 
 
* tools part:
[http://libcg.sourceforge.net/ Libcgroups] makes that functionality available to programmers and contains two tools, <code>cgexec</code> and <code>cgclassify</code>, to start processes in a control group or move existing processes from one control group to another. In Fedora libcgroups package already is incorporat, but the overall quality is very poor. There is almost no documentation, no man pages, no configuration file samples, there should be done code review and created other necessary tools and improve instalations:


The goal for Fedora 11 is to improve this package where necessary, i.e.:
The goal for Fedora 11 is to improve this package where necessary, i.e.:
Line 49: Line 92:


The long term goal is to create new tools to e.g. create or modify persistent cgroups configuration and display control groups data.  
The long term goal is to create new tools to e.g. create or modify persistent cgroups configuration and display control groups data.  
At the beginning the focus will be on command line tools, but we'll keep in mind that in the long term we'll likely want to have graphical tools. These would offer similar functionality and we should try to make sure that any non-UI code written is usable from both kinds of frontends.  
At the beginning the focus will be on command line tools, but we'll keep in mind that in the long term we'll likely want to have graphical tools. These would offer similar functionality and we should try to make sure that any non-UI code written is usable from both kinds of frontends.


== Benefit to Fedora ==
== Benefit to Fedora ==

Revision as of 09:28, 19 February 2009

ControlGroups

Summary

Control Groups consists of two parts - is an upstream kernel feature that allows system resources to be partitioned/divided up amongst different processes, or a group of processes. The second part is to improve existing tools which handles with kernel control groups mechanism where necessary and feasible and/or to create new ones e.g. to create or modify cgroups configuration or display control groups data (using libcgroups package).

Owner

  • Linda Wang
    • email: lwang@redhat.com
  • Nils Philippsen
    • email: nphilipp@redhat.com
  • Ivana Varekova
    • email: varekova@redhat.com
  • Jan Šafránek
    • email: jsafrane@redhat.com

Current status

  * Overall CGROUP infrastructure [completed, in Fedora 10]
  * Sub-CGROUP features:
    * CPUSET [completed, in Fedora 10]
    * CPUACCT [completed, in Fedora 10]
    * MEMCTL [completed, in Fedora 10]
    * DEVICE [completed, in Fedora 10]
    * NETWORKING [new, targeted for Fedora 11]
    • tools part
  * man-pages
  * code review
  * spec-file cleanup
  * make file cleanup
  * ps option for cgroups
  * new tools
  • Last updated: 2009-02-19
  • Percentage of completion: 65%

Detailed Description

  • this patr is implemented in kernel:

Resource Management/Control Groups

Control Groups provide a mechanism for aggregating/partitioning sets of tasks, and all their future children, into hierarchical groups with specialized behaviour.

Definitions:

A *cgroup* associates a set of tasks with a set of parameters for one or more subsystems.

A *subsystem* is a module that makes use of the task grouping facilities provided by cgroups to treat groups of tasks in particular ways. A subsystem is typically a "resource controller" that schedules a resource or applies per-cgroup limits, but it may be anything that wants to act on a group of processes, e.g. a virtualization subsystem.

A *hierarchy* is a set of cgroups arranged in a tree, such that every task in the system is in exactly one of the cgroups in the hierarchy, and a set of subsystems; each subsystem has system-specific state attached to each cgroup in the hierarchy. Each hierarchy has an instance of the cgroup virtual filesystem associated with it.

At any one time there may be multiple active hierachies of task cgroups. Each hierarchy is a partition of all tasks in the system.

User level code may create and destroy cgroups by name in an instance of the cgroup virtual file system, specify and query to which cgroup a task is assigned, and list the task pids assigned to a cgroup. Those creations and assignments only affect the hierarchy associated with that instance of the cgroup file system.

On their own, the only use for cgroups is for simple job tracking. The intention is that other subsystems hook into the generic cgroup support to provide new attributes for cgroups, such as accounting/limiting the resources which processes in a cgroup can access. For example, cpusets (see Documentation/cpusets.txt) allows you to associate a set of CPUs and a set of memory nodes with the tasks in each cgroup.


  • tools part:

Libcgroups makes that functionality available to programmers and contains two tools, cgexec and cgclassify, to start processes in a control group or move existing processes from one control group to another. In Fedora libcgroups package already is incorporat, but the overall quality is very poor. There is almost no documentation, no man pages, no configuration file samples, there should be done code review and created other necessary tools and improve instalations:

The goal for Fedora 11 is to improve this package where necessary, i.e.:

  • bugfixing
  • add/fix documentation and man-pages
  • add examples
  • fix error handling
  • rework logging
  • create displaying tool (to see, in which control group is given process)
  • prepare a way, how to start a service daemon in given context group

The long term goal is to create new tools to e.g. create or modify persistent cgroups configuration and display control groups data. At the beginning the focus will be on command line tools, but we'll keep in mind that in the long term we'll likely want to have graphical tools. These would offer similar functionality and we should try to make sure that any non-UI code written is usable from both kinds of frontends.

Benefit to Fedora

Libcgroups handles the new kernel features which are able to restrict the sources for tasks. This project should help the user to make the best of this feature.

Scope

Required extended testing and fixing of libcgroups package and in time when libcgroups will be stable enough try to add start to write another parts - based on existing ones.

How To Test

For now it is necessary to have a kernel with cgroups support (Documentation/cgroups/cgroups.txt) and the libcgroup package. The user/tester must know, what cgroups are and what they are good for, the best is to read aforementioned kernel doc.

1. yum install libcgroup


  • Creating cgroups:
  1. Configure /etc/cgconfig.conf file - there should be nice example and man page packaged.
  2. Start/stop cgconfig service and test whether the created groups are as expected.


  • Moving task to groups:
  1. Prepare some cgroups, i.e. prepare /etc/cgconfig.conf and start cgconfig service.
  2. Start/stop new proces using cgexec and check that it's in appropriate cgroup.
  3. Prepare cgrules.conf file - there should be some sample and man page available.
  4. Test cgrulesengd daemon (it should automatically move processes as written in cgrules.conf).
  5. Configure cgroup pam module and test that works if a user logs in (again, driven by cgrules.conf).

User Experience

Currently, the libcgroups package has several bugs, these will have to be fixed at first. When that is out of the way, configuration (or even monitoring) tools would reduce the barrier of entry to using control groups on Linux significantly.

Dependencies

  • Depends on kernel > 2.6.24 and libcgroups (current version is 0.32.2) which both are in Fedora since F-9.

Contingency Plan

Currently, nothing depends on libcgroup or the tools which would use it. If things go really wrong, we can always go back to the last working version of libcgroup.

Documentation

Release Notes

libcgroups is a tool which helps to manipulate, control and administrate control groups and the associated controllers. Using this tool it is possible to aggregate/partition set of tasks and their future children into hierarchical groups with specialized access to resources.

The tool consists of two parts -

  • The first one enables user to create persistent cgroups configuration using a configuration file and a service which creates configured groups on startup.
  • The second part enables user to define to which group belong the given process/given processes. This divison is based on uid or gid of processes. The user can start a service which will put the processes to the right subsystem, or there is a tool to move the process to the right subsystem or to create the process in it.

Comments and Discussion