Commit d7b9fff711d5e8db8c844161c684017e556c38a0
Committed by
Linus Torvalds
1 parent
2468c7234b
Exists in
master
and in
4 other branches
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: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Acked-by: Paul Menage <menage@google.com> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: KAMEZAWA 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 12 additions and 5 deletions Side-by-side Diff
include/linux/cgroup.h
... | ... | @@ -76,6 +76,12 @@ |
76 | 76 | CSS_REMOVED, /* This CSS is dead */ |
77 | 77 | }; |
78 | 78 | |
79 | +/* Caller must verify that the css is not for root cgroup */ | |
80 | +static inline void __css_get(struct cgroup_subsys_state *css, int count) | |
81 | +{ | |
82 | + atomic_add(count, &css->refcnt); | |
83 | +} | |
84 | + | |
79 | 85 | /* |
80 | 86 | * Call css_get() to hold a reference on the css; it can be used |
81 | 87 | * for a reference obtained via: |
... | ... | @@ -87,7 +93,7 @@ |
87 | 93 | { |
88 | 94 | /* We don't need to reference count the root state */ |
89 | 95 | if (!test_bit(CSS_ROOT, &css->flags)) |
90 | - atomic_inc(&css->refcnt); | |
96 | + __css_get(css, 1); | |
91 | 97 | } |
92 | 98 | |
93 | 99 | static inline bool css_is_removed(struct cgroup_subsys_state *css) |
94 | 100 | |
... | ... | @@ -118,11 +124,11 @@ |
118 | 124 | * css_get() or css_tryget() |
119 | 125 | */ |
120 | 126 | |
121 | -extern void __css_put(struct cgroup_subsys_state *css); | |
127 | +extern void __css_put(struct cgroup_subsys_state *css, int count); | |
122 | 128 | static inline void css_put(struct cgroup_subsys_state *css) |
123 | 129 | { |
124 | 130 | if (!test_bit(CSS_ROOT, &css->flags)) |
125 | - __css_put(css); | |
131 | + __css_put(css, 1); | |
126 | 132 | } |
127 | 133 | |
128 | 134 | /* bits in struct cgroup flags field */ |
kernel/cgroup.c
... | ... | @@ -3746,12 +3746,13 @@ |
3746 | 3746 | } |
3747 | 3747 | } |
3748 | 3748 | |
3749 | -void __css_put(struct cgroup_subsys_state *css) | |
3749 | +/* Caller must verify that the css is not for root cgroup */ | |
3750 | +void __css_put(struct cgroup_subsys_state *css, int count) | |
3750 | 3751 | { |
3751 | 3752 | struct cgroup *cgrp = css->cgroup; |
3752 | 3753 | int val; |
3753 | 3754 | rcu_read_lock(); |
3754 | - val = atomic_dec_return(&css->refcnt); | |
3755 | + val = atomic_sub_return(count, &css->refcnt); | |
3755 | 3756 | if (val == 1) { |
3756 | 3757 | if (notify_on_release(cgrp)) { |
3757 | 3758 | set_bit(CGRP_RELEASABLE, &cgrp->flags); |