Commit d7b9fff7 authored by Daisuke Nishimura's avatar Daisuke Nishimura Committed by Linus Torvalds

cgroup: introduce coalesce css_get() and css_put()

Current css_get() and css_put() increment/decrement css->refcnt one by
one.

This patch add a new function __css_get(), which takes "count" as a arg
and increment the css->refcnt by "count".  And this patch also add a new
arg("count") to __css_put() and change the function to decrement the
css->refcnt by "count".

These coalesce version of __css_get()/__css_put() will be used to improve
performance of memcg's moving charge feature later, where instead of
calling css_get()/css_put() repeatedly, these new functions will be used.

No change is needed for current users of css_get()/css_put().
Signed-off-by: default avatarDaisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Acked-by: default avatarPaul Menage <menage@google.com>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2468c723
...@@ -76,6 +76,12 @@ enum { ...@@ -76,6 +76,12 @@ enum {
CSS_REMOVED, /* This CSS is dead */ CSS_REMOVED, /* This CSS is dead */
}; };
/* Caller must verify that the css is not for root cgroup */
static inline void __css_get(struct cgroup_subsys_state *css, int count)
{
atomic_add(count, &css->refcnt);
}
/* /*
* Call css_get() to hold a reference on the css; it can be used * Call css_get() to hold a reference on the css; it can be used
* for a reference obtained via: * for a reference obtained via:
...@@ -87,7 +93,7 @@ static inline void css_get(struct cgroup_subsys_state *css) ...@@ -87,7 +93,7 @@ static inline void css_get(struct cgroup_subsys_state *css)
{ {
/* We don't need to reference count the root state */ /* We don't need to reference count the root state */
if (!test_bit(CSS_ROOT, &css->flags)) if (!test_bit(CSS_ROOT, &css->flags))
atomic_inc(&css->refcnt); __css_get(css, 1);
} }
static inline bool css_is_removed(struct cgroup_subsys_state *css) static inline bool css_is_removed(struct cgroup_subsys_state *css)
...@@ -118,11 +124,11 @@ static inline bool css_tryget(struct cgroup_subsys_state *css) ...@@ -118,11 +124,11 @@ static inline bool css_tryget(struct cgroup_subsys_state *css)
* css_get() or css_tryget() * css_get() or css_tryget()
*/ */
extern void __css_put(struct cgroup_subsys_state *css); extern void __css_put(struct cgroup_subsys_state *css, int count);
static inline void css_put(struct cgroup_subsys_state *css) static inline void css_put(struct cgroup_subsys_state *css)
{ {
if (!test_bit(CSS_ROOT, &css->flags)) if (!test_bit(CSS_ROOT, &css->flags))
__css_put(css); __css_put(css, 1);
} }
/* bits in struct cgroup flags field */ /* bits in struct cgroup flags field */
......
...@@ -3746,12 +3746,13 @@ static void check_for_release(struct cgroup *cgrp) ...@@ -3746,12 +3746,13 @@ static void check_for_release(struct cgroup *cgrp)
} }
} }
void __css_put(struct cgroup_subsys_state *css) /* Caller must verify that the css is not for root cgroup */
void __css_put(struct cgroup_subsys_state *css, int count)
{ {
struct cgroup *cgrp = css->cgroup; struct cgroup *cgrp = css->cgroup;
int val; int val;
rcu_read_lock(); rcu_read_lock();
val = atomic_dec_return(&css->refcnt); val = atomic_sub_return(count, &css->refcnt);
if (val == 1) { if (val == 1) {
if (notify_on_release(cgrp)) { if (notify_on_release(cgrp)) {
set_bit(CGRP_RELEASABLE, &cgrp->flags); set_bit(CGRP_RELEASABLE, &cgrp->flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment