diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-22 18:20:43 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-11-22 18:20:43 -0500 |
commit | 59b6f87344ab5eb3057e5844b8cd8a39e668f477 (patch) | |
tree | 889411e1dd5023e63dfbd723e770669824c5072d | |
parent | 347c4a8747104a945ecced358944e42879176ca5 (diff) |
memcg: make cgroup_event deal with mem_cgroup instead of cgroup_subsys_state
cgroup_event is now memcg specific. Replace cgroup_event->css with
->memcg and convert [un]register_event() callbacks to take mem_cgroup
pointer instead of cgroup_subsys_state one. This simplifies the code
slightly and makes css_to_vmpressure() unnecessary which is removed.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
-rw-r--r-- | include/linux/vmpressure.h | 5 | ||||
-rw-r--r-- | mm/memcontrol.c | 53 | ||||
-rw-r--r-- | mm/vmpressure.c | 12 |
3 files changed, 30 insertions, 40 deletions
diff --git a/include/linux/vmpressure.h b/include/linux/vmpressure.h index b048365a7ed9..3e4535876d37 100644 --- a/include/linux/vmpressure.h +++ b/include/linux/vmpressure.h | |||
@@ -34,11 +34,10 @@ extern void vmpressure_init(struct vmpressure *vmpr); | |||
34 | extern void vmpressure_cleanup(struct vmpressure *vmpr); | 34 | extern void vmpressure_cleanup(struct vmpressure *vmpr); |
35 | extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg); | 35 | extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg); |
36 | extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr); | 36 | extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr); |
37 | extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css); | 37 | extern int vmpressure_register_event(struct mem_cgroup *memcg, |
38 | extern int vmpressure_register_event(struct cgroup_subsys_state *css, | ||
39 | struct eventfd_ctx *eventfd, | 38 | struct eventfd_ctx *eventfd, |
40 | const char *args); | 39 | const char *args); |
41 | extern void vmpressure_unregister_event(struct cgroup_subsys_state *css, | 40 | extern void vmpressure_unregister_event(struct mem_cgroup *memcg, |
42 | struct eventfd_ctx *eventfd); | 41 | struct eventfd_ctx *eventfd); |
43 | #else | 42 | #else |
44 | static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, | 43 | static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 3c93dcfd26da..42f2843af1a7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -233,9 +233,9 @@ struct mem_cgroup_eventfd_list { | |||
233 | */ | 233 | */ |
234 | struct cgroup_event { | 234 | struct cgroup_event { |
235 | /* | 235 | /* |
236 | * css which the event belongs to. | 236 | * memcg which the event belongs to. |
237 | */ | 237 | */ |
238 | struct cgroup_subsys_state *css; | 238 | struct mem_cgroup *memcg; |
239 | /* | 239 | /* |
240 | * eventfd to signal userspace about the event. | 240 | * eventfd to signal userspace about the event. |
241 | */ | 241 | */ |
@@ -249,14 +249,14 @@ struct cgroup_event { | |||
249 | * waiter for changes related to this event. Use eventfd_signal() | 249 | * waiter for changes related to this event. Use eventfd_signal() |
250 | * on eventfd to send notification to userspace. | 250 | * on eventfd to send notification to userspace. |
251 | */ | 251 | */ |
252 | int (*register_event)(struct cgroup_subsys_state *css, | 252 | int (*register_event)(struct mem_cgroup *memcg, |
253 | struct eventfd_ctx *eventfd, const char *args); | 253 | struct eventfd_ctx *eventfd, const char *args); |
254 | /* | 254 | /* |
255 | * unregister_event() callback will be called when userspace closes | 255 | * unregister_event() callback will be called when userspace closes |
256 | * the eventfd or on cgroup removing. This callback must be set, | 256 | * the eventfd or on cgroup removing. This callback must be set, |
257 | * if you want provide notification functionality. | 257 | * if you want provide notification functionality. |
258 | */ | 258 | */ |
259 | void (*unregister_event)(struct cgroup_subsys_state *css, | 259 | void (*unregister_event)(struct mem_cgroup *memcg, |
260 | struct eventfd_ctx *eventfd); | 260 | struct eventfd_ctx *eventfd); |
261 | /* | 261 | /* |
262 | * All fields below needed to unregister event when | 262 | * All fields below needed to unregister event when |
@@ -535,11 +535,6 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr) | |||
535 | return &container_of(vmpr, struct mem_cgroup, vmpressure)->css; | 535 | return &container_of(vmpr, struct mem_cgroup, vmpressure)->css; |
536 | } | 536 | } |
537 | 537 | ||
538 | struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css) | ||
539 | { | ||
540 | return &mem_cgroup_from_css(css)->vmpressure; | ||
541 | } | ||
542 | |||
543 | static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) | 538 | static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) |
544 | { | 539 | { |
545 | return (memcg == root_mem_cgroup); | 540 | return (memcg == root_mem_cgroup); |
@@ -5682,10 +5677,9 @@ static void mem_cgroup_oom_notify(struct mem_cgroup *memcg) | |||
5682 | mem_cgroup_oom_notify_cb(iter); | 5677 | mem_cgroup_oom_notify_cb(iter); |
5683 | } | 5678 | } |
5684 | 5679 | ||
5685 | static int __mem_cgroup_usage_register_event(struct cgroup_subsys_state *css, | 5680 | static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, |
5686 | struct eventfd_ctx *eventfd, const char *args, enum res_type type) | 5681 | struct eventfd_ctx *eventfd, const char *args, enum res_type type) |
5687 | { | 5682 | { |
5688 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | ||
5689 | struct mem_cgroup_thresholds *thresholds; | 5683 | struct mem_cgroup_thresholds *thresholds; |
5690 | struct mem_cgroup_threshold_ary *new; | 5684 | struct mem_cgroup_threshold_ary *new; |
5691 | u64 threshold, usage; | 5685 | u64 threshold, usage; |
@@ -5764,22 +5758,21 @@ unlock: | |||
5764 | return ret; | 5758 | return ret; |
5765 | } | 5759 | } |
5766 | 5760 | ||
5767 | static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css, | 5761 | static int mem_cgroup_usage_register_event(struct mem_cgroup *memcg, |
5768 | struct eventfd_ctx *eventfd, const char *args) | 5762 | struct eventfd_ctx *eventfd, const char *args) |
5769 | { | 5763 | { |
5770 | return __mem_cgroup_usage_register_event(css, eventfd, args, _MEM); | 5764 | return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEM); |
5771 | } | 5765 | } |
5772 | 5766 | ||
5773 | static int memsw_cgroup_usage_register_event(struct cgroup_subsys_state *css, | 5767 | static int memsw_cgroup_usage_register_event(struct mem_cgroup *memcg, |
5774 | struct eventfd_ctx *eventfd, const char *args) | 5768 | struct eventfd_ctx *eventfd, const char *args) |
5775 | { | 5769 | { |
5776 | return __mem_cgroup_usage_register_event(css, eventfd, args, _MEMSWAP); | 5770 | return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEMSWAP); |
5777 | } | 5771 | } |
5778 | 5772 | ||
5779 | static void __mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, | 5773 | static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, |
5780 | struct eventfd_ctx *eventfd, enum res_type type) | 5774 | struct eventfd_ctx *eventfd, enum res_type type) |
5781 | { | 5775 | { |
5782 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | ||
5783 | struct mem_cgroup_thresholds *thresholds; | 5776 | struct mem_cgroup_thresholds *thresholds; |
5784 | struct mem_cgroup_threshold_ary *new; | 5777 | struct mem_cgroup_threshold_ary *new; |
5785 | u64 usage; | 5778 | u64 usage; |
@@ -5854,22 +5847,21 @@ unlock: | |||
5854 | mutex_unlock(&memcg->thresholds_lock); | 5847 | mutex_unlock(&memcg->thresholds_lock); |
5855 | } | 5848 | } |
5856 | 5849 | ||
5857 | static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, | 5850 | static void mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, |
5858 | struct eventfd_ctx *eventfd) | 5851 | struct eventfd_ctx *eventfd) |
5859 | { | 5852 | { |
5860 | return __mem_cgroup_usage_unregister_event(css, eventfd, _MEM); | 5853 | return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEM); |
5861 | } | 5854 | } |
5862 | 5855 | ||
5863 | static void memsw_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, | 5856 | static void memsw_cgroup_usage_unregister_event(struct mem_cgroup *memcg, |
5864 | struct eventfd_ctx *eventfd) | 5857 | struct eventfd_ctx *eventfd) |
5865 | { | 5858 | { |
5866 | return __mem_cgroup_usage_unregister_event(css, eventfd, _MEMSWAP); | 5859 | return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEMSWAP); |
5867 | } | 5860 | } |
5868 | 5861 | ||
5869 | static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css, | 5862 | static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg, |
5870 | struct eventfd_ctx *eventfd, const char *args) | 5863 | struct eventfd_ctx *eventfd, const char *args) |
5871 | { | 5864 | { |
5872 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | ||
5873 | struct mem_cgroup_eventfd_list *event; | 5865 | struct mem_cgroup_eventfd_list *event; |
5874 | 5866 | ||
5875 | event = kmalloc(sizeof(*event), GFP_KERNEL); | 5867 | event = kmalloc(sizeof(*event), GFP_KERNEL); |
@@ -5889,10 +5881,9 @@ static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css, | |||
5889 | return 0; | 5881 | return 0; |
5890 | } | 5882 | } |
5891 | 5883 | ||
5892 | static void mem_cgroup_oom_unregister_event(struct cgroup_subsys_state *css, | 5884 | static void mem_cgroup_oom_unregister_event(struct mem_cgroup *memcg, |
5893 | struct eventfd_ctx *eventfd) | 5885 | struct eventfd_ctx *eventfd) |
5894 | { | 5886 | { |
5895 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | ||
5896 | struct mem_cgroup_eventfd_list *ev, *tmp; | 5887 | struct mem_cgroup_eventfd_list *ev, *tmp; |
5897 | 5888 | ||
5898 | spin_lock(&memcg_oom_lock); | 5889 | spin_lock(&memcg_oom_lock); |
@@ -6019,18 +6010,18 @@ static void cgroup_event_remove(struct work_struct *work) | |||
6019 | { | 6010 | { |
6020 | struct cgroup_event *event = container_of(work, struct cgroup_event, | 6011 | struct cgroup_event *event = container_of(work, struct cgroup_event, |
6021 | remove); | 6012 | remove); |
6022 | struct cgroup_subsys_state *css = event->css; | 6013 | struct mem_cgroup *memcg = event->memcg; |
6023 | 6014 | ||
6024 | remove_wait_queue(event->wqh, &event->wait); | 6015 | remove_wait_queue(event->wqh, &event->wait); |
6025 | 6016 | ||
6026 | event->unregister_event(css, event->eventfd); | 6017 | event->unregister_event(memcg, event->eventfd); |
6027 | 6018 | ||
6028 | /* Notify userspace the event is going away. */ | 6019 | /* Notify userspace the event is going away. */ |
6029 | eventfd_signal(event->eventfd, 1); | 6020 | eventfd_signal(event->eventfd, 1); |
6030 | 6021 | ||
6031 | eventfd_ctx_put(event->eventfd); | 6022 | eventfd_ctx_put(event->eventfd); |
6032 | kfree(event); | 6023 | kfree(event); |
6033 | css_put(css); | 6024 | css_put(&memcg->css); |
6034 | } | 6025 | } |
6035 | 6026 | ||
6036 | /* | 6027 | /* |
@@ -6043,7 +6034,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode, | |||
6043 | { | 6034 | { |
6044 | struct cgroup_event *event = container_of(wait, | 6035 | struct cgroup_event *event = container_of(wait, |
6045 | struct cgroup_event, wait); | 6036 | struct cgroup_event, wait); |
6046 | struct mem_cgroup *memcg = mem_cgroup_from_css(event->css); | 6037 | struct mem_cgroup *memcg = event->memcg; |
6047 | unsigned long flags = (unsigned long)key; | 6038 | unsigned long flags = (unsigned long)key; |
6048 | 6039 | ||
6049 | if (flags & POLLHUP) { | 6040 | if (flags & POLLHUP) { |
@@ -6114,7 +6105,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css, | |||
6114 | if (!event) | 6105 | if (!event) |
6115 | return -ENOMEM; | 6106 | return -ENOMEM; |
6116 | 6107 | ||
6117 | event->css = css; | 6108 | event->memcg = memcg; |
6118 | INIT_LIST_HEAD(&event->list); | 6109 | INIT_LIST_HEAD(&event->list); |
6119 | init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); | 6110 | init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); |
6120 | init_waitqueue_func_entry(&event->wait, cgroup_event_wake); | 6111 | init_waitqueue_func_entry(&event->wait, cgroup_event_wake); |
@@ -6186,7 +6177,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css, | |||
6186 | if (ret) | 6177 | if (ret) |
6187 | goto out_put_cfile; | 6178 | goto out_put_cfile; |
6188 | 6179 | ||
6189 | ret = event->register_event(css, event->eventfd, buffer); | 6180 | ret = event->register_event(memcg, event->eventfd, buffer); |
6190 | if (ret) | 6181 | if (ret) |
6191 | goto out_put_css; | 6182 | goto out_put_css; |
6192 | 6183 | ||
diff --git a/mm/vmpressure.c b/mm/vmpressure.c index 0f25a996d150..196970a4541f 100644 --- a/mm/vmpressure.c +++ b/mm/vmpressure.c | |||
@@ -278,7 +278,7 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio) | |||
278 | 278 | ||
279 | /** | 279 | /** |
280 | * vmpressure_register_event() - Bind vmpressure notifications to an eventfd | 280 | * vmpressure_register_event() - Bind vmpressure notifications to an eventfd |
281 | * @css: css that is interested in vmpressure notifications | 281 | * @memcg: memcg that is interested in vmpressure notifications |
282 | * @eventfd: eventfd context to link notifications with | 282 | * @eventfd: eventfd context to link notifications with |
283 | * @args: event arguments (used to set up a pressure level threshold) | 283 | * @args: event arguments (used to set up a pressure level threshold) |
284 | * | 284 | * |
@@ -290,10 +290,10 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio) | |||
290 | * | 290 | * |
291 | * To be used as memcg event method. | 291 | * To be used as memcg event method. |
292 | */ | 292 | */ |
293 | int vmpressure_register_event(struct cgroup_subsys_state *css, | 293 | int vmpressure_register_event(struct mem_cgroup *memcg, |
294 | struct eventfd_ctx *eventfd, const char *args) | 294 | struct eventfd_ctx *eventfd, const char *args) |
295 | { | 295 | { |
296 | struct vmpressure *vmpr = css_to_vmpressure(css); | 296 | struct vmpressure *vmpr = memcg_to_vmpressure(memcg); |
297 | struct vmpressure_event *ev; | 297 | struct vmpressure_event *ev; |
298 | int level; | 298 | int level; |
299 | 299 | ||
@@ -321,7 +321,7 @@ int vmpressure_register_event(struct cgroup_subsys_state *css, | |||
321 | 321 | ||
322 | /** | 322 | /** |
323 | * vmpressure_unregister_event() - Unbind eventfd from vmpressure | 323 | * vmpressure_unregister_event() - Unbind eventfd from vmpressure |
324 | * @css: css handle | 324 | * @memcg: memcg handle |
325 | * @eventfd: eventfd context that was used to link vmpressure with the @cg | 325 | * @eventfd: eventfd context that was used to link vmpressure with the @cg |
326 | * | 326 | * |
327 | * This function does internal manipulations to detach the @eventfd from | 327 | * This function does internal manipulations to detach the @eventfd from |
@@ -330,10 +330,10 @@ int vmpressure_register_event(struct cgroup_subsys_state *css, | |||
330 | * | 330 | * |
331 | * To be used as memcg event method. | 331 | * To be used as memcg event method. |
332 | */ | 332 | */ |
333 | void vmpressure_unregister_event(struct cgroup_subsys_state *css, | 333 | void vmpressure_unregister_event(struct mem_cgroup *memcg, |
334 | struct eventfd_ctx *eventfd) | 334 | struct eventfd_ctx *eventfd) |
335 | { | 335 | { |
336 | struct vmpressure *vmpr = css_to_vmpressure(css); | 336 | struct vmpressure *vmpr = memcg_to_vmpressure(memcg); |
337 | struct vmpressure_event *ev; | 337 | struct vmpressure_event *ev; |
338 | 338 | ||
339 | mutex_lock(&vmpr->events_lock); | 339 | mutex_lock(&vmpr->events_lock); |