From: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
To: KAMEZAWA Hiroyuki
<kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
Cc: "containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org"
<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
"yamamoto-jCdQPDEk3idL9jVzuh4AOg@public.gmane.org"
<yamamoto-jCdQPDEk3idL9jVzuh4AOg@public.gmane.org>,
menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
"balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org"
<balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: Re: [RFC][ only for review ] memory controller bacground reclaim [3/5] high/low watermark support in res_counter
Date: Wed, 28 Nov 2007 14:12:53 +0300 [thread overview]
Message-ID: <474D4D35.9060603@openvz.org> (raw)
In-Reply-To: <20071128175408.1ee479f3.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
KAMEZAWA Hiroyuki wrote:
> This patch adds high/low watermark parameter to res_counter.
> splitted out from YAMAMOTO's background page reclaim for memory cgroup set.
>
> Changes:
> * added param watermark_state this allows status check without lock.
>
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
> From: YAMAMOTO Takashi <yamamoto-jCdQPDEk3idL9jVzuh4AOg@public.gmane.org>
>
> include/linux/res_counter.h | 27 +++++++++++++++++++++++++
> kernel/res_counter.c | 46 +++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 72 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.24-rc3-mm1/include/linux/res_counter.h
> ===================================================================
> --- linux-2.6.24-rc3-mm1.orig/include/linux/res_counter.h 2007-11-28 14:33:19.000000000 +0900
> +++ linux-2.6.24-rc3-mm1/include/linux/res_counter.h 2007-11-28 16:37:32.000000000 +0900
> @@ -19,6 +19,12 @@
> * the helpers described beyond
> */
>
> +enum watermark_state {
> + RES_WATERMARK_BELOW_LOW,
> + RES_WATERMARK_ABOVE_LOW,
> + RES_WATERMARK_ABOVE_HIGH,
> +};
> +
> struct res_counter {
> /*
> * the current resource consumption level
> @@ -33,10 +39,19 @@
> */
> unsigned long long failcnt;
> /*
> + * Watermarks
> + * Should be changed automatically when the limit is changed and
> + * keep low < high < limit.
> + */
> + unsigned long long high_watermark;
> + unsigned long long low_watermark;
> + /*
> * the lock to protect all of the above.
> * the routines below consider this to be IRQ-safe
> */
> spinlock_t lock;
> + /* can be read without lock */
> + enum watermark_state watermark_state;
> };
>
> /*
> @@ -73,6 +88,8 @@
> RES_USAGE,
> RES_LIMIT,
> RES_FAILCNT,
> + RES_HIGH_WATERMARK,
> + RES_LOW_WATERMARK,
I'd prefer some shorter names. Like RES_HWMARK and RES_LWMARK.
> };
>
> /*
> @@ -131,4 +148,17 @@
> return ret;
> }
>
> +/*
> + * Helper function for implementing high/low watermark to resource controller.
> + */
> +static inline bool res_counter_below_low_watermark(struct res_counter *cnt)
> +{
> + return (cnt->watermark_state == RES_WATERMARK_BELOW_LOW);
> +}
> +
> +static inline bool res_counter_above_high_watermark(struct res_counter *cnt)
> +{
> + return (cnt->watermark_state == RES_WATERMARK_ABOVE_HIGH);
> +}
> +
> #endif
> Index: linux-2.6.24-rc3-mm1/kernel/res_counter.c
> ===================================================================
> --- linux-2.6.24-rc3-mm1.orig/kernel/res_counter.c 2007-11-28 14:33:19.000000000 +0900
> +++ linux-2.6.24-rc3-mm1/kernel/res_counter.c 2007-11-28 16:33:20.000000000 +0900
> @@ -17,6 +17,9 @@
> {
> spin_lock_init(&counter->lock);
> counter->limit = (unsigned long long)LLONG_MAX;
> + counter->low_watermark = (unsigned long long)LLONG_MAX;
> + counter->high_watermark = (unsigned long long)LLONG_MAX;
> + counter->watermark_state = RES_WATERMARK_BELOW_LOW;
> }
>
> int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
> @@ -27,6 +30,15 @@
> }
>
> counter->usage += val;
> +
> + if (counter->usage > counter->high_watermark) {
> + counter->watermark_state = RES_WATERMARK_ABOVE_HIGH;
> + return 0;
> + }
"else" would look much better here :)
> + if (counter->usage > counter->low_watermark)
> + counter->watermark_state = RES_WATERMARK_ABOVE_LOW;
> +
> return 0;
> }
>
> @@ -47,6 +59,13 @@
> val = counter->usage;
>
> counter->usage -= val;
> +
> + if (counter->usage < counter->low_watermark) {
> + counter->watermark_state = RES_WATERMARK_BELOW_LOW;
> + return;
> + }
and here
> + if (counter->usage < counter->high_watermark)
> + counter->watermark_state = RES_WATERMARK_ABOVE_LOW;
> }
>
> void res_counter_uncharge(struct res_counter *counter, unsigned long val)
> @@ -69,6 +88,10 @@
> return &counter->limit;
> case RES_FAILCNT:
> return &counter->failcnt;
> + case RES_HIGH_WATERMARK:
> + return &counter->high_watermark;
> + case RES_LOW_WATERMARK:
> + return &counter->low_watermark;
> };
>
> BUG();
> @@ -117,7 +140,7 @@
> {
> int ret;
> char *buf, *end;
> - unsigned long long flags, tmp, *val;
> + unsigned long long flags, tmp, *val, limit, low, high;
>
> buf = kmalloc(nbytes + 1, GFP_KERNEL);
> ret = -ENOMEM;
> @@ -141,6 +164,26 @@
> goto out_free;
> }
> spin_lock_irqsave(&counter->lock, flags);
> + /*
> + * High/Low watermark should be changed automatically AMAP.
> + */
> + switch (member) {
> + case RES_HIGH_WATERMARK:
> + limit = res_counter_get(counter, RES_LIMIT);
> + if (tmp > limit)
> + goto out_free;
> + low = res_counter_get(counter, RES_LOW_WATERMARK);
> + if (tmp <= low)
> + goto out_free;
> + break;
> + case RES_LOW_WATERMARK:
> + high= res_counter_get(counter, RES_HIGH_WATERMARK);
> + if (tmp >= high)
> + goto out_free;
> + break;
Why there's no checks for limit? Smth like
case RES_LIMIT:
high = res_counter_get(counter, RES_HIGH_WATERMARK);
if (tmp < high)
goto out_free;
> + default:
> + break;
> + }
> val = res_counter_member(counter, member);
> *val = tmp;
> spin_unlock_irqrestore(&counter->lock, flags);
> @@ -150,3 +193,4 @@
> out:
> return ret;
> }
> +
>
>
next prev parent reply other threads:[~2007-11-28 11:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-28 8:49 [RFC][ only for review ] memory controller bacground reclaim [0/5] KAMEZAWA Hiroyuki
[not found] ` <20071128174923.1f54f53f.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 8:51 ` [RFC][ only for review ] memory controller bacground reclaim [1/5] spinlock fix in res_counter modification KAMEZAWA Hiroyuki
[not found] ` <20071128175135.c42adecc.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 11:08 ` Pavel Emelyanov
[not found] ` <474D4C2F.8020701-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:14 ` KAMEZAWA Hiroyuki
2007-11-28 8:52 ` [RFC][ only for review ] memory controller bacground reclaim [2/5] set/get ops for res_counter KAMEZAWA Hiroyuki
[not found] ` <20071128175239.e20ec09d.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 11:09 ` Pavel Emelyanov
[not found] ` <474D4C66.2080303-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:16 ` KAMEZAWA Hiroyuki
2007-11-28 8:54 ` [RFC][ only for review ] memory controller bacground reclaim [3/5] high/low watermark support in res_counter KAMEZAWA Hiroyuki
[not found] ` <20071128175408.1ee479f3.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 11:12 ` Pavel Emelyanov [this message]
[not found] ` <474D4D35.9060603-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:18 ` KAMEZAWA Hiroyuki
2007-11-29 2:56 ` YAMAMOTO Takashi
[not found] ` <20071129025609.0B7111CFE7C-Pcsii4f/SVk@public.gmane.org>
2007-11-29 3:24 ` KAMEZAWA Hiroyuki
[not found] ` <20071129122402.101c5fbc.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-29 3:36 ` YAMAMOTO Takashi
2007-11-28 8:56 ` [RFC][ only for review ] memory controller bacground reclaim [4/5] high/low watermark for memory controller KAMEZAWA Hiroyuki
[not found] ` <20071128175607.37df2187.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 11:20 ` Pavel Emelyanov
[not found] ` <474D4F01.4070705-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:27 ` KAMEZAWA Hiroyuki
2007-11-28 12:20 ` Pavel Emelyanov
[not found] ` <474D5D1A.4070409-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:20 ` KAMEZAWA Hiroyuki
[not found] ` <20071129102044.8087386c.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-29 19:55 ` Oren Laadan
[not found] ` <474F194C.1000401-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2007-11-30 0:26 ` KAMEZAWA Hiroyuki
2007-12-01 7:09 ` Paul Menage
[not found] ` <6599ad830711302309p3a68828fjec6793bc9d854a1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-12-01 10:45 ` Balbir Singh
[not found] ` <47513B50.8090003-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-12-01 16:55 ` Paul Menage
[not found] ` <6599ad830712010855j7967ddeau1a558474de4eea19-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-12-01 17:16 ` Balbir Singh
2007-11-28 8:57 ` [RFC][ only for review ] memory controller bacground reclaim [5/5] KAMEZAWA Hiroyuki
[not found] ` <20071128175713.4e9b8fff.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-28 11:06 ` Pavel Emelyanov
[not found] ` <474D4BAE.7090407-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-11-29 1:26 ` KAMEZAWA Hiroyuki
2007-12-01 7:16 ` Paul Menage
2007-11-29 11:53 ` [RFC][ only for review ] memory controller bacground reclaim [0/5] (Does anyone have an idea about throttling ?) KAMEZAWA Hiroyuki
[not found] ` <20071129205324.f9e7ab4e.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2007-11-29 14:42 ` Balbir Singh
[not found] ` <474ECFEB.9090202-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-11-30 0:29 ` KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=474D4D35.9060603@openvz.org \
--to=xemul-gefaqzzx7r8dnm+yrofe0a@public.gmane.org \
--cc=balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=yamamoto-jCdQPDEk3idL9jVzuh4AOg@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox