[Devel] Re: [PATCH -mmotm 1/2] memcg: dirty pages accounting and limiting infrastructure
Andrea Righi
arighi at develer.com
Mon Mar 1 02:39:47 PST 2010
On Mon, Mar 01, 2010 at 10:58:35AM +0200, Kirill A. Shutemov wrote:
[snip]
> > +static u64 mem_cgroup_dirty_ratio_read(struct cgroup *cgrp, struct cftype *cft)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + return get_dirty_param(memcg, MEM_CGROUP_DIRTY_RATIO);
> > +}
> > +
> > +static int
> > +mem_cgroup_dirty_ratio_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + if ((cgrp->parent == NULL) || (val > 100))
> > + return -EINVAL;
> > +
> > + spin_lock(&memcg->reclaim_param_lock);
> > + memcg->dirty_ratio = val;
> > + memcg->dirty_bytes = 0;
> > + spin_unlock(&memcg->reclaim_param_lock);
> > +
> > + return 0;
> > +}
> > +
> > +static u64 mem_cgroup_dirty_bytes_read(struct cgroup *cgrp, struct cftype *cft)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BYTES);
> > +}
> > +
> > +static int
> > +mem_cgroup_dirty_bytes_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + if (cgrp->parent == NULL)
> > + return -EINVAL;
> > +
> > + spin_lock(&memcg->reclaim_param_lock);
> > + memcg->dirty_ratio = 0;
> > + memcg->dirty_bytes = val;
> > + spin_unlock(&memcg->reclaim_param_lock);
> > +
> > + return 0;
> > +}
> > +
> > +static u64
> > +mem_cgroup_dirty_background_ratio_read(struct cgroup *cgrp, struct cftype *cft)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_RATIO);
> > +}
> > +
> > +static int mem_cgroup_dirty_background_ratio_write(struct cgroup *cgrp,
> > + struct cftype *cft, u64 val)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + if ((cgrp->parent == NULL) || (val > 100))
> > + return -EINVAL;
> > +
> > + spin_lock(&memcg->reclaim_param_lock);
> > + memcg->dirty_background_ratio = val;
> > + memcg->dirty_background_bytes = 0;
> > + spin_unlock(&memcg->reclaim_param_lock);
> > +
> > + return 0;
> > +}
> > +
> > +static u64
> > +mem_cgroup_dirty_background_bytes_read(struct cgroup *cgrp, struct cftype *cft)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + return get_dirty_param(memcg, MEM_CGROUP_DIRTY_BACKGROUND_BYTES);
> > +}
> > +
> > +static int mem_cgroup_dirty_background_bytes_write(struct cgroup *cgrp,
> > + struct cftype *cft, u64 val)
> > +{
> > + struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
> > +
> > + if (cgrp->parent == NULL)
> > + return -EINVAL;
> > +
> > + spin_lock(&memcg->reclaim_param_lock);
> > + memcg->dirty_background_ratio = 0;
> > + memcg->dirty_background_bytes = val;
> > + spin_unlock(&memcg->reclaim_param_lock);
> > +
> > + return 0;
> > +}
> > +
> > static struct cftype mem_cgroup_files[] = {
> > {
> > .name = "usage_in_bytes",
> > @@ -3518,6 +3785,26 @@ static struct cftype mem_cgroup_files[] = {
> > .write_u64 = mem_cgroup_swappiness_write,
> > },
> > {
> > + .name = "dirty_ratio",
> > + .read_u64 = mem_cgroup_dirty_ratio_read,
> > + .write_u64 = mem_cgroup_dirty_ratio_write,
> > + },
> > + {
> > + .name = "dirty_bytes",
> > + .read_u64 = mem_cgroup_dirty_bytes_read,
> > + .write_u64 = mem_cgroup_dirty_bytes_write,
> > + },
> > + {
> > + .name = "dirty_background_ratio",
> > + .read_u64 = mem_cgroup_dirty_background_ratio_read,
> > + .write_u64 = mem_cgroup_dirty_background_ratio_write,
> > + },
> > + {
> > + .name = "dirty_background_bytes",
> > + .read_u64 = mem_cgroup_dirty_background_bytes_read,
> > + .write_u64 = mem_cgroup_dirty_background_bytes_write,
> > + },
> > + {
>
> mem_cgroup_dirty_background_* functions are too similar to
> mem_cgroup_dirty_bytes_*. I think they should be combined
> like mem_cgroup_read() and mem_cgroup_write(). It will be
> cleaner.
Agreed.
Thanks,
-Andrea
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
More information about the Devel
mailing list