Re: [RFC][PATCH 5/6] memcg: mem+swap controller

From: Daisuke Nishimura
Date: Fri Nov 07 2008 - 08:34:54 EST


> > > static struct cftype mem_cgroup_files[] = {
> > > {
> > > .name = "usage_in_bytes",
> > > - .private = RES_USAGE,
> > > + .private = MEMFILE_PRIVATE(_MEM, RES_USAGE),
> > > .read_u64 = mem_cgroup_read,
> > > },
> > > {
> > > .name = "max_usage_in_bytes",
> > > - .private = RES_MAX_USAGE,
> > > + .private = MEMFILE_PRIVATE(_MEM, RES_MAX_USAGE),
> > > .trigger = mem_cgroup_reset,
> > > .read_u64 = mem_cgroup_read,
> > > },
> > > {
> > > .name = "limit_in_bytes",
> > > - .private = RES_LIMIT,
> > > + .private = MEMFILE_PRIVATE(_MEM, RES_LIMIT),
> > > .write_string = mem_cgroup_write,
> > > .read_u64 = mem_cgroup_read,
> > > },
> > > {
> > > .name = "failcnt",
> > > - .private = RES_FAILCNT,
> > > + .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT),
> > > .trigger = mem_cgroup_reset,
> > > .read_u64 = mem_cgroup_read,
> > > },
> > > @@ -1317,6 +1541,31 @@ static struct cftype mem_cgroup_files[]
> > > .name = "stat",
> > > .read_map = mem_control_stat_show,
> > > },
> > > +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
> > > + {
> > > + .name = "memsw.usage_in_bytes",
> > > + .private = MEMFILE_PRIVATE(_MEMSWAP, RES_USAGE),
> > > + .read_u64 = mem_cgroup_read,
> > > + },
> > > + {
> > > + .name = "memsw.max_usage_in_bytes",
> > > + .private = MEMFILE_PRIVATE(_MEMSWAP, RES_MAX_USAGE),
> > > + .trigger = mem_cgroup_reset,
> > > + .read_u64 = mem_cgroup_read,
> > > + },
> > > + {
> > > + .name = "memsw.limit_in_bytes",
> > > + .private = MEMFILE_PRIVATE(_MEMSWAP, RES_LIMIT),
> > > + .write_string = mem_cgroup_write,
> > > + .read_u64 = mem_cgroup_read,
> > > + },
> > > + {
> > > + .name = "memsw.failcnt",
> > > + .private = MEMFILE_PRIVATE(_MEMSWAP, RES_FAILCNT),
> > > + .trigger = mem_cgroup_reset,
> > > + .read_u64 = mem_cgroup_read,
> > > + },
> > > +#endif
> > > };
> > >
> > IMHO, it would be better to define those "memsw.*" files as memsw_cgroup_files[],
> > and change mem_cgroup_populate() like:
> >
> > static int mem_cgroup_populate(struct cgroup_subsys *ss,
> > struct cgroup *cont)
> > {
> > int ret;
> >
> > ret = cgroup_add_files(cont, ss, mem_cgroup_files,
> > ARRAY_SIZE(mem_cgroup_files));
> > if (!ret && do_swap_account)
> > ret = cgroup_add_files(cont, ss, memsw_cgroup_files,
> > ARRAY_SIZE(memsw_cgroup_files));
> >
> > return ret;
> > }
> >
> > so that those files appear only when swap accounting is enabled.
> >
>
> Nice idea. I'll try that.
>
I made a patch for this.

please merge this if it looks good to you.

I've confirmed that memsw.* files doesn't created with noswapaccount,
and this can be compiled with !CONFIG_CGROUP_MEM_RES_CTLR_SWAP.


Signed-off-by: Daisuke Nishimura <nishimura@xxxxxxxxxxxxxxxxx>
---
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 27f1772..03dfc46 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1542,6 +1542,9 @@ static struct cftype mem_cgroup_files[] = {
.name = "stat",
.read_map = mem_control_stat_show,
},
+};
+
+static struct cftype swap_cgroup_files[] = {
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
{
.name = "memsw.usage_in_bytes",
@@ -1724,8 +1727,14 @@ static void mem_cgroup_destroy(struct cgroup_subsys *ss,
static int mem_cgroup_populate(struct cgroup_subsys *ss,
struct cgroup *cont)
{
- return cgroup_add_files(cont, ss, mem_cgroup_files,
+ int ret;
+ ret = cgroup_add_files(cont, ss, mem_cgroup_files,
ARRAY_SIZE(mem_cgroup_files));
+ if (!ret && do_swap_account)
+ ret = cgroup_add_files(cont, ss, swap_cgroup_files,
+ ARRAY_SIZE(swap_cgroup_files));
+
+ return ret;
}

static void mem_cgroup_move_task(struct cgroup_subsys *ss,
--
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/