@@ -28,7 +28,7 @@ CONTENTS:
28
28
4. Questions
29
29
30
30
1. Control Groups
31
- ==========
31
+ =================
32
32
33
33
1.1 What are cgroups ?
34
34
----------------------
@@ -143,10 +143,10 @@ proliferation of such cgroups.
143
143
144
144
Also lets say that the administrator would like to give enhanced network
145
145
access temporarily to a student's browser (since it is night and the user
146
- wants to do online gaming :) OR give one of the students simulation
146
+ wants to do online gaming :)) OR give one of the students simulation
147
147
apps enhanced CPU power,
148
148
149
- With ability to write pids directly to resource classes, its just a
149
+ With ability to write pids directly to resource classes, it's just a
150
150
matter of :
151
151
152
152
# echo pid > /mnt/network/<new_class>/tasks
@@ -227,10 +227,13 @@ Each cgroup is represented by a directory in the cgroup file system
227
227
containing the following files describing that cgroup:
228
228
229
229
- tasks: list of tasks (by pid) attached to that cgroup
230
- - notify_on_release flag: run /sbin/cgroup_release_agent on exit?
230
+ - releasable flag: cgroup currently removeable?
231
+ - notify_on_release flag: run the release agent on exit?
232
+ - release_agent: the path to use for release notifications (this file
233
+ exists in the top cgroup only)
231
234
232
235
Other subsystems such as cpusets may add additional files in each
233
- cgroup dir
236
+ cgroup dir.
234
237
235
238
New cgroups are created using the mkdir system call or shell
236
239
command. The properties of a cgroup, such as its flags, are
@@ -257,7 +260,7 @@ performance.
257
260
To allow access from a cgroup to the css_sets (and hence tasks)
258
261
that comprise it, a set of cg_cgroup_link objects form a lattice;
259
262
each cg_cgroup_link is linked into a list of cg_cgroup_links for
260
- a single cgroup on its cont_link_list field, and a list of
263
+ a single cgroup on its cgrp_link_list field, and a list of
261
264
cg_cgroup_links for a single css_set on its cg_link_list.
262
265
263
266
Thus the set of tasks in a cgroup can be listed by iterating over
@@ -271,9 +274,6 @@ for cgroups, with a minimum of additional kernel code.
271
274
1.4 What does notify_on_release do ?
272
275
------------------------------------
273
276
274
- *** notify_on_release is disabled in the current patch set. It will be
275
- *** reactivated in a future patch in a less-intrusive manner
276
-
277
277
If the notify_on_release flag is enabled (1) in a cgroup, then
278
278
whenever the last task in the cgroup leaves (exits or attaches to
279
279
some other cgroup) and the last child cgroup of that cgroup
@@ -360,8 +360,8 @@ Now you want to do something with this cgroup.
360
360
361
361
In this directory you can find several files:
362
362
# ls
363
- notify_on_release release_agent tasks
364
- (plus whatever files are added by the attached subsystems)
363
+ notify_on_release releasable tasks
364
+ (plus whatever files added by the attached subsystems)
365
365
366
366
Now attach your shell to this cgroup:
367
367
# /bin/echo $$ > tasks
@@ -404,19 +404,13 @@ with a subsystem id which will be assigned by the cgroup system.
404
404
Other fields in the cgroup_subsys object include:
405
405
406
406
- subsys_id: a unique array index for the subsystem, indicating which
407
- entry in cgroup->subsys[] this subsystem should be
408
- managing. Initialized by cgroup_register_subsys(); prior to this
409
- it should be initialized to -1
407
+ entry in cgroup->subsys[] this subsystem should be managing.
410
408
411
- - hierarchy: an index indicating which hierarchy, if any, this
412
- subsystem is currently attached to. If this is -1, then the
413
- subsystem is not attached to any hierarchy, and all tasks should be
414
- considered to be members of the subsystem's top_cgroup. It should
415
- be initialized to -1.
409
+ - name: should be initialized to a unique subsystem name. Should be
410
+ no longer than MAX_CGROUP_TYPE_NAMELEN.
416
411
417
- - name: should be initialized to a unique subsystem name prior to
418
- calling cgroup_register_subsystem. Should be no longer than
419
- MAX_CGROUP_TYPE_NAMELEN
412
+ - early_init: indicate if the subsystem needs early initialization
413
+ at system boot.
420
414
421
415
Each cgroup object created by the system has an array of pointers,
422
416
indexed by subsystem id; this pointer is entirely managed by the
@@ -434,8 +428,6 @@ situation.
434
428
See kernel/cgroup.c for more details.
435
429
436
430
Subsystems can take/release the cgroup_mutex via the functions
437
- cgroup_lock()/cgroup_unlock(), and can
438
- take/release the callback_mutex via the functions
439
431
cgroup_lock()/cgroup_unlock().
440
432
441
433
Accessing a task's cgroup pointer may be done in the following ways:
@@ -444,7 +436,7 @@ Accessing a task's cgroup pointer may be done in the following ways:
444
436
- inside an rcu_read_lock() section via rcu_dereference()
445
437
446
438
3.3 Subsystem API
447
- --------------------------
439
+ -----------------
448
440
449
441
Each subsystem should:
450
442
@@ -455,7 +447,8 @@ Each subsystem may export the following methods. The only mandatory
455
447
methods are create/destroy. Any others that are null are presumed to
456
448
be successful no-ops.
457
449
458
- struct cgroup_subsys_state *create(struct cgroup *cont)
450
+ struct cgroup_subsys_state *create(struct cgroup_subsys *ss,
451
+ struct cgroup *cgrp)
459
452
(cgroup_mutex held by caller)
460
453
461
454
Called to create a subsystem state object for a cgroup. The
@@ -470,7 +463,7 @@ identified by the passed cgroup object having a NULL parent (since
470
463
it's the root of the hierarchy) and may be an appropriate place for
471
464
initialization code.
472
465
473
- void destroy(struct cgroup *cont )
466
+ void destroy(struct cgroup_subsys *ss, struct cgroup *cgrp )
474
467
(cgroup_mutex held by caller)
475
468
476
469
The cgroup system is about to destroy the passed cgroup; the subsystem
@@ -481,7 +474,14 @@ cgroup->parent is still valid. (Note - can also be called for a
481
474
newly-created cgroup if an error occurs after this subsystem's
482
475
create() method has been called for the new cgroup).
483
476
484
- int can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
477
+ void pre_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp);
478
+ (cgroup_mutex held by caller)
479
+
480
+ Called before checking the reference count on each subsystem. This may
481
+ be useful for subsystems which have some extra references even if
482
+ there are not tasks in the cgroup.
483
+
484
+ int can_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
485
485
struct task_struct *task)
486
486
(cgroup_mutex held by caller)
487
487
@@ -492,8 +492,8 @@ unspecified task can be moved into the cgroup. Note that this isn't
492
492
called on a fork. If this method returns 0 (success) then this should
493
493
remain valid while the caller holds cgroup_mutex.
494
494
495
- void attach(struct cgroup_subsys *ss, struct cgroup *cont ,
496
- struct cgroup *old_cont , struct task_struct *task)
495
+ void attach(struct cgroup_subsys *ss, struct cgroup *cgrp ,
496
+ struct cgroup *old_cgrp , struct task_struct *task)
497
497
498
498
Called after the task has been attached to the cgroup, to allow any
499
499
post-attachment activity that requires memory allocations or blocking.
@@ -505,9 +505,9 @@ registration for all existing tasks.
505
505
506
506
void exit(struct cgroup_subsys *ss, struct task_struct *task)
507
507
508
- Called during task exit
508
+ Called during task exit.
509
509
510
- int populate(struct cgroup_subsys *ss, struct cgroup *cont )
510
+ int populate(struct cgroup_subsys *ss, struct cgroup *cgrp )
511
511
512
512
Called after creation of a cgroup to allow a subsystem to populate
513
513
the cgroup directory with file entries. The subsystem should make
@@ -516,7 +516,7 @@ include/linux/cgroup.h for details). Note that although this
516
516
method can return an error code, the error code is currently not
517
517
always handled well.
518
518
519
- void post_clone(struct cgroup_subsys *ss, struct cgroup *cont )
519
+ void post_clone(struct cgroup_subsys *ss, struct cgroup *cgrp )
520
520
521
521
Called at the end of cgroup_clone() to do any paramater
522
522
initialization which might be required before a task could attach. For
0 commit comments