Re: [RFC][PATCH 2/3] memcg: oom notifier

From: KAMEZAWA Hiroyuki
Date: Thu Mar 11 2010 - 18:58:21 EST


Thank you.

On Thu, 11 Mar 2010 16:47:00 +0200
"Kirill A. Shutemov" <kirill@xxxxxxxxxxxxx> wrote:

> On Thu, Mar 11, 2010 at 9:57 AM, KAMEZAWA Hiroyuki
> <kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> > From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>

> > Â Â Â Â/*
> > Â Â Â Â * Should we move charges of a task when a task is moved into this
> > Â Â Â Â * mem_cgroup ? And what type of charges should we move ?
> > @@ -282,9 +292,12 @@ enum charge_type {
> > Â/* for encoding cft->private value on file */
> > Â#define _MEM Â Â Â Â Â Â Â Â Â (0)
> > Â#define _MEMSWAP Â Â Â Â Â Â Â (1)
> > +#define _OOM_TYPE Â Â Â Â Â Â Â(2)
> > Â#define MEMFILE_PRIVATE(x, val) Â Â Â Â(((x) << 16) | (val))
> > Â#define MEMFILE_TYPE(val) Â Â Â(((val) >> 16) & 0xffff)
> > Â#define MEMFILE_ATTR(val) Â Â Â((val) & 0xffff)
> > +/* Used for OOM nofiier */
> > +#define OOM_CONTROL Â Â Â Â Â Â(0)
> >
> > Â/*
> > Â* Reclaim flags for mem_cgroup_hierarchical_reclaim
> > @@ -1351,6 +1364,8 @@ bool mem_cgroup_handle_oom(struct mem_cg
> > Â Â Â Â */
> > Â Â Â Âif (!locked)
> > Â Â Â Â Â Â Â Âprepare_to_wait(&memcg_oom_waitq, &owait.wait, TASK_KILLABLE);
> > + Â Â Â else
> > + Â Â Â Â Â Â Â mem_cgroup_oom_notify(mem);
> > Â Â Â Âmutex_unlock(&memcg_oom_mutex);
> >
> > Â Â Â Âif (locked)
> > @@ -3398,8 +3413,22 @@ static int compare_thresholds(const void
> > Â Â Â Âreturn _a->threshold - _b->threshold;
> > Â}
> >
> > -static int mem_cgroup_register_event(struct cgroup *cgrp, struct cftype *cft,
> > - Â Â Â Â Â Â Â struct eventfd_ctx *eventfd, const char *args)
> > +static int mem_cgroup_oom_notify_cb(struct mem_cgroup *mem, void *data)
> > +{
> > + Â Â Â struct mem_cgroup_eventfd_list *ev;
> > +
> > + Â Â Â list_for_each_entry(ev, &mem->oom_notify, list)
> > + Â Â Â Â Â Â Â eventfd_signal(ev->eventfd, 1);
> > + Â Â Â return 0;
> > +}
> > +
> > +static void mem_cgroup_oom_notify(struct mem_cgroup *mem)
> > +{
> > + Â Â Â mem_cgroup_walk_tree(mem, NULL, mem_cgroup_oom_notify_cb);
> > +}
> > +
> > +static int mem_cgroup_usage_register_event(struct cgroup *cgrp,
> > + Â Â Â struct cftype *cft, struct eventfd_ctx *eventfd, const char *args)
> > Â{
> > Â Â Â Âstruct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > Â Â Â Âstruct mem_cgroup_threshold_ary *thresholds, *thresholds_new;
> > @@ -3483,8 +3512,8 @@ unlock:
> > Â Â Â Âreturn ret;
> > Â}
> >
> > -static int mem_cgroup_unregister_event(struct cgroup *cgrp, struct cftype *cft,
> > - Â Â Â Â Â Â Â struct eventfd_ctx *eventfd)
> > +static int mem_cgroup_usage_unregister_event(struct cgroup *cgrp,
> > + Â Â Â struct cftype *cft, struct eventfd_ctx *eventfd)
> > Â{
> > Â Â Â Âstruct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > Â Â Â Âstruct mem_cgroup_threshold_ary *thresholds, *thresholds_new;
> > @@ -3568,13 +3597,66 @@ unlock:
> > Â Â Â Âreturn ret;
> > Â}
> >
> > +static int mem_cgroup_oom_register_event(struct cgroup *cgrp,
> > + Â Â Â struct cftype *cft, struct eventfd_ctx *eventfd, const char *args)
> > +{
> > + Â Â Â struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > + Â Â Â struct mem_cgroup_eventfd_list *event;
> > + Â Â Â int type = MEMFILE_TYPE(cft->private);
> > + Â Â Â int ret = -ENOMEM;
> > +
> > + Â Â Â BUG_ON(type != _OOM_TYPE);
> > +
> > + Â Â Â mutex_lock(&memcg_oom_mutex);
> > +
> > + Â Â Â /* Allocate memory for new array of thresholds */
>
> Irrelevant comment?
>
> > + Â Â Â event = kmalloc(sizeof(*event), GFP_KERNEL);
> > + Â Â Â if (!event)
> > + Â Â Â Â Â Â Â goto unlock;
> > + Â Â Â /* Add new threshold */
>
> Ditto.
>
Ah...sorry for garbages..I'll clean these up.

Thanks,
-Kame

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/