aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:26 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:26 -0400
commit81eeaf0411204f52af8ef78ff107cfca2fcfec1d (patch)
tree50ef753a5f351d9b838c0fbcf16f9e3b3723cc15
parent72ec7029937f0518eff21b8762743c31591684f5 (diff)
cgroup: make cftype->[un]register_event() deal with cgroup_subsys_state instead of cgroup
cgroup is in the process of converting to css (cgroup_subsys_state) from cgroup as the principal subsystem interface handle. This is mostly to prepare for the unified hierarchy support where css's will be created and destroyed dynamically but also helps cleaning up subsystem implementations as css is usually what they are interested in anyway. cftype->[un]register_event() is among the remaining couple interfaces which still use struct cgroup. Convert it to cgroup_subsys_state. The conversion is mostly mechanical and removes the last users of mem_cgroup_from_cont() and cg_to_vmpressure(), which are removed. v2: indentation update as suggested by Li Zefan. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com>
-rw-r--r--include/linux/cgroup.h10
-rw-r--r--include/linux/vmpressure.h6
-rw-r--r--kernel/cgroup.c15
-rw-r--r--mm/memcontrol.c21
-rw-r--r--mm/vmpressure.c21
5 files changed, 35 insertions, 38 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index cd105fce089c..b065d24486e6 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -506,16 +506,18 @@ struct cftype {
506 * you want to provide this functionality. Use eventfd_signal() 506 * you want to provide this functionality. Use eventfd_signal()
507 * on eventfd to send notification to userspace. 507 * on eventfd to send notification to userspace.
508 */ 508 */
509 int (*register_event)(struct cgroup *cgrp, struct cftype *cft, 509 int (*register_event)(struct cgroup_subsys_state *css,
510 struct eventfd_ctx *eventfd, const char *args); 510 struct cftype *cft, struct eventfd_ctx *eventfd,
511 const char *args);
511 /* 512 /*
512 * unregister_event() callback will be called when userspace 513 * unregister_event() callback will be called when userspace
513 * closes the eventfd or on cgroup removing. 514 * closes the eventfd or on cgroup removing.
514 * This callback must be implemented, if you want provide 515 * This callback must be implemented, if you want provide
515 * notification functionality. 516 * notification functionality.
516 */ 517 */
517 void (*unregister_event)(struct cgroup *cgrp, struct cftype *cft, 518 void (*unregister_event)(struct cgroup_subsys_state *css,
518 struct eventfd_ctx *eventfd); 519 struct cftype *cft,
520 struct eventfd_ctx *eventfd);
519}; 521};
520 522
521/* 523/*
diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h
index 76be077340ea..b239482bd39d 100644
--- a/include/linux/vmpressure.h
+++ b/include/linux/vmpressure.h
@@ -33,10 +33,12 @@ extern void vmpressure_init(struct vmpressure *vmpr);
33extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg); 33extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
34extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr); 34extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
35extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css); 35extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css);
36extern int vmpressure_register_event(struct cgroup *cg, struct cftype *cft, 36extern int vmpressure_register_event(struct cgroup_subsys_state *css,
37 struct cftype *cft,
37 struct eventfd_ctx *eventfd, 38 struct eventfd_ctx *eventfd,
38 const char *args); 39 const char *args);
39extern void vmpressure_unregister_event(struct cgroup *cg, struct cftype *cft, 40extern void vmpressure_unregister_event(struct cgroup_subsys_state *css,
41 struct cftype *cft,
40 struct eventfd_ctx *eventfd); 42 struct eventfd_ctx *eventfd);
41#else 43#else
42static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, 44static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 8c57301d0561..a71f2e0f9711 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -159,9 +159,9 @@ struct css_id {
159 */ 159 */
160struct cgroup_event { 160struct cgroup_event {
161 /* 161 /*
162 * Cgroup which the event belongs to. 162 * css which the event belongs to.
163 */ 163 */
164 struct cgroup *cgrp; 164 struct cgroup_subsys_state *css;
165 /* 165 /*
166 * Control file which the event associated. 166 * Control file which the event associated.
167 */ 167 */
@@ -3955,11 +3955,12 @@ static void cgroup_event_remove(struct work_struct *work)
3955{ 3955{
3956 struct cgroup_event *event = container_of(work, struct cgroup_event, 3956 struct cgroup_event *event = container_of(work, struct cgroup_event,
3957 remove); 3957 remove);
3958 struct cgroup *cgrp = event->cgrp; 3958 struct cgroup_subsys_state *css = event->css;
3959 struct cgroup *cgrp = css->cgroup;
3959 3960
3960 remove_wait_queue(event->wqh, &event->wait); 3961 remove_wait_queue(event->wqh, &event->wait);
3961 3962
3962 event->cft->unregister_event(cgrp, event->cft, event->eventfd); 3963 event->cft->unregister_event(css, event->cft, event->eventfd);
3963 3964
3964 /* Notify userspace the event is going away. */ 3965 /* Notify userspace the event is going away. */
3965 eventfd_signal(event->eventfd, 1); 3966 eventfd_signal(event->eventfd, 1);
@@ -3979,7 +3980,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
3979{ 3980{
3980 struct cgroup_event *event = container_of(wait, 3981 struct cgroup_event *event = container_of(wait,
3981 struct cgroup_event, wait); 3982 struct cgroup_event, wait);
3982 struct cgroup *cgrp = event->cgrp; 3983 struct cgroup *cgrp = event->css->cgroup;
3983 unsigned long flags = (unsigned long)key; 3984 unsigned long flags = (unsigned long)key;
3984 3985
3985 if (flags & POLLHUP) { 3986 if (flags & POLLHUP) {
@@ -4048,7 +4049,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
4048 event = kzalloc(sizeof(*event), GFP_KERNEL); 4049 event = kzalloc(sizeof(*event), GFP_KERNEL);
4049 if (!event) 4050 if (!event)
4050 return -ENOMEM; 4051 return -ENOMEM;
4051 event->cgrp = cgrp; 4052 event->css = css;
4052 INIT_LIST_HEAD(&event->list); 4053 INIT_LIST_HEAD(&event->list);
4053 init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); 4054 init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc);
4054 init_waitqueue_func_entry(&event->wait, cgroup_event_wake); 4055 init_waitqueue_func_entry(&event->wait, cgroup_event_wake);
@@ -4099,7 +4100,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
4099 goto out_put_cfile; 4100 goto out_put_cfile;
4100 } 4101 }
4101 4102
4102 ret = event->cft->register_event(cgrp, event->cft, 4103 ret = event->cft->register_event(css, event->cft,
4103 event->eventfd, buffer); 4104 event->eventfd, buffer);
4104 if (ret) 4105 if (ret)
4105 goto out_put_cfile; 4106 goto out_put_cfile;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 95106a993777..2885e3e85047 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1034,11 +1034,6 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
1034 preempt_enable(); 1034 preempt_enable();
1035} 1035}
1036 1036
1037static inline struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
1038{
1039 return mem_cgroup_from_css(cgroup_css(cont, mem_cgroup_subsys_id));
1040}
1041
1042struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) 1037struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
1043{ 1038{
1044 /* 1039 /*
@@ -5620,10 +5615,10 @@ static void mem_cgroup_oom_notify(struct mem_cgroup *memcg)
5620 mem_cgroup_oom_notify_cb(iter); 5615 mem_cgroup_oom_notify_cb(iter);
5621} 5616}
5622 5617
5623static int mem_cgroup_usage_register_event(struct cgroup *cgrp, 5618static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css,
5624 struct cftype *cft, struct eventfd_ctx *eventfd, const char *args) 5619 struct cftype *cft, struct eventfd_ctx *eventfd, const char *args)
5625{ 5620{
5626 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5621 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5627 struct mem_cgroup_thresholds *thresholds; 5622 struct mem_cgroup_thresholds *thresholds;
5628 struct mem_cgroup_threshold_ary *new; 5623 struct mem_cgroup_threshold_ary *new;
5629 enum res_type type = MEMFILE_TYPE(cft->private); 5624 enum res_type type = MEMFILE_TYPE(cft->private);
@@ -5703,10 +5698,10 @@ unlock:
5703 return ret; 5698 return ret;
5704} 5699}
5705 5700
5706static void mem_cgroup_usage_unregister_event(struct cgroup *cgrp, 5701static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css,
5707 struct cftype *cft, struct eventfd_ctx *eventfd) 5702 struct cftype *cft, struct eventfd_ctx *eventfd)
5708{ 5703{
5709 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5704 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5710 struct mem_cgroup_thresholds *thresholds; 5705 struct mem_cgroup_thresholds *thresholds;
5711 struct mem_cgroup_threshold_ary *new; 5706 struct mem_cgroup_threshold_ary *new;
5712 enum res_type type = MEMFILE_TYPE(cft->private); 5707 enum res_type type = MEMFILE_TYPE(cft->private);
@@ -5782,10 +5777,10 @@ unlock:
5782 mutex_unlock(&memcg->thresholds_lock); 5777 mutex_unlock(&memcg->thresholds_lock);
5783} 5778}
5784 5779
5785static int mem_cgroup_oom_register_event(struct cgroup *cgrp, 5780static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css,
5786 struct cftype *cft, struct eventfd_ctx *eventfd, const char *args) 5781 struct cftype *cft, struct eventfd_ctx *eventfd, const char *args)
5787{ 5782{
5788 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5783 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5789 struct mem_cgroup_eventfd_list *event; 5784 struct mem_cgroup_eventfd_list *event;
5790 enum res_type type = MEMFILE_TYPE(cft->private); 5785 enum res_type type = MEMFILE_TYPE(cft->private);
5791 5786
@@ -5807,10 +5802,10 @@ static int mem_cgroup_oom_register_event(struct cgroup *cgrp,
5807 return 0; 5802 return 0;
5808} 5803}
5809 5804
5810static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp, 5805static void mem_cgroup_oom_unregister_event(struct cgroup_subsys_state *css,
5811 struct cftype *cft, struct eventfd_ctx *eventfd) 5806 struct cftype *cft, struct eventfd_ctx *eventfd)
5812{ 5807{
5813 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5808 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5814 struct mem_cgroup_eventfd_list *ev, *tmp; 5809 struct mem_cgroup_eventfd_list *ev, *tmp;
5815 enum res_type type = MEMFILE_TYPE(cft->private); 5810 enum res_type type = MEMFILE_TYPE(cft->private);
5816 5811
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 2a8a736e95cc..13489b1f4ee3 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -74,11 +74,6 @@ static struct vmpressure *work_to_vmpressure(struct work_struct *work)
74 return container_of(work, struct vmpressure, work); 74 return container_of(work, struct vmpressure, work);
75} 75}
76 76
77static struct vmpressure *cg_to_vmpressure(struct cgroup *cg)
78{
79 return css_to_vmpressure(cgroup_css(cg, mem_cgroup_subsys_id));
80}
81
82static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr) 77static struct vmpressure *vmpressure_parent(struct vmpressure *vmpr)
83{ 78{
84 struct cgroup_subsys_state *css = vmpressure_to_css(vmpr); 79 struct cgroup_subsys_state *css = vmpressure_to_css(vmpr);
@@ -283,7 +278,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
283 278
284/** 279/**
285 * vmpressure_register_event() - Bind vmpressure notifications to an eventfd 280 * vmpressure_register_event() - Bind vmpressure notifications to an eventfd
286 * @cg: cgroup that is interested in vmpressure notifications 281 * @css: css that is interested in vmpressure notifications
287 * @cft: cgroup control files handle 282 * @cft: cgroup control files handle
288 * @eventfd: eventfd context to link notifications with 283 * @eventfd: eventfd context to link notifications with
289 * @args: event arguments (used to set up a pressure level threshold) 284 * @args: event arguments (used to set up a pressure level threshold)
@@ -298,10 +293,11 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
298 * cftype).register_event, and then cgroup core will handle everything by 293 * cftype).register_event, and then cgroup core will handle everything by
299 * itself. 294 * itself.
300 */ 295 */
301int vmpressure_register_event(struct cgroup *cg, struct cftype *cft, 296int vmpressure_register_event(struct cgroup_subsys_state *css,
302 struct eventfd_ctx *eventfd, const char *args) 297 struct cftype *cft, struct eventfd_ctx *eventfd,
298 const char *args)
303{ 299{
304 struct vmpressure *vmpr = cg_to_vmpressure(cg); 300 struct vmpressure *vmpr = css_to_vmpressure(css);
305 struct vmpressure_event *ev; 301 struct vmpressure_event *ev;
306 int level; 302 int level;
307 303
@@ -329,7 +325,7 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
329 325
330/** 326/**
331 * vmpressure_unregister_event() - Unbind eventfd from vmpressure 327 * vmpressure_unregister_event() - Unbind eventfd from vmpressure
332 * @cg: cgroup handle 328 * @css: css handle
333 * @cft: cgroup control files handle 329 * @cft: cgroup control files handle
334 * @eventfd: eventfd context that was used to link vmpressure with the @cg 330 * @eventfd: eventfd context that was used to link vmpressure with the @cg
335 * 331 *
@@ -341,10 +337,11 @@ int vmpressure_register_event(struct cgroup *cg, struct cftype *cft,
341 * cftype).unregister_event, and then cgroup core will handle everything 337 * cftype).unregister_event, and then cgroup core will handle everything
342 * by itself. 338 * by itself.
343 */ 339 */
344void vmpressure_unregister_event(struct cgroup *cg, struct cftype *cft, 340void vmpressure_unregister_event(struct cgroup_subsys_state *css,
341 struct cftype *cft,
345 struct eventfd_ctx *eventfd) 342 struct eventfd_ctx *eventfd)
346{ 343{
347 struct vmpressure *vmpr = cg_to_vmpressure(cg); 344 struct vmpressure *vmpr = css_to_vmpressure(css);
348 struct vmpressure_event *ev; 345 struct vmpressure_event *ev;
349 346
350 mutex_lock(&vmpr->events_lock); 347 mutex_lock(&vmpr->events_lock);