mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-04-01 03:44:08 +00:00
cgroup: kill CSS_REMOVED
CSS_REMOVED is one of the several contortions which were necessary to support css reference draining on cgroup removal. All css->refcnts which need draining should be deactivated and verified to equal zero atomically w.r.t. css_tryget(). If any one isn't zero, all refcnts needed to be re-activated and css_tryget() shouldn't fail in the process. This was achieved by letting css_tryget() busy-loop until either the refcnt is reactivated (failed removal attempt) or CSS_REMOVED is set (committing to removal). Now that css refcnt draining is no longer used, there's no need for atomic rollback mechanism. css_tryget() simply can look at the reference count and fail if it's deactivated - it's never getting re-activated. This patch removes CSS_REMOVED and updates __css_tryget() to fail if the refcnt is deactivated. As deactivation and removal are a single step now, they no longer need to be protected against css_tryget() happening from irq context. Remove local_irq_disable/enable() from cgroup_rmdir(). Note that this removes css_is_removed() whose only user is VM_BUG_ON() in memcontrol.c. We can replace it with a check on the refcnt but given that the only use case is a debug assert, I think it's better to simply unexport it. v2: Comment updated and explanation on local_irq_disable/enable() added per Michal Hocko. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Michal Hocko <mhocko@suse.cz> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com>
This commit is contained in:
parent
ed95779340
commit
e93160803f
3 changed files with 15 additions and 29 deletions
|
@ -85,7 +85,6 @@ struct cgroup_subsys_state {
|
||||||
/* bits in struct cgroup_subsys_state flags field */
|
/* bits in struct cgroup_subsys_state flags field */
|
||||||
enum {
|
enum {
|
||||||
CSS_ROOT, /* This CSS is the root of the subsystem */
|
CSS_ROOT, /* This CSS is the root of the subsystem */
|
||||||
CSS_REMOVED, /* This CSS is dead */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Caller must verify that the css is not for root cgroup */
|
/* Caller must verify that the css is not for root cgroup */
|
||||||
|
@ -108,11 +107,6 @@ static inline void css_get(struct cgroup_subsys_state *css)
|
||||||
__css_get(css, 1);
|
__css_get(css, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool css_is_removed(struct cgroup_subsys_state *css)
|
|
||||||
{
|
|
||||||
return test_bit(CSS_REMOVED, &css->flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call css_tryget() to take a reference on a css if your existing
|
* Call css_tryget() to take a reference on a css if your existing
|
||||||
* (known-valid) reference isn't already ref-counted. Returns false if
|
* (known-valid) reference isn't already ref-counted. Returns false if
|
||||||
|
|
|
@ -170,8 +170,8 @@ struct css_id {
|
||||||
* The css to which this ID points. This pointer is set to valid value
|
* The css to which this ID points. This pointer is set to valid value
|
||||||
* after cgroup is populated. If cgroup is removed, this will be NULL.
|
* after cgroup is populated. If cgroup is removed, this will be NULL.
|
||||||
* This pointer is expected to be RCU-safe because destroy()
|
* This pointer is expected to be RCU-safe because destroy()
|
||||||
* is called after synchronize_rcu(). But for safe use, css_is_removed()
|
* is called after synchronize_rcu(). But for safe use, css_tryget()
|
||||||
* css_tryget() should be used for avoiding race.
|
* should be used for avoiding race.
|
||||||
*/
|
*/
|
||||||
struct cgroup_subsys_state __rcu *css;
|
struct cgroup_subsys_state __rcu *css;
|
||||||
/*
|
/*
|
||||||
|
@ -4112,8 +4112,6 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
|
||||||
}
|
}
|
||||||
prepare_to_wait(&cgroup_rmdir_waitq, &wait, TASK_INTERRUPTIBLE);
|
prepare_to_wait(&cgroup_rmdir_waitq, &wait, TASK_INTERRUPTIBLE);
|
||||||
|
|
||||||
local_irq_disable();
|
|
||||||
|
|
||||||
/* block new css_tryget() by deactivating refcnt */
|
/* block new css_tryget() by deactivating refcnt */
|
||||||
for_each_subsys(cgrp->root, ss) {
|
for_each_subsys(cgrp->root, ss) {
|
||||||
struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id];
|
struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id];
|
||||||
|
@ -4123,21 +4121,14 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set REMOVED. All in-progress css_tryget() will be released.
|
|
||||||
* Put all the base refs. Each css holds an extra reference to the
|
* Put all the base refs. Each css holds an extra reference to the
|
||||||
* cgroup's dentry and cgroup removal proceeds regardless of css
|
* cgroup's dentry and cgroup removal proceeds regardless of css
|
||||||
* refs. On the last put of each css, whenever that may be, the
|
* refs. On the last put of each css, whenever that may be, the
|
||||||
* extra dentry ref is put so that dentry destruction happens only
|
* extra dentry ref is put so that dentry destruction happens only
|
||||||
* after all css's are released.
|
* after all css's are released.
|
||||||
*/
|
*/
|
||||||
for_each_subsys(cgrp->root, ss) {
|
for_each_subsys(cgrp->root, ss)
|
||||||
struct cgroup_subsys_state *css = cgrp->subsys[ss->subsys_id];
|
css_put(cgrp->subsys[ss->subsys_id]);
|
||||||
|
|
||||||
set_bit(CSS_REMOVED, &css->flags);
|
|
||||||
css_put(css);
|
|
||||||
}
|
|
||||||
|
|
||||||
local_irq_enable();
|
|
||||||
|
|
||||||
finish_wait(&cgroup_rmdir_waitq, &wait);
|
finish_wait(&cgroup_rmdir_waitq, &wait);
|
||||||
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
clear_bit(CGRP_WAIT_ON_RMDIR, &cgrp->flags);
|
||||||
|
@ -4861,15 +4852,17 @@ static void check_for_release(struct cgroup *cgrp)
|
||||||
/* Caller must verify that the css is not for root cgroup */
|
/* Caller must verify that the css is not for root cgroup */
|
||||||
bool __css_tryget(struct cgroup_subsys_state *css)
|
bool __css_tryget(struct cgroup_subsys_state *css)
|
||||||
{
|
{
|
||||||
do {
|
while (true) {
|
||||||
int v = css_refcnt(css);
|
int t, v;
|
||||||
|
|
||||||
if (atomic_cmpxchg(&css->refcnt, v, v + 1) == v)
|
v = css_refcnt(css);
|
||||||
|
t = atomic_cmpxchg(&css->refcnt, v, v + 1);
|
||||||
|
if (likely(t == v))
|
||||||
return true;
|
return true;
|
||||||
cpu_relax();
|
else if (t < 0)
|
||||||
} while (!test_bit(CSS_REMOVED, &css->flags));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
cpu_relax();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__css_tryget);
|
EXPORT_SYMBOL_GPL(__css_tryget);
|
||||||
|
|
||||||
|
|
|
@ -2343,7 +2343,6 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
|
||||||
again:
|
again:
|
||||||
if (*ptr) { /* css should be a valid one */
|
if (*ptr) { /* css should be a valid one */
|
||||||
memcg = *ptr;
|
memcg = *ptr;
|
||||||
VM_BUG_ON(css_is_removed(&memcg->css));
|
|
||||||
if (mem_cgroup_is_root(memcg))
|
if (mem_cgroup_is_root(memcg))
|
||||||
goto done;
|
goto done;
|
||||||
if (nr_pages == 1 && consume_stock(memcg))
|
if (nr_pages == 1 && consume_stock(memcg))
|
||||||
|
@ -2483,9 +2482,9 @@ static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A helper function to get mem_cgroup from ID. must be called under
|
* A helper function to get mem_cgroup from ID. must be called under
|
||||||
* rcu_read_lock(). The caller must check css_is_removed() or some if
|
* rcu_read_lock(). The caller is responsible for calling css_tryget if
|
||||||
* it's concern. (dropping refcnt from swap can be called against removed
|
* the mem_cgroup is used for charging. (dropping refcnt from swap can be
|
||||||
* memcg.)
|
* called against removed memcg.)
|
||||||
*/
|
*/
|
||||||
static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
|
static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue