Commit 347c4a87 authored by Tejun Heo's avatar Tejun Heo

memcg: remove cgroup_event->cft

The only use of cgroup_event->cft is distinguishing "usage_in_bytes"
and "memsw.usgae_in_bytes" for mem_cgroup_usage_[un]register_event(),
which can be done by adding an explicit argument to the function and
implementing two wrappers so that the two cases can be distinguished
from the function alone.

Remove cgroup_event->cft and the related code including
[un]register_events() methods.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
Acked-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.cz>
parent fba94807
...@@ -36,11 +36,9 @@ extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg); ...@@ -36,11 +36,9 @@ extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg);
extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr); extern struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr);
extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css); extern struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css);
extern int vmpressure_register_event(struct cgroup_subsys_state *css, extern int vmpressure_register_event(struct cgroup_subsys_state *css,
struct cftype *cft,
struct eventfd_ctx *eventfd, struct eventfd_ctx *eventfd,
const char *args); const char *args);
extern void vmpressure_unregister_event(struct cgroup_subsys_state *css, extern void vmpressure_unregister_event(struct cgroup_subsys_state *css,
struct cftype *cft,
struct eventfd_ctx *eventfd); struct eventfd_ctx *eventfd);
#else #else
static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, static inline void vmpressure(gfp_t gfp, struct mem_cgroup *memcg,
......
...@@ -236,10 +236,6 @@ struct cgroup_event { ...@@ -236,10 +236,6 @@ struct cgroup_event {
* css which the event belongs to. * css which the event belongs to.
*/ */
struct cgroup_subsys_state *css; struct cgroup_subsys_state *css;
/*
* Control file which the event associated.
*/
struct cftype *cft;
/* /*
* eventfd to signal userspace about the event. * eventfd to signal userspace about the event.
*/ */
...@@ -254,15 +250,13 @@ struct cgroup_event { ...@@ -254,15 +250,13 @@ struct cgroup_event {
* on eventfd to send notification to userspace. * on eventfd to send notification to userspace.
*/ */
int (*register_event)(struct cgroup_subsys_state *css, int (*register_event)(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd, struct eventfd_ctx *eventfd, const char *args);
const char *args);
/* /*
* unregister_event() callback will be called when userspace closes * unregister_event() callback will be called when userspace closes
* the eventfd or on cgroup removing. This callback must be set, * the eventfd or on cgroup removing. This callback must be set,
* if you want provide notification functionality. * if you want provide notification functionality.
*/ */
void (*unregister_event)(struct cgroup_subsys_state *css, void (*unregister_event)(struct cgroup_subsys_state *css,
struct cftype *cft,
struct eventfd_ctx *eventfd); struct eventfd_ctx *eventfd);
/* /*
* All fields below needed to unregister event when * All fields below needed to unregister event when
...@@ -5688,13 +5682,12 @@ static void mem_cgroup_oom_notify(struct mem_cgroup *memcg) ...@@ -5688,13 +5682,12 @@ static void mem_cgroup_oom_notify(struct mem_cgroup *memcg)
mem_cgroup_oom_notify_cb(iter); mem_cgroup_oom_notify_cb(iter);
} }
static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css, static int __mem_cgroup_usage_register_event(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd, const char *args) struct eventfd_ctx *eventfd, const char *args, enum res_type type)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
struct mem_cgroup_thresholds *thresholds; struct mem_cgroup_thresholds *thresholds;
struct mem_cgroup_threshold_ary *new; struct mem_cgroup_threshold_ary *new;
enum res_type type = MEMFILE_TYPE(cft->private);
u64 threshold, usage; u64 threshold, usage;
int i, size, ret; int i, size, ret;
...@@ -5771,13 +5764,24 @@ static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css, ...@@ -5771,13 +5764,24 @@ static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css,
return ret; return ret;
} }
static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd, const char *args)
{
return __mem_cgroup_usage_register_event(css, eventfd, args, _MEM);
}
static int memsw_cgroup_usage_register_event(struct cgroup_subsys_state *css,
struct eventfd_ctx *eventfd, const char *args)
{
return __mem_cgroup_usage_register_event(css, eventfd, args, _MEMSWAP);
}
static void __mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css,
struct eventfd_ctx *eventfd, enum res_type type)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
struct mem_cgroup_thresholds *thresholds; struct mem_cgroup_thresholds *thresholds;
struct mem_cgroup_threshold_ary *new; struct mem_cgroup_threshold_ary *new;
enum res_type type = MEMFILE_TYPE(cft->private);
u64 usage; u64 usage;
int i, j, size; int i, j, size;
...@@ -5850,14 +5854,24 @@ static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, ...@@ -5850,14 +5854,24 @@ static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css,
mutex_unlock(&memcg->thresholds_lock); mutex_unlock(&memcg->thresholds_lock);
} }
static void mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css,
struct eventfd_ctx *eventfd)
{
return __mem_cgroup_usage_unregister_event(css, eventfd, _MEM);
}
static void memsw_cgroup_usage_unregister_event(struct cgroup_subsys_state *css,
struct eventfd_ctx *eventfd)
{
return __mem_cgroup_usage_unregister_event(css, eventfd, _MEMSWAP);
}
static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css, static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd, const char *args) struct eventfd_ctx *eventfd, const char *args)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
struct mem_cgroup_eventfd_list *event; struct mem_cgroup_eventfd_list *event;
enum res_type type = MEMFILE_TYPE(cft->private);
BUG_ON(type != _OOM_TYPE);
event = kmalloc(sizeof(*event), GFP_KERNEL); event = kmalloc(sizeof(*event), GFP_KERNEL);
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
...@@ -5876,13 +5890,10 @@ static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css, ...@@ -5876,13 +5890,10 @@ static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css,
} }
static void mem_cgroup_oom_unregister_event(struct cgroup_subsys_state *css, static void mem_cgroup_oom_unregister_event(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
struct mem_cgroup_eventfd_list *ev, *tmp; struct mem_cgroup_eventfd_list *ev, *tmp;
enum res_type type = MEMFILE_TYPE(cft->private);
BUG_ON(type != _OOM_TYPE);
spin_lock(&memcg_oom_lock); spin_lock(&memcg_oom_lock);
...@@ -6012,7 +6023,7 @@ static void cgroup_event_remove(struct work_struct *work) ...@@ -6012,7 +6023,7 @@ static void cgroup_event_remove(struct work_struct *work)
remove_wait_queue(event->wqh, &event->wait); remove_wait_queue(event->wqh, &event->wait);
event->unregister_event(css, event->cft, event->eventfd); event->unregister_event(css, event->eventfd);
/* Notify userspace the event is going away. */ /* Notify userspace the event is going away. */
eventfd_signal(event->eventfd, 1); eventfd_signal(event->eventfd, 1);
...@@ -6133,12 +6144,6 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css, ...@@ -6133,12 +6144,6 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
if (ret < 0) if (ret < 0)
goto out_put_cfile; goto out_put_cfile;
event->cft = __file_cft(cfile.file);
if (IS_ERR(event->cft)) {
ret = PTR_ERR(event->cft);
goto out_put_cfile;
}
/* /*
* Determine the event callbacks and set them in @event. This used * Determine the event callbacks and set them in @event. This used
* to be done via struct cftype but cgroup core no longer knows * to be done via struct cftype but cgroup core no longer knows
...@@ -6157,8 +6162,8 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css, ...@@ -6157,8 +6162,8 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
event->register_event = vmpressure_register_event; event->register_event = vmpressure_register_event;
event->unregister_event = vmpressure_unregister_event; event->unregister_event = vmpressure_unregister_event;
} else if (!strcmp(name, "memory.memsw.usage_in_bytes")) { } else if (!strcmp(name, "memory.memsw.usage_in_bytes")) {
event->register_event = mem_cgroup_usage_register_event; event->register_event = memsw_cgroup_usage_register_event;
event->unregister_event = mem_cgroup_usage_unregister_event; event->unregister_event = memsw_cgroup_usage_unregister_event;
} else { } else {
ret = -EINVAL; ret = -EINVAL;
goto out_put_cfile; goto out_put_cfile;
...@@ -6181,7 +6186,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css, ...@@ -6181,7 +6186,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
if (ret) if (ret)
goto out_put_cfile; goto out_put_cfile;
ret = event->register_event(css, event->cft, event->eventfd, buffer); ret = event->register_event(css, event->eventfd, buffer);
if (ret) if (ret)
goto out_put_css; goto out_put_css;
......
...@@ -279,7 +279,6 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio) ...@@ -279,7 +279,6 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
/** /**
* vmpressure_register_event() - Bind vmpressure notifications to an eventfd * vmpressure_register_event() - Bind vmpressure notifications to an eventfd
* @css: css that is interested in vmpressure notifications * @css: css that is interested in vmpressure notifications
* @cft: cgroup control files handle
* @eventfd: eventfd context to link notifications with * @eventfd: eventfd context to link notifications with
* @args: event arguments (used to set up a pressure level threshold) * @args: event arguments (used to set up a pressure level threshold)
* *
...@@ -289,13 +288,10 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio) ...@@ -289,13 +288,10 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
* threshold (one of vmpressure_str_levels, i.e. "low", "medium", or * threshold (one of vmpressure_str_levels, i.e. "low", "medium", or
* "critical"). * "critical").
* *
* This function should not be used directly, just pass it to (struct * To be used as memcg event method.
* cftype).register_event, and then cgroup core will handle everything by
* itself.
*/ */
int vmpressure_register_event(struct cgroup_subsys_state *css, int vmpressure_register_event(struct cgroup_subsys_state *css,
struct cftype *cft, struct eventfd_ctx *eventfd, struct eventfd_ctx *eventfd, const char *args)
const char *args)
{ {
struct vmpressure *vmpr = css_to_vmpressure(css); struct vmpressure *vmpr = css_to_vmpressure(css);
struct vmpressure_event *ev; struct vmpressure_event *ev;
...@@ -326,19 +322,15 @@ int vmpressure_register_event(struct cgroup_subsys_state *css, ...@@ -326,19 +322,15 @@ int vmpressure_register_event(struct cgroup_subsys_state *css,
/** /**
* vmpressure_unregister_event() - Unbind eventfd from vmpressure * vmpressure_unregister_event() - Unbind eventfd from vmpressure
* @css: css handle * @css: css handle
* @cft: cgroup control files handle
* @eventfd: eventfd context that was used to link vmpressure with the @cg * @eventfd: eventfd context that was used to link vmpressure with the @cg
* *
* This function does internal manipulations to detach the @eventfd from * This function does internal manipulations to detach the @eventfd from
* the vmpressure notifications, and then frees internal resources * the vmpressure notifications, and then frees internal resources
* associated with the @eventfd (but the @eventfd itself is not freed). * associated with the @eventfd (but the @eventfd itself is not freed).
* *
* This function should not be used directly, just pass it to (struct * To be used as memcg event method.
* cftype).unregister_event, and then cgroup core will handle everything
* by itself.
*/ */
void vmpressure_unregister_event(struct cgroup_subsys_state *css, void vmpressure_unregister_event(struct cgroup_subsys_state *css,
struct cftype *cft,
struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
struct vmpressure *vmpr = css_to_vmpressure(css); struct vmpressure *vmpr = css_to_vmpressure(css);
......
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