Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
cgroup.c File Reference
#include <linux/cgroup.h>
#include <linux/cred.h>
#include <linux/ctype.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/init_task.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/mm.h>
#include <linux/mutex.h>
#include <linux/mount.h>
#include <linux/pagemap.h>
#include <linux/proc_fs.h>
#include <linux/rcupdate.h>
#include <linux/sched.h>
#include <linux/backing-dev.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/magic.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/sort.h>
#include <linux/kmod.h>
#include <linux/module.h>
#include <linux/delayacct.h>
#include <linux/cgroupstats.h>
#include <linux/hash.h>
#include <linux/namei.h>
#include <linux/pid_namespace.h>
#include <linux/idr.h>
#include <linux/vmalloc.h>
#include <linux/eventfd.h>
#include <linux/poll.h>
#include <linux/flex_array.h>
#include <linux/kthread.h>
#include <linux/atomic.h>
#include <linux/cgroup_subsys.h>

Go to the source code of this file.

Data Structures

struct  cgroupfs_root
 
struct  cfent
 
struct  css_id
 
struct  cgroup_event
 
struct  cg_cgroup_link
 
struct  cgroup_sb_opts
 
struct  task_and_cgroup
 
struct  cgroup_taskset
 
struct  cgroup_seqfile_state
 
struct  cgroup_pidlist
 

Macros

#define CSS_DEACT_BIAS   INT_MIN
 
#define SUBSYS(_x)   [_x ## _subsys_id] = &_x ## _subsys,
 
#define IS_SUBSYS_ENABLED(option)   IS_BUILTIN(option)
 
#define MAX_CGROUP_ROOT_NAMELEN   64
 
#define CSS_ID_MAX   (65535)
 
#define dummytop   (&rootnode.top_cgroup)
 
#define for_each_subsys(_root, _ss)   list_for_each_entry(_ss, &_root->subsys_list, sibling)
 
#define for_each_active_root(_root)   list_for_each_entry(_root, &roots, root_list)
 
#define CSS_SET_HASH_BITS   7
 
#define CSS_SET_TABLE_SIZE   (1 << CSS_SET_HASH_BITS)
 
#define CGROUP_LOCAL_BUFFER_SIZE   64
 
#define PIDLIST_TOO_LARGE(c)   ((c) * sizeof(pid_t) > (PAGE_SIZE * 2))
 
#define PIDLIST_REALLOC_DIFFERENCE(old, new)   ((old) - PAGE_SIZE >= (new))
 
#define CGROUP_FILE_GENERIC_PREFIX   "cgroup."
 

Enumerations

enum  { ROOT_NOPREFIX, ROOT_XATTR }
 
enum  cgroup_filetype { CGROUP_FILE_PROCS, CGROUP_FILE_TASKS }
 

Functions

int cgroup_lock_is_held (void)
 
 EXPORT_SYMBOL_GPL (cgroup_lock_is_held)
 
int cgroup_is_removed (const struct cgroup *cgrp)
 
void cgroup_lock (void)
 
 EXPORT_SYMBOL_GPL (cgroup_lock)
 
void cgroup_unlock (void)
 
 EXPORT_SYMBOL_GPL (cgroup_unlock)
 
void cgroup_exclude_rmdir (struct cgroup_subsys_state *css)
 
void cgroup_release_and_wakeup_rmdir (struct cgroup_subsys_state *css)
 
int cgroup_path (const struct cgroup *cgrp, char *buf, int buflen)
 
 EXPORT_SYMBOL_GPL (cgroup_path)
 
struct task_structcgroup_taskset_first (struct cgroup_taskset *tset)
 
 EXPORT_SYMBOL_GPL (cgroup_taskset_first)
 
struct task_structcgroup_taskset_next (struct cgroup_taskset *tset)
 
 EXPORT_SYMBOL_GPL (cgroup_taskset_next)
 
struct cgroup * cgroup_taskset_cur_cgroup (struct cgroup_taskset *tset)
 
 EXPORT_SYMBOL_GPL (cgroup_taskset_cur_cgroup)
 
int cgroup_taskset_size (struct cgroup_taskset *tset)
 
 EXPORT_SYMBOL_GPL (cgroup_taskset_size)
 
int cgroup_attach_task (struct cgroup *cgrp, struct task_struct *tsk)
 
int cgroup_attach_task_all (struct task_struct *from, struct task_struct *tsk)
 
 EXPORT_SYMBOL_GPL (cgroup_attach_task_all)
 
bool cgroup_lock_live_group (struct cgroup *cgrp)
 
 EXPORT_SYMBOL_GPL (cgroup_lock_live_group)
 
int cgroup_add_cftypes (struct cgroup_subsys *ss, struct cftype *cfts)
 
 EXPORT_SYMBOL_GPL (cgroup_add_cftypes)
 
int cgroup_rm_cftypes (struct cgroup_subsys *ss, struct cftype *cfts)
 
int cgroup_task_count (const struct cgroup *cgrp)
 
void cgroup_iter_start (struct cgroup *cgrp, struct cgroup_iter *it) __acquires(css_set_lock)
 
struct task_structcgroup_iter_next (struct cgroup *cgrp, struct cgroup_iter *it)
 
void cgroup_iter_end (struct cgroup *cgrp, struct cgroup_iter *it) __releases(css_set_lock)
 
int cgroup_scan_tasks (struct cgroup_scanner *scan)
 
int cgroupstats_build (struct cgroupstats *stats, struct dentry *dentry)
 
int __init_or_module cgroup_load_subsys (struct cgroup_subsys *ss)
 
 EXPORT_SYMBOL_GPL (cgroup_load_subsys)
 
void cgroup_unload_subsys (struct cgroup_subsys *ss)
 
 EXPORT_SYMBOL_GPL (cgroup_unload_subsys)
 
int __init cgroup_init_early (void)
 
int __init cgroup_init (void)
 
void cgroup_fork (struct task_struct *child)
 
void cgroup_fork_callbacks (struct task_struct *child)
 
void cgroup_post_fork (struct task_struct *child)
 
void cgroup_exit (struct task_struct *tsk, int run_callbacks)
 
int cgroup_is_descendant (const struct cgroup *cgrp, struct task_struct *task)
 
bool __css_tryget (struct cgroup_subsys_state *css)
 
 EXPORT_SYMBOL_GPL (__css_tryget)
 
void __css_put (struct cgroup_subsys_state *css)
 
 EXPORT_SYMBOL_GPL (__css_put)
 
 __setup ("cgroup_disable=", cgroup_disable)
 
unsigned short css_id (struct cgroup_subsys_state *css)
 
 EXPORT_SYMBOL_GPL (css_id)
 
unsigned short css_depth (struct cgroup_subsys_state *css)
 
 EXPORT_SYMBOL_GPL (css_depth)
 
bool css_is_ancestor (struct cgroup_subsys_state *child, const struct cgroup_subsys_state *root)
 
void free_css_id (struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
 
 EXPORT_SYMBOL_GPL (free_css_id)
 
struct cgroup_subsys_state * css_lookup (struct cgroup_subsys *ss, int id)
 
 EXPORT_SYMBOL_GPL (css_lookup)
 
struct cgroup_subsys_state * css_get_next (struct cgroup_subsys *ss, int id, struct cgroup_subsys_state *root, int *foundid)
 
struct cgroup_subsys_state * cgroup_css_from_dir (struct file *f, int id)
 

Variables

struct file_operations proc_cgroup_operations
 

Macro Definition Documentation

#define CGROUP_FILE_GENERIC_PREFIX   "cgroup."

Definition at line 3915 of file cgroup.c.

#define CGROUP_LOCAL_BUFFER_SIZE   64

Definition at line 2363 of file cgroup.c.

#define CSS_DEACT_BIAS   INT_MIN

Definition at line 68 of file cgroup.c.

#define CSS_ID_MAX   (65535)

Definition at line 168 of file cgroup.c.

#define CSS_SET_HASH_BITS   7

Definition at line 376 of file cgroup.c.

#define CSS_SET_TABLE_SIZE   (1 << CSS_SET_HASH_BITS)

Definition at line 377 of file cgroup.c.

#define dummytop   (&rootnode.top_cgroup)

Definition at line 236 of file cgroup.c.

#define for_each_active_root (   _root)    list_for_each_entry(_root, &roots, root_list)

Definition at line 310 of file cgroup.c.

#define for_each_subsys (   _root,
  _ss 
)    list_for_each_entry(_ss, &_root->subsys_list, sibling)

Definition at line 306 of file cgroup.c.

#define IS_SUBSYS_ENABLED (   option)    IS_BUILTIN(option)

Definition at line 96 of file cgroup.c.

#define MAX_CGROUP_ROOT_NAMELEN   64

Definition at line 101 of file cgroup.c.

#define PIDLIST_REALLOC_DIFFERENCE (   old,
  new 
)    ((old) - PAGE_SIZE >= (new))

Definition at line 3338 of file cgroup.c.

#define PIDLIST_TOO_LARGE (   c)    ((c) * sizeof(pid_t) > (PAGE_SIZE * 2))

Definition at line 3300 of file cgroup.c.

#define SUBSYS (   _x)    [_x ## _subsys_id] = &_x ## _subsys,

Definition at line 95 of file cgroup.c.

Enumeration Type Documentation

anonymous enum
Enumerator:
ROOT_NOPREFIX 
ROOT_XATTR 

Definition at line 279 of file cgroup.c.

Enumerator:
CGROUP_FILE_PROCS 
CGROUP_FILE_TASKS 

Definition at line 3264 of file cgroup.c.

Function Documentation

void __css_put ( struct cgroup_subsys_state *  css)

Definition at line 5038 of file cgroup.c.

bool __css_tryget ( struct cgroup_subsys_state *  css)

Definition at line 5023 of file cgroup.c.

__setup ( )
int cgroup_add_cftypes ( struct cgroup_subsys *  ss,
struct cftype *  cfts 
)

cgroup_add_cftypes - add an array of cftypes to a subsystem : target cgroup subsystem : zero-length name terminated array of cftypes

Register to . Files described by are created for all existing cgroups to which is attached and all future cgroups will have them too. This function can be called anytime whether is attached or not.

Returns 0 on successful registration, -errno on failure. Note that this function currently returns 0 as long as registration is successful even if some file creation attempts on existing cgroups fail.

Definition at line 2921 of file cgroup.c.

int cgroup_attach_task ( struct cgroup *  cgrp,
struct task_struct tsk 
)

cgroup_attach_task - attach task 'tsk' to cgroup 'cgrp' : the cgroup the task is attaching to : the task to be attached

Call with cgroup_mutex and threadgroup locked. May take task_lock of during call.

Definition at line 1977 of file cgroup.c.

int cgroup_attach_task_all ( struct task_struct from,
struct task_struct tsk 
)

cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from' : attach to all cgroups of a given task : the task to be attached

Definition at line 2057 of file cgroup.c.

struct cgroup_subsys_state* cgroup_css_from_dir ( struct file f,
int  id 
)
read

Definition at line 5421 of file cgroup.c.

void cgroup_exclude_rmdir ( struct cgroup_subsys_state *  css)

Definition at line 1033 of file cgroup.c.

void cgroup_exit ( struct task_struct tsk,
int  run_callbacks 
)

cgroup_exit - detach cgroup from exiting task : pointer to task_struct of exiting process : run exit callbacks?

Description: Detach cgroup from and release it.

Note that cgroups marked notify_on_release force every task in them to take the global cgroup_mutex mutex when exiting. This could impact scaling on very large systems. Be reluctant to use notify_on_release cgroups where very high task exit scaling is required on large systems.

the_top_cgroup_hack:

Set the exiting tasks cgroup to the root cgroup (top_cgroup).

We call cgroup_exit() while the task is still competent to handle notify_on_release(), then leave the task attached to the root cgroup in each hierarchy for the remainder of its exit.

To do this properly, we would increment the reference count on top_cgroup, and near the very end of the kernel/exit.c do_exit() code we would add a second cgroup function call, to drop that reference. This would just create an unnecessary hot spot on the top_cgroup reference count, to no avail.

Normally, holding a reference to a cgroup without bumping its count is unsafe. The cgroup could go away, or someone could attach us to a different cgroup, decrementing the count on the first cgroup that we never incremented. But in this case, top_cgroup isn't going away, and either task has PF_EXITING set, which wards off any cgroup_attach_task() attempts, or task is a failed fork, never visible to cgroup_attach_task.

Definition at line 4928 of file cgroup.c.

void cgroup_fork ( struct task_struct child)

cgroup_fork - attach newly forked task to its parents cgroup. : pointer to task_struct of forking parent process.

Description: A task inherits its parent's cgroup at fork().

A pointer to the shared css_set was automatically copied in fork.c by dup_task_struct(). However, we ignore that copy, since it was not made under the protection of RCU or cgroup_mutex, so might no longer be a valid cgroup pointer. cgroup_attach_task() might have already changed current->cgroups, allowing the previously referenced cgroup group to be removed and freed.

At the point that cgroup_fork() is called, 'current' is the parent task, and the passed argument 'child' points to the child task.

Definition at line 4825 of file cgroup.c.

void cgroup_fork_callbacks ( struct task_struct child)

cgroup_fork_callbacks - run fork callbacks : the new task

Called on a new task very soon before adding it to the tasklist. No need to take any locks since no-one can be operating on this task.

Definition at line 4842 of file cgroup.c.

int __init cgroup_init ( void  )

cgroup_init - cgroup initialization

Register cgroup filesystem and /proc file, and initialize any subsystems that didn't request early init.

Definition at line 4647 of file cgroup.c.

int __init cgroup_init_early ( void  )

cgroup_init_early - cgroup initialization at system boot

Initialize cgroups at system boot, and initialize any subsystems that request early init.

Definition at line 4596 of file cgroup.c.

int cgroup_is_descendant ( const struct cgroup *  cgrp,
struct task_struct task 
)

cgroup_is_descendant - see if is a descendant of 's cgrp : the cgroup in question : the task in question

See if is a descendant of 's cgroup in the appropriate hierarchy.

If we are sending in dummytop, then presumably we are creating the top cgroup in the subsystem.

Called only by the ns (nsproxy) cgroup.

Definition at line 4985 of file cgroup.c.

int cgroup_is_removed ( const struct cgroup *  cgrp)
inline

Definition at line 273 of file cgroup.c.

void cgroup_iter_end ( struct cgroup *  cgrp,
struct cgroup_iter *  it 
)

Definition at line 3087 of file cgroup.c.

struct task_struct* cgroup_iter_next ( struct cgroup *  cgrp,
struct cgroup_iter *  it 
)
read

Definition at line 3063 of file cgroup.c.

void cgroup_iter_start ( struct cgroup *  cgrp,
struct cgroup_iter *  it 
)

Definition at line 3047 of file cgroup.c.

int __init_or_module cgroup_load_subsys ( struct cgroup_subsys *  ss)

cgroup_load_subsys: load and register a modular subsystem at runtime : the subsystem to load

This function should be called in a modular subsystem's initcall. If the subsystem is built as a module, it will be assigned a new subsys_id and set up for use. If the subsystem is built-in anyway, work is delegated to the simpler cgroup_init_subsys.

Definition at line 4431 of file cgroup.c.

void cgroup_lock ( void  )

cgroup_lock - lock out any changes to cgroup structures

Definition at line 802 of file cgroup.c.

int cgroup_lock_is_held ( void  )

Definition at line 251 of file cgroup.c.

bool cgroup_lock_live_group ( struct cgroup *  cgrp)

cgroup_lock_live_group - take cgroup_mutex and check that cgrp is alive. : the cgroup to be checked for liveness

On success, returns true; the lock should be later released with cgroup_unlock(). On failure returns false with no lock held.

Definition at line 2325 of file cgroup.c.

int cgroup_path ( const struct cgroup *  cgrp,
char buf,
int  buflen 
)

cgroup_path - generate the path of a cgroup : the cgroup in question : the buffer to write the path into : the length of the buffer

Called with cgroup_mutex held or else with an RCU-protected cgroup reference. Writes path of cgroup into buf. Returns 0 on success, -errno on error.

Definition at line 1809 of file cgroup.c.

void cgroup_post_fork ( struct task_struct child)

cgroup_post_fork - called on a new task after adding it to the task list : the task in question

Adds the task to the list running through its css_set if necessary. Has to be after the task is visible on the task list in case we race with the first call to cgroup_iter_start() - to guarantee that the new task ends up on its list.

Definition at line 4871 of file cgroup.c.

void cgroup_release_and_wakeup_rmdir ( struct cgroup_subsys_state *  css)

Definition at line 1038 of file cgroup.c.

int cgroup_rm_cftypes ( struct cgroup_subsys *  ss,
struct cftype *  cfts 
)

cgroup_rm_cftypes - remove an array of cftypes from a subsystem : target cgroup subsystem : zero-length name terminated array of cftypes

Unregister from . Files described by are removed from all existing cgroups to which is attached and all future cgroups won't have them either. This function can be called anytime whether is attached or not.

Returns 0 on successful unregistration, -ENOENT if is not registered with .

Definition at line 2951 of file cgroup.c.

int cgroup_scan_tasks ( struct cgroup_scanner *  scan)

cgroup_scan_tasks - iterate though all the tasks in a cgroup : struct cgroup_scanner containing arguments for the scan

Arguments include pointers to callback functions test_task() and process_task(). Iterate through all the tasks in a cgroup, calling test_task() for each, and if it returns true, call process_task() for it also. The test_task pointer may be NULL, meaning always true (select all tasks). Effectively duplicates cgroup_iter_{start,next,end}() but does not lock css_set_lock for the call to process_task(). The struct cgroup_scanner may be embedded in any structure of the caller's creation. It is guaranteed that process_task() will act on every task that is a member of the cgroup for the duration of this call. This function may or may not call process_task() for tasks that exit or move to a different cgroup during the call, or are forked or move into the cgroup during the call.

Note that test_task() may be called with locks held, and may in some situations be called multiple times for the same task, so it should be cheap. If the heap pointer in the struct cgroup_scanner is non-NULL, a heap has been pre-allocated and will be used for heap operations (and its "gt" member will be overwritten), else a temporary heap will be used (allocation of which may cause this function to fail).

Definition at line 3154 of file cgroup.c.

int cgroup_task_count ( const struct cgroup *  cgrp)

cgroup_task_count - count the number of tasks in a cgroup. : the cgroup in question

Return the number of tasks in the cgroup.

Definition at line 2975 of file cgroup.c.

struct cgroup* cgroup_taskset_cur_cgroup ( struct cgroup_taskset tset)
read

cgroup_taskset_cur_cgroup - return the matching cgroup for the current task : taskset of interest

Return the cgroup for the current (last returned) task of . This function must be preceded by either cgroup_taskset_first() or cgroup_taskset_next().

Definition at line 1913 of file cgroup.c.

struct task_struct* cgroup_taskset_first ( struct cgroup_taskset tset)
read

cgroup_taskset_first - reset taskset and return the first task : taskset of interest

iteration is initialized and the first task is returned.

Definition at line 1873 of file cgroup.c.

struct task_struct* cgroup_taskset_next ( struct cgroup_taskset tset)
read

cgroup_taskset_next - iterate to the next task in taskset : taskset of interest

Return the next task in . Iteration must have been initialized with cgroup_taskset_first().

Definition at line 1892 of file cgroup.c.

int cgroup_taskset_size ( struct cgroup_taskset tset)

cgroup_taskset_size - return the number of tasks in taskset : taskset of interest

Definition at line 1923 of file cgroup.c.

void cgroup_unload_subsys ( struct cgroup_subsys *  ss)

cgroup_unload_subsys: unload a modular subsystem : the subsystem to unload

This function should be called in a modular subsystem's exitcall. When this function is invoked, the refcount on the subsystem's module will be 0, so the subsystem will not be attached to any hierarchy.

Definition at line 4540 of file cgroup.c.

void cgroup_unlock ( void  )

cgroup_unlock - release lock on cgroup changes

Undo the lock taken in a previous cgroup_lock() call.

Definition at line 813 of file cgroup.c.

int cgroupstats_build ( struct cgroupstats stats,
struct dentry dentry 
)

cgroupstats_build - build and fill cgroupstats : cgroupstats to fill information into : A dentry entry belonging to the cgroup for which stats have been requested.

Build and fill cgroupstats so that taskstats can export it to user space.

Definition at line 3494 of file cgroup.c.

unsigned short css_depth ( struct cgroup_subsys_state *  css)

Definition at line 5190 of file cgroup.c.

struct cgroup_subsys_state* css_get_next ( struct cgroup_subsys *  ss,
int  id,
struct cgroup_subsys_state *  root,
int foundid 
)
read

css_get_next - lookup next cgroup under specified hierarchy. : pointer to subsystem : current position of iteration. : pointer to css. search tree under this. : position of found object.

Search next css under the specified hierarchy of rootid. Calling under rcu_read_lock() is necessary. Returns NULL if it reaches the end.

Definition at line 5380 of file cgroup.c.

unsigned short css_id ( struct cgroup_subsys_state *  css)

Definition at line 5173 of file cgroup.c.

bool css_is_ancestor ( struct cgroup_subsys_state *  child,
const struct cgroup_subsys_state *  root 
)

css_is_ancestor - test "root" css is an ancestor of "child" : the css to be tested. : the css supporsed to be an ancestor of the child.

Returns true if "root" is an ancestor of "child" in its hierarchy. Because this function reads css->id, the caller must hold rcu_read_lock(). But, considering usual usage, the csses should be valid objects after test. Assuming that the caller will do some action to the child if this returns returns true, the caller must take "child";s reference count. If "child" is valid object and this returns true, "root" is valid, too.

Definition at line 5215 of file cgroup.c.

struct cgroup_subsys_state* css_lookup ( struct cgroup_subsys *  ss,
int  id 
)
read

css_lookup - lookup css by id : cgroup subsys to be looked into. : the id

Returns pointer to cgroup_subsys_state if there is valid one with id. NULL if not. Should be called under rcu_read_lock()

Definition at line 5355 of file cgroup.c.

EXPORT_SYMBOL_GPL ( cgroup_lock_is_held  )
EXPORT_SYMBOL_GPL ( cgroup_lock  )
EXPORT_SYMBOL_GPL ( cgroup_unlock  )
EXPORT_SYMBOL_GPL ( cgroup_path  )
EXPORT_SYMBOL_GPL ( cgroup_taskset_first  )
EXPORT_SYMBOL_GPL ( cgroup_taskset_next  )
EXPORT_SYMBOL_GPL ( cgroup_taskset_cur_cgroup  )
EXPORT_SYMBOL_GPL ( cgroup_taskset_size  )
EXPORT_SYMBOL_GPL ( cgroup_attach_task_all  )
EXPORT_SYMBOL_GPL ( cgroup_lock_live_group  )
EXPORT_SYMBOL_GPL ( cgroup_add_cftypes  )
EXPORT_SYMBOL_GPL ( cgroup_load_subsys  )
EXPORT_SYMBOL_GPL ( cgroup_unload_subsys  )
EXPORT_SYMBOL_GPL ( __css_tryget  )
EXPORT_SYMBOL_GPL ( __css_put  )
EXPORT_SYMBOL_GPL ( css_id  )
EXPORT_SYMBOL_GPL ( css_depth  )
EXPORT_SYMBOL_GPL ( free_css_id  )
EXPORT_SYMBOL_GPL ( css_lookup  )
void free_css_id ( struct cgroup_subsys *  ss,
struct cgroup_subsys_state *  css 
)

Definition at line 5234 of file cgroup.c.

Variable Documentation

struct file_operations proc_cgroup_operations
Initial value:
= {
.open = cgroup_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
}

Definition at line 4766 of file cgroup.c.