Skip to content

Commit 2ff2a7d

Browse files
lizf-oshtejun
authored andcommitted
cgroup: kill css_id
The only user of css_id was memcg, and it has been convered to use cgroup->id, so kill css_id. Signed-off-by: Li Zefan <lizefan@huwei.com> Reviewed-by: Michal Hocko <mhocko@suse.cz> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent b862783 commit 2ff2a7d

2 files changed

Lines changed: 1 addition & 284 deletions

File tree

‎include/linux/cgroup.h‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,6 @@ struct cgroup_subsys {
612612
int subsys_id;
613613
int disabled;
614614
int early_init;
615-
/*
616-
* True if this subsys uses ID. ID is not available before cgroup_init()
617-
* (not available in early_init time.)
618-
*/
619-
bool use_id;
620615

621616
/*
622617
* If %false, this subsystem is properly hierarchical -
@@ -642,9 +637,6 @@ struct cgroup_subsys {
642637
*/
643638
struct cgroupfs_root *root;
644639
struct list_head sibling;
645-
/* used when use_id == true */
646-
struct idr idr;
647-
spinlock_t id_lock;
648640

649641
/* list of cftype_sets */
650642
struct list_head cftsets;
@@ -875,35 +867,6 @@ int css_scan_tasks(struct cgroup_subsys_state *css,
875867
int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
876868
int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
877869

878-
/*
879-
* CSS ID is ID for cgroup_subsys_state structs under subsys. This only works
880-
* if cgroup_subsys.use_id == true. It can be used for looking up and scanning.
881-
* CSS ID is assigned at cgroup allocation (create) automatically
882-
* and removed when subsys calls free_css_id() function. This is because
883-
* the lifetime of cgroup_subsys_state is subsys's matter.
884-
*
885-
* Looking up and scanning function should be called under rcu_read_lock().
886-
* Taking cgroup_mutex is not necessary for following calls.
887-
* But the css returned by this routine can be "not populated yet" or "being
888-
* destroyed". The caller should check css and cgroup's status.
889-
*/
890-
891-
/*
892-
* Typically Called at ->destroy(), or somewhere the subsys frees
893-
* cgroup_subsys_state.
894-
*/
895-
void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css);
896-
897-
/* Find a cgroup_subsys_state which has given ID */
898-
899-
struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id);
900-
901-
/* Returns true if root is ancestor of cg */
902-
bool css_is_ancestor(struct cgroup_subsys_state *cg,
903-
const struct cgroup_subsys_state *root);
904-
905-
/* Get id and depth of css */
906-
unsigned short css_id(struct cgroup_subsys_state *css);
907870
struct cgroup_subsys_state *css_from_dir(struct dentry *dentry,
908871
struct cgroup_subsys *ss);
909872

‎kernel/cgroup.c‎

Lines changed: 1 addition & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -124,38 +124,6 @@ struct cfent {
124124
struct simple_xattrs xattrs;
125125
};
126126

127-
/*
128-
* CSS ID -- ID per subsys's Cgroup Subsys State(CSS). used only when
129-
* cgroup_subsys->use_id != 0.
130-
*/
131-
#define CSS_ID_MAX (65535)
132-
struct css_id {
133-
/*
134-
* The css to which this ID points. This pointer is set to valid value
135-
* after cgroup is populated. If cgroup is removed, this will be NULL.
136-
* This pointer is expected to be RCU-safe because destroy()
137-
* is called after synchronize_rcu(). But for safe use, css_tryget()
138-
* should be used for avoiding race.
139-
*/
140-
struct cgroup_subsys_state __rcu *css;
141-
/*
142-
* ID of this css.
143-
*/
144-
unsigned short id;
145-
/*
146-
* Depth in hierarchy which this ID belongs to.
147-
*/
148-
unsigned short depth;
149-
/*
150-
* ID is freed by RCU. (and lookup routine is RCU safe.)
151-
*/
152-
struct rcu_head rcu_head;
153-
/*
154-
* Hierarchy of CSS ID belongs to.
155-
*/
156-
unsigned short stack[0]; /* Array of Length (depth+1) */
157-
};
158-
159127
/*
160128
* cgroup_event represents events which userspace want to receive.
161129
*/
@@ -387,9 +355,6 @@ struct cgrp_cset_link {
387355
static struct css_set init_css_set;
388356
static struct cgrp_cset_link init_cgrp_cset_link;
389357

390-
static int cgroup_init_idr(struct cgroup_subsys *ss,
391-
struct cgroup_subsys_state *css);
392-
393358
/*
394359
* css_set_lock protects the list of css_set objects, and the chain of
395360
* tasks off each css_set. Nests outside task->alloc_lock due to
@@ -841,8 +806,6 @@ static struct backing_dev_info cgroup_backing_dev_info = {
841806
.capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
842807
};
843808

844-
static int alloc_css_id(struct cgroup_subsys_state *child_css);
845-
846809
static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb)
847810
{
848811
struct inode *inode = new_inode(sb);
@@ -4242,21 +4205,6 @@ static int cgroup_populate_dir(struct cgroup *cgrp, unsigned long subsys_mask)
42424205
goto err;
42434206
}
42444207
}
4245-
4246-
/* This cgroup is ready now */
4247-
for_each_root_subsys(cgrp->root, ss) {
4248-
struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
4249-
struct css_id *id = rcu_dereference_protected(css->id, true);
4250-
4251-
/*
4252-
* Update id->css pointer and make this css visible from
4253-
* CSS ID functions. This pointer will be dereferened
4254-
* from RCU-read-side without locks.
4255-
*/
4256-
if (id)
4257-
rcu_assign_pointer(id->css, css);
4258-
}
4259-
42604208
return 0;
42614209
err:
42624210
cgroup_clear_dir(cgrp, subsys_mask);
@@ -4325,7 +4273,6 @@ static void init_css(struct cgroup_subsys_state *css, struct cgroup_subsys *ss,
43254273
css->cgroup = cgrp;
43264274
css->ss = ss;
43274275
css->flags = 0;
4328-
css->id = NULL;
43294276

43304277
if (cgrp->parent)
43314278
css->parent = cgroup_css(cgrp->parent, ss);
@@ -4457,12 +4404,6 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
44574404
goto err_free_all;
44584405

44594406
init_css(css, ss, cgrp);
4460-
4461-
if (ss->use_id) {
4462-
err = alloc_css_id(css);
4463-
if (err)
4464-
goto err_free_all;
4465-
}
44664407
}
44674408

44684409
/*
@@ -4927,12 +4868,6 @@ int __init_or_module cgroup_load_subsys(struct cgroup_subsys *ss)
49274868

49284869
/* our new subsystem will be attached to the dummy hierarchy. */
49294870
init_css(css, ss, cgroup_dummy_top);
4930-
/* init_idr must be after init_css() because it sets css->id. */
4931-
if (ss->use_id) {
4932-
ret = cgroup_init_idr(ss, css);
4933-
if (ret)
4934-
goto err_unload;
4935-
}
49364871

49374872
/*
49384873
* Now we need to entangle the css into the existing css_sets. unlike
@@ -4998,9 +4933,6 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
49984933

49994934
offline_css(cgroup_css(cgroup_dummy_top, ss));
50004935

5001-
if (ss->use_id)
5002-
idr_destroy(&ss->idr);
5003-
50044936
/* deassign the subsys_id */
50054937
cgroup_subsys[ss->subsys_id] = NULL;
50064938

@@ -5027,8 +4959,7 @@ void cgroup_unload_subsys(struct cgroup_subsys *ss)
50274959
/*
50284960
* remove subsystem's css from the cgroup_dummy_top and free it -
50294961
* need to free before marking as null because ss->css_free needs
5030-
* the cgrp->subsys pointer to find their state. note that this
5031-
* also takes care of freeing the css_id.
4962+
* the cgrp->subsys pointer to find their state.
50324963
*/
50334964
ss->css_free(cgroup_css(cgroup_dummy_top, ss));
50344965
RCU_INIT_POINTER(cgroup_dummy_top->subsys[ss->subsys_id], NULL);
@@ -5099,8 +5030,6 @@ int __init cgroup_init(void)
50995030
for_each_builtin_subsys(ss, i) {
51005031
if (!ss->early_init)
51015032
cgroup_init_subsys(ss);
5102-
if (ss->use_id)
5103-
cgroup_init_idr(ss, init_css_set.subsys[ss->subsys_id]);
51045033
}
51055034

51065035
/* allocate id for the dummy hierarchy */
@@ -5520,181 +5449,6 @@ static int __init cgroup_disable(char *str)
55205449
}
55215450
__setup("cgroup_disable=", cgroup_disable);
55225451

5523-
/*
5524-
* Functons for CSS ID.
5525-
*/
5526-
5527-
/* to get ID other than 0, this should be called when !cgroup_is_dead() */
5528-
unsigned short css_id(struct cgroup_subsys_state *css)
5529-
{
5530-
struct css_id *cssid;
5531-
5532-
/*
5533-
* This css_id() can return correct value when somone has refcnt
5534-
* on this or this is under rcu_read_lock(). Once css->id is allocated,
5535-
* it's unchanged until freed.
5536-
*/
5537-
cssid = rcu_dereference_raw(css->id);
5538-
5539-
if (cssid)
5540-
return cssid->id;
5541-
return 0;
5542-
}
5543-
EXPORT_SYMBOL_GPL(css_id);
5544-
5545-
/**
5546-
* css_is_ancestor - test "root" css is an ancestor of "child"
5547-
* @child: the css to be tested.
5548-
* @root: the css supporsed to be an ancestor of the child.
5549-
*
5550-
* Returns true if "root" is an ancestor of "child" in its hierarchy. Because
5551-
* this function reads css->id, the caller must hold rcu_read_lock().
5552-
* But, considering usual usage, the csses should be valid objects after test.
5553-
* Assuming that the caller will do some action to the child if this returns
5554-
* returns true, the caller must take "child";s reference count.
5555-
* If "child" is valid object and this returns true, "root" is valid, too.
5556-
*/
5557-
5558-
bool css_is_ancestor(struct cgroup_subsys_state *child,
5559-
const struct cgroup_subsys_state *root)
5560-
{
5561-
struct css_id *child_id;
5562-
struct css_id *root_id;
5563-
5564-
child_id = rcu_dereference(child->id);
5565-
if (!child_id)
5566-
return false;
5567-
root_id = rcu_dereference(root->id);
5568-
if (!root_id)
5569-
return false;
5570-
if (child_id->depth < root_id->depth)
5571-
return false;
5572-
if (child_id->stack[root_id->depth] != root_id->id)
5573-
return false;
5574-
return true;
5575-
}
5576-
5577-
void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css)
5578-
{
5579-
struct css_id *id = rcu_dereference_protected(css->id, true);
5580-
5581-
/* When this is called before css_id initialization, id can be NULL */
5582-
if (!id)
5583-
return;
5584-
5585-
BUG_ON(!ss->use_id);
5586-
5587-
rcu_assign_pointer(id->css, NULL);
5588-
rcu_assign_pointer(css->id, NULL);
5589-
spin_lock(&ss->id_lock);
5590-
idr_remove(&ss->idr, id->id);
5591-
spin_unlock(&ss->id_lock);
5592-
kfree_rcu(id, rcu_head);
5593-
}
5594-
EXPORT_SYMBOL_GPL(free_css_id);
5595-
5596-
/*
5597-
* This is called by init or create(). Then, calls to this function are
5598-
* always serialized (By cgroup_mutex() at create()).
5599-
*/
5600-
5601-
static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth)
5602-
{
5603-
struct css_id *newid;
5604-
int ret, size;
5605-
5606-
BUG_ON(!ss->use_id);
5607-
5608-
size = sizeof(*newid) + sizeof(unsigned short) * (depth + 1);
5609-
newid = kzalloc(size, GFP_KERNEL);
5610-
if (!newid)
5611-
return ERR_PTR(-ENOMEM);
5612-
5613-
idr_preload(GFP_KERNEL);
5614-
spin_lock(&ss->id_lock);
5615-
/* Don't use 0. allocates an ID of 1-65535 */
5616-
ret = idr_alloc(&ss->idr, newid, 1, CSS_ID_MAX + 1, GFP_NOWAIT);
5617-
spin_unlock(&ss->id_lock);
5618-
idr_preload_end();
5619-
5620-
/* Returns error when there are no free spaces for new ID.*/
5621-
if (ret < 0)
5622-
goto err_out;
5623-
5624-
newid->id = ret;
5625-
newid->depth = depth;
5626-
return newid;
5627-
err_out:
5628-
kfree(newid);
5629-
return ERR_PTR(ret);
5630-
5631-
}
5632-
5633-
static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss,
5634-
struct cgroup_subsys_state *rootcss)
5635-
{
5636-
struct css_id *newid;
5637-
5638-
spin_lock_init(&ss->id_lock);
5639-
idr_init(&ss->idr);
5640-
5641-
newid = get_new_cssid(ss, 0);
5642-
if (IS_ERR(newid))
5643-
return PTR_ERR(newid);
5644-
5645-
newid->stack[0] = newid->id;
5646-
RCU_INIT_POINTER(newid->css, rootcss);
5647-
RCU_INIT_POINTER(rootcss->id, newid);
5648-
return 0;
5649-
}
5650-
5651-
static int alloc_css_id(struct cgroup_subsys_state *child_css)
5652-
{
5653-
struct cgroup_subsys_state *parent_css = css_parent(child_css);
5654-
struct css_id *child_id, *parent_id;
5655-
int i, depth;
5656-
5657-
parent_id = rcu_dereference_protected(parent_css->id, true);
5658-
depth = parent_id->depth + 1;
5659-
5660-
child_id = get_new_cssid(child_css->ss, depth);
5661-
if (IS_ERR(child_id))
5662-
return PTR_ERR(child_id);
5663-
5664-
for (i = 0; i < depth; i++)
5665-
child_id->stack[i] = parent_id->stack[i];
5666-
child_id->stack[depth] = child_id->id;
5667-
/*
5668-
* child_id->css pointer will be set after this cgroup is available
5669-
* see cgroup_populate_dir()
5670-
*/
5671-
rcu_assign_pointer(child_css->id, child_id);
5672-
5673-
return 0;
5674-
}
5675-
5676-
/**
5677-
* css_lookup - lookup css by id
5678-
* @ss: cgroup subsys to be looked into.
5679-
* @id: the id
5680-
*
5681-
* Returns pointer to cgroup_subsys_state if there is valid one with id.
5682-
* NULL if not. Should be called under rcu_read_lock()
5683-
*/
5684-
struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
5685-
{
5686-
struct css_id *cssid = NULL;
5687-
5688-
BUG_ON(!ss->use_id);
5689-
cssid = idr_find(&ss->idr, id);
5690-
5691-
if (unlikely(!cssid))
5692-
return NULL;
5693-
5694-
return rcu_dereference(cssid->css);
5695-
}
5696-
EXPORT_SYMBOL_GPL(css_lookup);
5697-
56985452
/**
56995453
* css_from_dir - get corresponding css from the dentry of a cgroup dir
57005454
* @dentry: directory dentry of interest

0 commit comments

Comments
 (0)