Re: [PATCH 1/2] memcg: res counter set limit

From: Balbir Singh
Date: Mon Jun 16 2008 - 23:40:54 EST


KAMEZAWA Hiroyuki wrote:
> Helper function of res_counter for reducing usage in subsys(memcg).
>
> Changelog xxx -> v5.
> - new file.
>
> Background:
> In v3, I was asked to implement generic ones to res_counter.
> In v4. I was asked not to implement generic ones because memcg is only
> controller which can reduce usage by the kernel. Okay, maybe make sense.
> In this version, adds only necessary helpers to res_counter in
> not-invasive manner.
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
>
> ---
> include/linux/res_counter.h | 7 +++++++
> kernel/res_counter.c | 24 ++++++++++++++++++++++++
> 2 files changed, 31 insertions(+)
>
> Index: mm-2.6.26-rc5-mm3/include/linux/res_counter.h
> ===================================================================
> --- mm-2.6.26-rc5-mm3.orig/include/linux/res_counter.h
> +++ mm-2.6.26-rc5-mm3/include/linux/res_counter.h
> @@ -136,6 +136,12 @@ static inline bool res_counter_check_und
> return ret;
> }
>
> +/*
> + * set new limit to the val. if usage > val, returns -EBUSY.
> + * returns 0 at success.
> + */
> +int res_counter_set_limit(struct res_counter *cnt, unsigned long long limit);
> +
> static inline void res_counter_reset_max(struct res_counter *cnt)
> {
> unsigned long flags;
> @@ -153,4 +159,5 @@ static inline void res_counter_reset_fai
> cnt->failcnt = 0;
> spin_unlock_irqrestore(&cnt->lock, flags);
> }
> +

I don't understand this extra newline here

> #endif
> Index: mm-2.6.26-rc5-mm3/kernel/res_counter.c
> ===================================================================
> --- mm-2.6.26-rc5-mm3.orig/kernel/res_counter.c
> +++ mm-2.6.26-rc5-mm3/kernel/res_counter.c
> @@ -143,3 +143,27 @@ out_free:
> out:
> return ret;
> }
> +
> +
> +/**
> + * res_counter_set_limit - set limit of res_counter.
> + * @cnt: the res_counter
> + * @limit: the new limit
> + *
> + * Note that res_coutner_write() allows the same kind of operation.
> + * But this returns -EBUSY when new limit < usage. If you want strict control
> + * of limit, please use this.
> + */
> +int res_counter_set_limit(struct res_counter *cnt, unsigned long long limit)
> +{
> + unsigned long flags;
> + int ret = -EBUSY;
> +
> + spin_lock_irqsave(&cnt->lock, flags);
> + if (cnt->usage <= limit) {
> + cnt->limit = limit;
> + ret = 0;
> + }
> + spin_unlock_irqrestore(&cnt->lock, flags);
> + return ret;
> +}

Reviewed-by: Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx>

--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL
--
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/