aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-05-13 12:11:01 -0400
committerTejun Heo <tj@kernel.org>2014-05-13 12:11:01 -0400
commitec903c0c858e4963a9e0724bdcadfa837253341c (patch)
treeb52cd0d5bcac48d2d9c21e6186397c29ef89c33b
parent46cfeb043b04f5878154bea36714709d46028495 (diff)
cgroup: rename css_tryget*() to css_tryget_online*()
Unlike the more usual refcnting, what css_tryget() provides is the distinction between online and offline csses instead of protection against upping a refcnt which already reached zero. cgroup is planning to provide actual tryget which fails if the refcnt already reached zero. Let's rename the existing trygets so that they clearly indicate that they're onliness. I thought about keeping the existing names as-are and introducing new names for the planned actual tryget; however, given that each controller participates in the synchronization of the online state, it seems worthwhile to make it explicit that these functions are about on/offline state. Rename css_tryget() to css_tryget_online() and css_tryget_from_dir() to css_tryget_online_from_dir(). This is pure rename. v2: cgroup_freezer grew new usages of css_tryget(). Update accordingly. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
-rw-r--r--block/blk-cgroup.c2
-rw-r--r--fs/bio.c2
-rw-r--r--include/linux/cgroup.h14
-rw-r--r--kernel/cgroup.c40
-rw-r--r--kernel/cgroup_freezer.c4
-rw-r--r--kernel/cpuset.c6
-rw-r--r--kernel/events/core.c3
-rw-r--r--mm/hugetlb_cgroup.c2
-rw-r--r--mm/memcontrol.c46
9 files changed, 61 insertions, 58 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 1039fb9ff5f5..9f5bce33e6fe 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -185,7 +185,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
185 lockdep_assert_held(q->queue_lock); 185 lockdep_assert_held(q->queue_lock);
186 186
187 /* blkg holds a reference to blkcg */ 187 /* blkg holds a reference to blkcg */
188 if (!css_tryget(&blkcg->css)) { 188 if (!css_tryget_online(&blkcg->css)) {
189 ret = -EINVAL; 189 ret = -EINVAL;
190 goto err_free_blkg; 190 goto err_free_blkg;
191 } 191 }
diff --git a/fs/bio.c b/fs/bio.c
index 6f0362b77806..0608ef9422bd 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1970,7 +1970,7 @@ int bio_associate_current(struct bio *bio)
1970 /* associate blkcg if exists */ 1970 /* associate blkcg if exists */
1971 rcu_read_lock(); 1971 rcu_read_lock();
1972 css = task_css(current, blkio_cgrp_id); 1972 css = task_css(current, blkio_cgrp_id);
1973 if (css && css_tryget(css)) 1973 if (css && css_tryget_online(css))
1974 bio->bi_css = css; 1974 bio->bi_css = css;
1975 rcu_read_unlock(); 1975 rcu_read_unlock();
1976 1976
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index bde44618d8c2..c5f3684ef557 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -95,16 +95,16 @@ static inline void css_get(struct cgroup_subsys_state *css)
95} 95}
96 96
97/** 97/**
98 * css_tryget - try to obtain a reference on the specified css 98 * css_tryget_online - try to obtain a reference on the specified css if online
99 * @css: target css 99 * @css: target css
100 * 100 *
101 * Obtain a reference on @css if it's alive. The caller naturally needs to 101 * Obtain a reference on @css if it's online. The caller naturally needs
102 * ensure that @css is accessible but doesn't have to be holding a 102 * to ensure that @css is accessible but doesn't have to be holding a
103 * reference on it - IOW, RCU protected access is good enough for this 103 * reference on it - IOW, RCU protected access is good enough for this
104 * function. Returns %true if a reference count was successfully obtained; 104 * function. Returns %true if a reference count was successfully obtained;
105 * %false otherwise. 105 * %false otherwise.
106 */ 106 */
107static inline bool css_tryget(struct cgroup_subsys_state *css) 107static inline bool css_tryget_online(struct cgroup_subsys_state *css)
108{ 108{
109 if (css->flags & CSS_ROOT) 109 if (css->flags & CSS_ROOT)
110 return true; 110 return true;
@@ -115,7 +115,7 @@ static inline bool css_tryget(struct cgroup_subsys_state *css)
115 * css_put - put a css reference 115 * css_put - put a css reference
116 * @css: target css 116 * @css: target css
117 * 117 *
118 * Put a reference obtained via css_get() and css_tryget(). 118 * Put a reference obtained via css_get() and css_tryget_online().
119 */ 119 */
120static inline void css_put(struct cgroup_subsys_state *css) 120static inline void css_put(struct cgroup_subsys_state *css)
121{ 121{
@@ -905,8 +905,8 @@ void css_task_iter_end(struct css_task_iter *it);
905int cgroup_attach_task_all(struct task_struct *from, struct task_struct *); 905int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
906int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from); 906int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
907 907
908struct cgroup_subsys_state *css_tryget_from_dir(struct dentry *dentry, 908struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
909 struct cgroup_subsys *ss); 909 struct cgroup_subsys *ss);
910 910
911#else /* !CONFIG_CGROUPS */ 911#else /* !CONFIG_CGROUPS */
912 912
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7633703e9baf..671d8a6dae37 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3771,7 +3771,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
3771 3771
3772 /* 3772 /*
3773 * We aren't being called from kernfs and there's no guarantee on 3773 * We aren't being called from kernfs and there's no guarantee on
3774 * @kn->priv's validity. For this and css_tryget_from_dir(), 3774 * @kn->priv's validity. For this and css_tryget_online_from_dir(),
3775 * @kn->priv is RCU safe. Let's do the RCU dancing. 3775 * @kn->priv is RCU safe. Let's do the RCU dancing.
3776 */ 3776 */
3777 rcu_read_lock(); 3777 rcu_read_lock();
@@ -4060,9 +4060,9 @@ err:
4060 * Implemented in kill_css(). 4060 * Implemented in kill_css().
4061 * 4061 *
4062 * 2. When the percpu_ref is confirmed to be visible as killed on all CPUs 4062 * 2. When the percpu_ref is confirmed to be visible as killed on all CPUs
4063 * and thus css_tryget() is guaranteed to fail, the css can be offlined 4063 * and thus css_tryget_online() is guaranteed to fail, the css can be
4064 * by invoking offline_css(). After offlining, the base ref is put. 4064 * offlined by invoking offline_css(). After offlining, the base ref is
4065 * Implemented in css_killed_work_fn(). 4065 * put. Implemented in css_killed_work_fn().
4066 * 4066 *
4067 * 3. When the percpu_ref reaches zero, the only possible remaining 4067 * 3. When the percpu_ref reaches zero, the only possible remaining
4068 * accessors are inside RCU read sections. css_release() schedules the 4068 * accessors are inside RCU read sections. css_release() schedules the
@@ -4386,7 +4386,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
4386 4386
4387/* 4387/*
4388 * This is called when the refcnt of a css is confirmed to be killed. 4388 * This is called when the refcnt of a css is confirmed to be killed.
4389 * css_tryget() is now guaranteed to fail. 4389 * css_tryget_online() is now guaranteed to fail.
4390 */ 4390 */
4391static void css_killed_work_fn(struct work_struct *work) 4391static void css_killed_work_fn(struct work_struct *work)
4392{ 4392{
@@ -4398,8 +4398,8 @@ static void css_killed_work_fn(struct work_struct *work)
4398 mutex_lock(&cgroup_mutex); 4398 mutex_lock(&cgroup_mutex);
4399 4399
4400 /* 4400 /*
4401 * css_tryget() is guaranteed to fail now. Tell subsystems to 4401 * css_tryget_online() is guaranteed to fail now. Tell subsystems
4402 * initate destruction. 4402 * to initate destruction.
4403 */ 4403 */
4404 offline_css(css); 4404 offline_css(css);
4405 4405
@@ -4440,8 +4440,8 @@ static void css_killed_ref_fn(struct percpu_ref *ref)
4440 * 4440 *
4441 * This function initiates destruction of @css by removing cgroup interface 4441 * This function initiates destruction of @css by removing cgroup interface
4442 * files and putting its base reference. ->css_offline() will be invoked 4442 * files and putting its base reference. ->css_offline() will be invoked
4443 * asynchronously once css_tryget() is guaranteed to fail and when the 4443 * asynchronously once css_tryget_online() is guaranteed to fail and when
4444 * reference count reaches zero, @css will be released. 4444 * the reference count reaches zero, @css will be released.
4445 */ 4445 */
4446static void kill_css(struct cgroup_subsys_state *css) 4446static void kill_css(struct cgroup_subsys_state *css)
4447{ 4447{
@@ -4462,7 +4462,7 @@ static void kill_css(struct cgroup_subsys_state *css)
4462 /* 4462 /*
4463 * cgroup core guarantees that, by the time ->css_offline() is 4463 * cgroup core guarantees that, by the time ->css_offline() is
4464 * invoked, no new css reference will be given out via 4464 * invoked, no new css reference will be given out via
4465 * css_tryget(). We can't simply call percpu_ref_kill() and 4465 * css_tryget_online(). We can't simply call percpu_ref_kill() and
4466 * proceed to offlining css's because percpu_ref_kill() doesn't 4466 * proceed to offlining css's because percpu_ref_kill() doesn't
4467 * guarantee that the ref is seen as killed on all CPUs on return. 4467 * guarantee that the ref is seen as killed on all CPUs on return.
4468 * 4468 *
@@ -4478,9 +4478,9 @@ static void kill_css(struct cgroup_subsys_state *css)
4478 * 4478 *
4479 * css's make use of percpu refcnts whose killing latency shouldn't be 4479 * css's make use of percpu refcnts whose killing latency shouldn't be
4480 * exposed to userland and are RCU protected. Also, cgroup core needs to 4480 * exposed to userland and are RCU protected. Also, cgroup core needs to
4481 * guarantee that css_tryget() won't succeed by the time ->css_offline() is 4481 * guarantee that css_tryget_online() won't succeed by the time
4482 * invoked. To satisfy all the requirements, destruction is implemented in 4482 * ->css_offline() is invoked. To satisfy all the requirements,
4483 * the following two steps. 4483 * destruction is implemented in the following two steps.
4484 * 4484 *
4485 * s1. Verify @cgrp can be destroyed and mark it dying. Remove all 4485 * s1. Verify @cgrp can be destroyed and mark it dying. Remove all
4486 * userland visible parts and start killing the percpu refcnts of 4486 * userland visible parts and start killing the percpu refcnts of
@@ -4574,9 +4574,9 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
4574 /* 4574 /*
4575 * There are two control paths which try to determine cgroup from 4575 * There are two control paths which try to determine cgroup from
4576 * dentry without going through kernfs - cgroupstats_build() and 4576 * dentry without going through kernfs - cgroupstats_build() and
4577 * css_tryget_from_dir(). Those are supported by RCU protecting 4577 * css_tryget_online_from_dir(). Those are supported by RCU
4578 * clearing of cgrp->kn->priv backpointer, which should happen 4578 * protecting clearing of cgrp->kn->priv backpointer, which should
4579 * after all files under it have been removed. 4579 * happen after all files under it have been removed.
4580 */ 4580 */
4581 kernfs_remove(cgrp->kn); /* @cgrp has an extra ref on its kn */ 4581 kernfs_remove(cgrp->kn); /* @cgrp has an extra ref on its kn */
4582 RCU_INIT_POINTER(*(void __rcu __force **)&cgrp->kn->priv, NULL); 4582 RCU_INIT_POINTER(*(void __rcu __force **)&cgrp->kn->priv, NULL);
@@ -5173,7 +5173,7 @@ static int __init cgroup_disable(char *str)
5173__setup("cgroup_disable=", cgroup_disable); 5173__setup("cgroup_disable=", cgroup_disable);
5174 5174
5175/** 5175/**
5176 * css_tryget_from_dir - get corresponding css from the dentry of a cgroup dir 5176 * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
5177 * @dentry: directory dentry of interest 5177 * @dentry: directory dentry of interest
5178 * @ss: subsystem of interest 5178 * @ss: subsystem of interest
5179 * 5179 *
@@ -5181,8 +5181,8 @@ __setup("cgroup_disable=", cgroup_disable);
5181 * to get the corresponding css and return it. If such css doesn't exist 5181 * to get the corresponding css and return it. If such css doesn't exist
5182 * or can't be pinned, an ERR_PTR value is returned. 5182 * or can't be pinned, an ERR_PTR value is returned.
5183 */ 5183 */
5184struct cgroup_subsys_state *css_tryget_from_dir(struct dentry *dentry, 5184struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
5185 struct cgroup_subsys *ss) 5185 struct cgroup_subsys *ss)
5186{ 5186{
5187 struct kernfs_node *kn = kernfs_node_from_dentry(dentry); 5187 struct kernfs_node *kn = kernfs_node_from_dentry(dentry);
5188 struct cgroup_subsys_state *css = NULL; 5188 struct cgroup_subsys_state *css = NULL;
@@ -5204,7 +5204,7 @@ struct cgroup_subsys_state *css_tryget_from_dir(struct dentry *dentry,
5204 if (cgrp) 5204 if (cgrp)
5205 css = cgroup_css(cgrp, ss); 5205 css = cgroup_css(cgrp, ss);
5206 5206
5207 if (!css || !css_tryget(css)) 5207 if (!css || !css_tryget_online(css))
5208 css = ERR_PTR(-ENOENT); 5208 css = ERR_PTR(-ENOENT);
5209 5209
5210 rcu_read_unlock(); 5210 rcu_read_unlock();
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 345628c78b5b..0398f7e9ac81 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -304,7 +304,7 @@ static int freezer_read(struct seq_file *m, void *v)
304 304
305 /* update states bottom-up */ 305 /* update states bottom-up */
306 css_for_each_descendant_post(pos, css) { 306 css_for_each_descendant_post(pos, css) {
307 if (!css_tryget(pos)) 307 if (!css_tryget_online(pos))
308 continue; 308 continue;
309 rcu_read_unlock(); 309 rcu_read_unlock();
310 310
@@ -404,7 +404,7 @@ static void freezer_change_state(struct freezer *freezer, bool freeze)
404 struct freezer *pos_f = css_freezer(pos); 404 struct freezer *pos_f = css_freezer(pos);
405 struct freezer *parent = parent_freezer(pos_f); 405 struct freezer *parent = parent_freezer(pos_f);
406 406
407 if (!css_tryget(pos)) 407 if (!css_tryget_online(pos))
408 continue; 408 continue;
409 rcu_read_unlock(); 409 rcu_read_unlock();
410 410
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 7c0e8da59e26..37ca0a5c226d 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -872,7 +872,7 @@ static void update_tasks_cpumask_hier(struct cpuset *root_cs, bool update_root)
872 continue; 872 continue;
873 } 873 }
874 } 874 }
875 if (!css_tryget(&cp->css)) 875 if (!css_tryget_online(&cp->css))
876 continue; 876 continue;
877 rcu_read_unlock(); 877 rcu_read_unlock();
878 878
@@ -1108,7 +1108,7 @@ static void update_tasks_nodemask_hier(struct cpuset *root_cs, bool update_root)
1108 continue; 1108 continue;
1109 } 1109 }
1110 } 1110 }
1111 if (!css_tryget(&cp->css)) 1111 if (!css_tryget_online(&cp->css))
1112 continue; 1112 continue;
1113 rcu_read_unlock(); 1113 rcu_read_unlock();
1114 1114
@@ -2153,7 +2153,7 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
2153 2153
2154 rcu_read_lock(); 2154 rcu_read_lock();
2155 cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) { 2155 cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) {
2156 if (cs == &top_cpuset || !css_tryget(&cs->css)) 2156 if (cs == &top_cpuset || !css_tryget_online(&cs->css))
2157 continue; 2157 continue;
2158 rcu_read_unlock(); 2158 rcu_read_unlock();
2159 2159
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f83a71a3e46d..077968d19b8a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -607,7 +607,8 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
607 if (!f.file) 607 if (!f.file)
608 return -EBADF; 608 return -EBADF;
609 609
610 css = css_tryget_from_dir(f.file->f_dentry, &perf_event_cgrp_subsys); 610 css = css_tryget_online_from_dir(f.file->f_dentry,
611 &perf_event_cgrp_subsys);
611 if (IS_ERR(css)) { 612 if (IS_ERR(css)) {
612 ret = PTR_ERR(css); 613 ret = PTR_ERR(css);
613 goto out; 614 goto out;
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
index 595d7fd795e1..372f1adca491 100644
--- a/mm/hugetlb_cgroup.c
+++ b/mm/hugetlb_cgroup.c
@@ -181,7 +181,7 @@ int hugetlb_cgroup_charge_cgroup(int idx, unsigned long nr_pages,
181again: 181again:
182 rcu_read_lock(); 182 rcu_read_lock();
183 h_cg = hugetlb_cgroup_from_task(current); 183 h_cg = hugetlb_cgroup_from_task(current);
184 if (!css_tryget(&h_cg->css)) { 184 if (!css_tryget_online(&h_cg->css)) {
185 rcu_read_unlock(); 185 rcu_read_unlock();
186 goto again; 186 goto again;
187 } 187 }
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c3f82f69ef58..5cf3246314a2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -567,7 +567,8 @@ void sock_update_memcg(struct sock *sk)
567 memcg = mem_cgroup_from_task(current); 567 memcg = mem_cgroup_from_task(current);
568 cg_proto = sk->sk_prot->proto_cgroup(memcg); 568 cg_proto = sk->sk_prot->proto_cgroup(memcg);
569 if (!mem_cgroup_is_root(memcg) && 569 if (!mem_cgroup_is_root(memcg) &&
570 memcg_proto_active(cg_proto) && css_tryget(&memcg->css)) { 570 memcg_proto_active(cg_proto) &&
571 css_tryget_online(&memcg->css)) {
571 sk->sk_cgrp = cg_proto; 572 sk->sk_cgrp = cg_proto;
572 } 573 }
573 rcu_read_unlock(); 574 rcu_read_unlock();
@@ -834,7 +835,7 @@ retry:
834 */ 835 */
835 __mem_cgroup_remove_exceeded(mz->memcg, mz, mctz); 836 __mem_cgroup_remove_exceeded(mz->memcg, mz, mctz);
836 if (!res_counter_soft_limit_excess(&mz->memcg->res) || 837 if (!res_counter_soft_limit_excess(&mz->memcg->res) ||
837 !css_tryget(&mz->memcg->css)) 838 !css_tryget_online(&mz->memcg->css))
838 goto retry; 839 goto retry;
839done: 840done:
840 return mz; 841 return mz;
@@ -1076,7 +1077,7 @@ static struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
1076 memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); 1077 memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
1077 if (unlikely(!memcg)) 1078 if (unlikely(!memcg))
1078 memcg = root_mem_cgroup; 1079 memcg = root_mem_cgroup;
1079 } while (!css_tryget(&memcg->css)); 1080 } while (!css_tryget_online(&memcg->css));
1080 rcu_read_unlock(); 1081 rcu_read_unlock();
1081 return memcg; 1082 return memcg;
1082} 1083}
@@ -1113,7 +1114,8 @@ skip_node:
1113 */ 1114 */
1114 if (next_css) { 1115 if (next_css) {
1115 if ((next_css == &root->css) || 1116 if ((next_css == &root->css) ||
1116 ((next_css->flags & CSS_ONLINE) && css_tryget(next_css))) 1117 ((next_css->flags & CSS_ONLINE) &&
1118 css_tryget_online(next_css)))
1117 return mem_cgroup_from_css(next_css); 1119 return mem_cgroup_from_css(next_css);
1118 1120
1119 prev_css = next_css; 1121 prev_css = next_css;
@@ -1159,7 +1161,7 @@ mem_cgroup_iter_load(struct mem_cgroup_reclaim_iter *iter,
1159 * would be returned all the time. 1161 * would be returned all the time.
1160 */ 1162 */
1161 if (position && position != root && 1163 if (position && position != root &&
1162 !css_tryget(&position->css)) 1164 !css_tryget_online(&position->css))
1163 position = NULL; 1165 position = NULL;
1164 } 1166 }
1165 return position; 1167 return position;
@@ -2785,9 +2787,9 @@ static void __mem_cgroup_cancel_local_charge(struct mem_cgroup *memcg,
2785 2787
2786/* 2788/*
2787 * A helper function to get mem_cgroup from ID. must be called under 2789 * A helper function to get mem_cgroup from ID. must be called under
2788 * rcu_read_lock(). The caller is responsible for calling css_tryget if 2790 * rcu_read_lock(). The caller is responsible for calling
2789 * the mem_cgroup is used for charging. (dropping refcnt from swap can be 2791 * css_tryget_online() if the mem_cgroup is used for charging. (dropping
2790 * called against removed memcg.) 2792 * refcnt from swap can be called against removed memcg.)
2791 */ 2793 */
2792static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) 2794static struct mem_cgroup *mem_cgroup_lookup(unsigned short id)
2793{ 2795{
@@ -2810,14 +2812,14 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
2810 lock_page_cgroup(pc); 2812 lock_page_cgroup(pc);
2811 if (PageCgroupUsed(pc)) { 2813 if (PageCgroupUsed(pc)) {
2812 memcg = pc->mem_cgroup; 2814 memcg = pc->mem_cgroup;
2813 if (memcg && !css_tryget(&memcg->css)) 2815 if (memcg && !css_tryget_online(&memcg->css))
2814 memcg = NULL; 2816 memcg = NULL;
2815 } else if (PageSwapCache(page)) { 2817 } else if (PageSwapCache(page)) {
2816 ent.val = page_private(page); 2818 ent.val = page_private(page);
2817 id = lookup_swap_cgroup_id(ent); 2819 id = lookup_swap_cgroup_id(ent);
2818 rcu_read_lock(); 2820 rcu_read_lock();
2819 memcg = mem_cgroup_lookup(id); 2821 memcg = mem_cgroup_lookup(id);
2820 if (memcg && !css_tryget(&memcg->css)) 2822 if (memcg && !css_tryget_online(&memcg->css))
2821 memcg = NULL; 2823 memcg = NULL;
2822 rcu_read_unlock(); 2824 rcu_read_unlock();
2823 } 2825 }
@@ -3473,7 +3475,7 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep,
3473 } 3475 }
3474 3476
3475 /* The corresponding put will be done in the workqueue. */ 3477 /* The corresponding put will be done in the workqueue. */
3476 if (!css_tryget(&memcg->css)) 3478 if (!css_tryget_online(&memcg->css))
3477 goto out; 3479 goto out;
3478 rcu_read_unlock(); 3480 rcu_read_unlock();
3479 3481
@@ -4246,8 +4248,8 @@ void mem_cgroup_uncharge_swap(swp_entry_t ent)
4246 memcg = mem_cgroup_lookup(id); 4248 memcg = mem_cgroup_lookup(id);
4247 if (memcg) { 4249 if (memcg) {
4248 /* 4250 /*
4249 * We uncharge this because swap is freed. 4251 * We uncharge this because swap is freed. This memcg can
4250 * This memcg can be obsolete one. We avoid calling css_tryget 4252 * be obsolete one. We avoid calling css_tryget_online().
4251 */ 4253 */
4252 if (!mem_cgroup_is_root(memcg)) 4254 if (!mem_cgroup_is_root(memcg))
4253 res_counter_uncharge(&memcg->memsw, PAGE_SIZE); 4255 res_counter_uncharge(&memcg->memsw, PAGE_SIZE);
@@ -5840,10 +5842,10 @@ static void kmem_cgroup_css_offline(struct mem_cgroup *memcg)
5840 * which is then paired with css_put during uncharge resp. here. 5842 * which is then paired with css_put during uncharge resp. here.
5841 * 5843 *
5842 * Although this might sound strange as this path is called from 5844 * Although this might sound strange as this path is called from
5843 * css_offline() when the referencemight have dropped down to 0 5845 * css_offline() when the referencemight have dropped down to 0 and
5844 * and shouldn't be incremented anymore (css_tryget would fail) 5846 * shouldn't be incremented anymore (css_tryget_online() would
5845 * we do not have other options because of the kmem allocations 5847 * fail) we do not have other options because of the kmem
5846 * lifetime. 5848 * allocations lifetime.
5847 */ 5849 */
5848 css_get(&memcg->css); 5850 css_get(&memcg->css);
5849 5851
@@ -6051,8 +6053,8 @@ static int memcg_write_event_control(struct cgroup_subsys_state *css,
6051 * automatically removed on cgroup destruction but the removal is 6053 * automatically removed on cgroup destruction but the removal is
6052 * asynchronous, so take an extra ref on @css. 6054 * asynchronous, so take an extra ref on @css.
6053 */ 6055 */
6054 cfile_css = css_tryget_from_dir(cfile.file->f_dentry->d_parent, 6056 cfile_css = css_tryget_online_from_dir(cfile.file->f_dentry->d_parent,
6055 &memory_cgrp_subsys); 6057 &memory_cgrp_subsys);
6056 ret = -EINVAL; 6058 ret = -EINVAL;
6057 if (IS_ERR(cfile_css)) 6059 if (IS_ERR(cfile_css))
6058 goto out_put_cfile; 6060 goto out_put_cfile;
@@ -6496,7 +6498,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
6496 /* 6498 /*
6497 * XXX: css_offline() would be where we should reparent all 6499 * XXX: css_offline() would be where we should reparent all
6498 * memory to prepare the cgroup for destruction. However, 6500 * memory to prepare the cgroup for destruction. However,
6499 * memcg does not do css_tryget() and res_counter charging 6501 * memcg does not do css_tryget_online() and res_counter charging
6500 * under the same RCU lock region, which means that charging 6502 * under the same RCU lock region, which means that charging
6501 * could race with offlining. Offlining only happens to 6503 * could race with offlining. Offlining only happens to
6502 * cgroups with no tasks in them but charges can show up 6504 * cgroups with no tasks in them but charges can show up
@@ -6510,9 +6512,9 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
6510 * lookup_swap_cgroup_id() 6512 * lookup_swap_cgroup_id()
6511 * rcu_read_lock() 6513 * rcu_read_lock()
6512 * mem_cgroup_lookup() 6514 * mem_cgroup_lookup()
6513 * css_tryget() 6515 * css_tryget_online()
6514 * rcu_read_unlock() 6516 * rcu_read_unlock()
6515 * disable css_tryget() 6517 * disable css_tryget_online()
6516 * call_rcu() 6518 * call_rcu()
6517 * offline_css() 6519 * offline_css()
6518 * reparent_charges() 6520 * reparent_charges()