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>
This commit is contained in:
Tejun Heo 2013-11-22 18:20:43 -05:00
parent 347c4a8747
commit 59b6f87344
3 changed files with 30 additions and 40 deletions

View file

@ -34,11 +34,10 @@ extern void vmpressure_init(struct vmpressure *vmpr);
extern void vmpressure_cleanup(struct vmpressure *vmpr); extern void vmpressure_cleanup(struct vmpressure *vmpr);
extern struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg); 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 int vmpressure_register_event(struct mem_cgroup *memcg,
extern int vmpressure_register_event(struct cgroup_subsys_state *css,
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 mem_cgroup *memcg,
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,

View file

@ -233,9 +233,9 @@ struct mem_cgroup_eventfd_list {
*/ */
struct cgroup_event { struct cgroup_event {
/* /*
* css which the event belongs to. * memcg which the event belongs to.
*/ */
struct cgroup_subsys_state *css; struct mem_cgroup *memcg;
/* /*
* eventfd to signal userspace about the event. * eventfd to signal userspace about the event.
*/ */
@ -249,14 +249,14 @@ struct cgroup_event {
* waiter for changes related to this event. Use eventfd_signal() * waiter for changes related to this event. Use eventfd_signal()
* 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 mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args); struct eventfd_ctx *eventfd, 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 mem_cgroup *memcg,
struct eventfd_ctx *eventfd); struct eventfd_ctx *eventfd);
/* /*
* All fields below needed to unregister event when * All fields below needed to unregister event when
@ -535,11 +535,6 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
return &container_of(vmpr, struct mem_cgroup, vmpressure)->css; return &container_of(vmpr, struct mem_cgroup, vmpressure)->css;
} }
struct vmpressure *css_to_vmpressure(struct cgroup_subsys_state *css)
{
return &mem_cgroup_from_css(css)->vmpressure;
}
static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg) static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
{ {
return (memcg == root_mem_cgroup); return (memcg == root_mem_cgroup);
@ -5682,10 +5677,9 @@ 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 mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args, enum res_type type) struct eventfd_ctx *eventfd, const char *args, enum res_type type)
{ {
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;
u64 threshold, usage; u64 threshold, usage;
@ -5764,22 +5758,21 @@ static int __mem_cgroup_usage_register_event(struct cgroup_subsys_state *css,
return ret; return ret;
} }
static int mem_cgroup_usage_register_event(struct cgroup_subsys_state *css, static int mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args) struct eventfd_ctx *eventfd, const char *args)
{ {
return __mem_cgroup_usage_register_event(css, eventfd, args, _MEM); return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEM);
} }
static int memsw_cgroup_usage_register_event(struct cgroup_subsys_state *css, static int memsw_cgroup_usage_register_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args) struct eventfd_ctx *eventfd, const char *args)
{ {
return __mem_cgroup_usage_register_event(css, eventfd, args, _MEMSWAP); return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEMSWAP);
} }
static void __mem_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd, enum res_type type) struct eventfd_ctx *eventfd, enum res_type type)
{ {
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;
u64 usage; u64 usage;
@ -5854,22 +5847,21 @@ 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, static void mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
return __mem_cgroup_usage_unregister_event(css, eventfd, _MEM); return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEM);
} }
static void memsw_cgroup_usage_unregister_event(struct cgroup_subsys_state *css, static void memsw_cgroup_usage_unregister_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
return __mem_cgroup_usage_unregister_event(css, eventfd, _MEMSWAP); return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEMSWAP);
} }
static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css, static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg,
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_eventfd_list *event; struct mem_cgroup_eventfd_list *event;
event = kmalloc(sizeof(*event), GFP_KERNEL); event = kmalloc(sizeof(*event), GFP_KERNEL);
@ -5889,10 +5881,9 @@ static int mem_cgroup_oom_register_event(struct cgroup_subsys_state *css,
return 0; return 0;
} }
static void mem_cgroup_oom_unregister_event(struct cgroup_subsys_state *css, static void mem_cgroup_oom_unregister_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
struct mem_cgroup_eventfd_list *ev, *tmp; struct mem_cgroup_eventfd_list *ev, *tmp;
spin_lock(&memcg_oom_lock); spin_lock(&memcg_oom_lock);
@ -6019,18 +6010,18 @@ static void cgroup_event_remove(struct work_struct *work)
{ {
struct cgroup_event *event = container_of(work, struct cgroup_event, struct cgroup_event *event = container_of(work, struct cgroup_event,
remove); remove);
struct cgroup_subsys_state *css = event->css; struct mem_cgroup *memcg = event->memcg;
remove_wait_queue(event->wqh, &event->wait); remove_wait_queue(event->wqh, &event->wait);
event->unregister_event(css, event->eventfd); event->unregister_event(memcg, 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);
eventfd_ctx_put(event->eventfd); eventfd_ctx_put(event->eventfd);
kfree(event); kfree(event);
css_put(css); css_put(&memcg->css);
} }
/* /*
@ -6043,7 +6034,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
{ {
struct cgroup_event *event = container_of(wait, struct cgroup_event *event = container_of(wait,
struct cgroup_event, wait); struct cgroup_event, wait);
struct mem_cgroup *memcg = mem_cgroup_from_css(event->css); struct mem_cgroup *memcg = event->memcg;
unsigned long flags = (unsigned long)key; unsigned long flags = (unsigned long)key;
if (flags & POLLHUP) { if (flags & POLLHUP) {
@ -6114,7 +6105,7 @@ static int cgroup_write_event_control(struct cgroup_subsys_state *css,
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
event->css = css; event->memcg = memcg;
INIT_LIST_HEAD(&event->list); INIT_LIST_HEAD(&event->list);
init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc); init_poll_funcptr(&event->pt, cgroup_event_ptable_queue_proc);
init_waitqueue_func_entry(&event->wait, cgroup_event_wake); init_waitqueue_func_entry(&event->wait, cgroup_event_wake);
@ -6186,7 +6177,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->eventfd, buffer); ret = event->register_event(memcg, event->eventfd, buffer);
if (ret) if (ret)
goto out_put_css; goto out_put_css;

View file

@ -278,7 +278,7 @@ 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 * @memcg: memcg that is interested in vmpressure notifications
* @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)
* *
@ -290,10 +290,10 @@ void vmpressure_prio(gfp_t gfp, struct mem_cgroup *memcg, int prio)
* *
* To be used as memcg event method. * To be used as memcg event method.
*/ */
int vmpressure_register_event(struct cgroup_subsys_state *css, int vmpressure_register_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd, const char *args) struct eventfd_ctx *eventfd, const char *args)
{ {
struct vmpressure *vmpr = css_to_vmpressure(css); struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
struct vmpressure_event *ev; struct vmpressure_event *ev;
int level; int level;
@ -321,7 +321,7 @@ 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 * @memcg: memcg 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
@ -330,10 +330,10 @@ int vmpressure_register_event(struct cgroup_subsys_state *css,
* *
* To be used as memcg event method. * To be used as memcg event method.
*/ */
void vmpressure_unregister_event(struct cgroup_subsys_state *css, void vmpressure_unregister_event(struct mem_cgroup *memcg,
struct eventfd_ctx *eventfd) struct eventfd_ctx *eventfd)
{ {
struct vmpressure *vmpr = css_to_vmpressure(css); struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
struct vmpressure_event *ev; struct vmpressure_event *ev;
mutex_lock(&vmpr->events_lock); mutex_lock(&vmpr->events_lock);