Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 218526
b: refs/heads/master
c: 97978e6
h: refs/heads/master
v: v3
  • Loading branch information
Daniel Lezcano authored and Linus Torvalds committed Oct 28, 2010
1 parent ab6430a commit 7786349
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2d3cbf8bc852ac1bc3d098186143c5973f87b753
refs/heads/master: 97978e6d1f2da0073416870410459694fbdbfd9b
14 changes: 12 additions & 2 deletions trunk/Documentation/cgroups/cgroups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ CONTENTS:
1.2 Why are cgroups needed ?
1.3 How are cgroups implemented ?
1.4 What does notify_on_release do ?
1.5 How do I use cgroups ?
1.5 What does clone_children do ?
1.6 How do I use cgroups ?
2. Usage Examples and Syntax
2.1 Basic Usage
2.2 Attaching processes
Expand Down Expand Up @@ -293,7 +294,16 @@ notify_on_release in the root cgroup at system boot is disabled
value of their parents notify_on_release setting. The default value of
a cgroup hierarchy's release_agent path is empty.

1.5 How do I use cgroups ?
1.5 What does clone_children do ?
---------------------------------

If the clone_children flag is enabled (1) in a cgroup, then all
cgroups created beneath will call the post_clone callbacks for each
subsystem of the newly created cgroup. Usually when this callback is
implemented for a subsystem, it copies the values of the parent
subsystem, this is the case for the cpuset.

1.6 How do I use cgroups ?
--------------------------

To start a new job that is to be contained within a cgroup, using
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ enum {
* A thread in rmdir() is wating for this cgroup.
*/
CGRP_WAIT_ON_RMDIR,
/*
* Clone cgroup values when creating a new child cgroup
*/
CGRP_CLONE_CHILDREN,
};

/* which pidlist file are we talking about? */
Expand Down
39 changes: 39 additions & 0 deletions trunk/kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ static int notify_on_release(const struct cgroup *cgrp)
return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
}

static int clone_children(const struct cgroup *cgrp)
{
return test_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
}

/*
* for_each_subsys() allows you to iterate on each subsystem attached to
* an active hierarchy
Expand Down Expand Up @@ -1040,6 +1045,8 @@ static int cgroup_show_options(struct seq_file *seq, struct vfsmount *vfs)
seq_puts(seq, ",noprefix");
if (strlen(root->release_agent_path))
seq_printf(seq, ",release_agent=%s", root->release_agent_path);
if (clone_children(&root->top_cgroup))
seq_puts(seq, ",clone_children");
if (strlen(root->name))
seq_printf(seq, ",name=%s", root->name);
mutex_unlock(&cgroup_mutex);
Expand All @@ -1050,6 +1057,7 @@ struct cgroup_sb_opts {
unsigned long subsys_bits;
unsigned long flags;
char *release_agent;
bool clone_children;
char *name;
/* User explicitly requested empty subsystem */
bool none;
Expand Down Expand Up @@ -1097,6 +1105,8 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
opts->none = true;
} else if (!strcmp(token, "noprefix")) {
set_bit(ROOT_NOPREFIX, &opts->flags);
} else if (!strcmp(token, "clone_children")) {
opts->clone_children = true;
} else if (!strncmp(token, "release_agent=", 14)) {
/* Specifying two release agents is forbidden */
if (opts->release_agent)
Expand Down Expand Up @@ -1355,6 +1365,8 @@ static struct cgroupfs_root *cgroup_root_from_opts(struct cgroup_sb_opts *opts)
strcpy(root->release_agent_path, opts->release_agent);
if (opts->name)
strcpy(root->name, opts->name);
if (opts->clone_children)
set_bit(CGRP_CLONE_CHILDREN, &root->top_cgroup.flags);
return root;
}

Expand Down Expand Up @@ -3173,6 +3185,23 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft,
return ret;
}

static u64 cgroup_clone_children_read(struct cgroup *cgrp,
struct cftype *cft)
{
return clone_children(cgrp);
}

static int cgroup_clone_children_write(struct cgroup *cgrp,
struct cftype *cft,
u64 val)
{
if (val)
set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
else
clear_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
return 0;
}

/*
* for the common functions, 'private' gives the type of file
*/
Expand Down Expand Up @@ -3203,6 +3232,11 @@ static struct cftype files[] = {
.write_string = cgroup_write_event_control,
.mode = S_IWUGO,
},
{
.name = "cgroup.clone_children",
.read_u64 = cgroup_clone_children_read,
.write_u64 = cgroup_clone_children_write,
},
};

static struct cftype cft_release_agent = {
Expand Down Expand Up @@ -3332,6 +3366,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
if (notify_on_release(parent))
set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);

if (clone_children(parent))
set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);

for_each_subsys(root, ss) {
struct cgroup_subsys_state *css = ss->create(ss, cgrp);

Expand All @@ -3346,6 +3383,8 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
goto err_destroy;
}
/* At error, ->destroy() callback has to free assigned ID. */
if (clone_children(parent) && ss->post_clone)
ss->post_clone(ss, cgrp);
}

cgroup_lock_hierarchy(root);
Expand Down

0 comments on commit 7786349

Please sign in to comment.