~ubuntu-branches/ubuntu/maverick/libcgroup/maverick-proposed

« back to all changes in this revision

Viewing changes to README

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-08-26 11:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20090826112917-402ews2uj6v350d2
Tags: upstream-0.34
ImportĀ upstreamĀ versionĀ 0.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Please follow the following steps (TODO: Automate these steps)
 
2
 
 
3
0. Update package version in AC_INIT (configure.in)
 
4
1. Tag the current sources in trunk to the specified version
 
5
1. Run autoreconf -i to generate the configure file again
 
6
   (on changing any of the automake files)
 
7
2. Run configure with --prefix=<desired prefix> default is /usr/local
 
8
3. This step should generate
 
9
        a. Makefile
 
10
        b. libcgroup.spec
 
11
4. To build the RPM, carry out the following steps (obsolete, will be revised)
 
12
        a. Create a tag with the same version as specified in step 0
 
13
        a. Run mktarball
 
14
        b. copy tarball and spec file to correct place in the RPMBUILD
 
15
        c. Build an rpm of the spec file
 
16
 
 
17
 
 
18
Design
 
19
========
 
20
 
 
21
After cgroup system has taken shape, its time to have some basic tools
 
22
in user space which can enable a user to use the resource management
 
23
functionality effictively.
 
24
 
 
25
One of the needed functionality is rule based placement of a task.  In general,
 
26
there can be either uid or gid or exec based rules. Admin/root will
 
27
control/enforce uid/gid based rules and exec based rules can be defined by
 
28
user in a config file residing in user's home dir and fully controlled by user.
 
29
 
 
30
uid/gid based rules will be defined in /etc/cgrules.conf config file and
 
31
this file will be managed by root.
 
32
 
 
33
Basic idea is that to begin with provide facility to implement rules
 
34
based on uid and gid. So a hierarchy might look like as follows.
 
35
 
 
36
                        /mnt/cgroup
 
37
                        |       |
 
38
                      gid1      gid2
 
39
                     |   |
 
40
                   uid1 uid2
 
41
                  |   |
 
42
               proj1  proj2
 
43
 
 
44
 
 
45
Admin will write rules to control the resources among users. Then users
 
46
can manage their own cgroup at their own (proj1 and proj2) and control
 
47
the resources as they want.
 
48
 
 
49
Following are the few methods using which tasks can be placed in right
 
50
cgroups.
 
51
 
 
52
- Use pam_cgroup PAM plugin which will make sure users are placed in right
 
53
  cgroup at login time and any tasks launch after login, will continue to run
 
54
  in user's cgroup.
 
55
 
 
56
- Use command line tool "cgexec" to launch the task in right cgroup.
 
57
 
 
58
- Modify the program and use libcgroup provided APIs for placing a task
 
59
  in right cgroup before doing exec().
 
60
 
 
61
- Use "cgclassify" tool to classify a already running task.
 
62
 
 
63
- May be, a user space daemon can also be implemented which will listen to
 
64
  kernel events and place the task in right group based on the rules.
 
65
  This method involves few concerns.
 
66
 
 
67
        - Reliability of netlink socket. Messages can be dropped.
 
68
                - Change the netlink with a cgroup controller which exports the
 
69
                  events.
 
70
 
 
71
        - Delay incurred since the event took place and task was actually placed
 
72
          in right cgroup.
 
73
 
 
74
        - daemon will interfere with container's tasks which is not desired.
 
75
 
 
76
HOWTO
 
77
=====
 
78
 
 
79
Section 1:
 
80
----------
 
81
To use "cgexec" to place the task in right cgroup.
 
82
 
 
83
- make cgexec
 
84
- Run a task using cgexec. Following is the cgexec syntax.
 
85
 
 
86
 cgexec [-g <list of controllers>:<relative path to cgroup>] command [arguments]
 
87
 
 
88
 Note: Cgroup controllers and path are optional. If user does not know the
 
89
       right cgroup, cgexec will automatically place the task in right
 
90
       cgroup based on /etc/cgrules.conf
 
91
 
 
92
Example:
 
93
        cgexec -g *:test1 ls
 
94
        cgexec -g cpu,memory:test1 ls -l
 
95
        cgexec -g cpu,memory:test1 -g swap:test2 ls -l
 
96
 
 
97
Section 2
 
98
---------
 
99
To use "cgclassify" to place task in right cgroup.
 
100
 
 
101
- make cgclassify
 
102
- Pick a task's pid to be classified, and run
 
103
        cgclassify <list of pids>
 
104
 
 
105
Example:
 
106
--------
 
107
        cgclassify 2140 4325
 
108
 
 
109
        Note: After classification check out whether tasks 2140 and 4325
 
110
        are in the right cgroup or not (Based on rules in /etc/cgrules.conf)
 
111
 
 
112
Section 3:
 
113
----------
 
114
To use a pam plugin which will automatically place the task in right
 
115
cgroup upon login.
 
116
 
 
117
- Build pam_cgroup.so
 
118
        make pam_cgroup.so
 
119
- Copy pam_cgroup.so to /lib/security/
 
120
- Edit /etc/pam.d/su to make use of pam_cgroup.so session module upon
 
121
  execution of su.
 
122
 
 
123
example:
 
124
        Add following line at the end of /etc/pam.d/su file
 
125
 
 
126
session                optional        pam_cgroup.so
 
127
 
 
128
- Now launch a shell for a user "xyz" using su and the resulting shell
 
129
  should be running in the cgroup designated for the user as specified
 
130
  by cgrules.conf
 
131
 
 
132
  ex. "su test1"
 
133
 
 
134
Try similar things with other services like sshd.
 
135
 
 
136
Note: pam_cgroup.so moves the service providing process in the right cgroup
 
137
      and not the process which will be launched later. Due to parent child
 
138
      relationship, yet to be forked/execed process will launch in right
 
139
      group.
 
140
 
 
141
Ex. Lets say user root does "su test1". In this case process "su" is the
 
142
    one providing service (launching a shell) for user "test1". pam_cgroup.so
 
143
    will move process "su" to the user "test1"'s cgroup (Decided by the uid
 
144
    and gid of "test1"). Now once su forks/execs a shell for user test1,
 
145
    final shell is effectively running in the cgroup it should have been
 
146
    running based on /etc/cgrules.conf for user test1.
 
147
 
 
148
 
 
149
Section 4:
 
150
----------
 
151
To use cgrulesengd which will move a task to right cgroup based on
 
152
rules in /etc/cgrules.conf do following.
 
153
 
 
154
- build and install latest libcgroup.so
 
155
- build cgrulesengd
 
156
        make cgrulesengd
 
157
- specify some uid/gid based rules in /etc/cgrules.conf
 
158
- Mount some controllers and create an hierarchy of cgroups (matching
 
159
  your rules).
 
160
- Run cgrulesengd.
 
161
        - ./cgrulesengd
 
162
- Launch some task or login as a user to the sytem. Daemon should automatically
 
163
  place the task in right cgroup.
 
164
 
 
165
FAQ
 
166
===
 
167
Q. Why admin should not control "exec" based rules.
 
168
A. Unix file system provides access control only based on uid/gid. So
 
169
   even if admin starts putting tasks based on uid/gid, it can't enforce
 
170
   it. For example, consider following scenario.
 
171
 
 
172
  Lets say an admin creates following cgroup hierarchy.
 
173
 
 
174
                        /container
 
175
                        |       |
 
176
                database        browser
 
177
                |    |          |     |
 
178
              user1  user2     user1  user2
 
179
 
 
180
 Now admin wants to run all the database jobs under /container/database/
 
181
 and all the firefox jobs under /container/browser/. Based on which user
 
182
 launched it, jobs should go in either user1 or user2 dir.
 
183
 
 
184
 Now assume that database subdir has to more cpu resources as compared to
 
185
 browser subdir. Then a user, say user2, can always move his browser job
 
186
 also to /container/database/user2 dir to get more cpu resources and
 
187
 admin will not be able to control that.
 
188
 
 
189
 [Note: user2 will control what tasks can be added in /container/database/user2
 
190
  and will contol what further subdirs can be created under user2 dir. Root
 
191
  should not restrict the control to root only for practical purposes. Its
 
192
  something like that till /container/databse, admin controls the resources
 
193
  and below that how resources are further subdivided among various projects
 
194
  should be controlled by respective user].
 
195
 
 
196
In the light of above, it seems to make more sense that admin should enforce
 
197
rules only based on uid and gid. Probably later we can have a per user exec
 
198
based rules config file (~/.cgrules.conf), which can be parsed by cgrulesd
 
199
and then jobs launched by user will be placed in right cgroup based on
 
200
combination of rules in /etc/cgrules.conf and ~/cgrules.conf.