All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kamezawa.hiroyu@jp.fujitsu.com, nishimura@mxp.nes.nec.co.jp,
	balbir@linux.vnet.ibm.com, minchan.kim@gmail.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [patch 2/3] memcg: prevent endless loop when charging huge pages to near-limit group
Date: Tue, 1 Feb 2011 01:04:55 +0100	[thread overview]
Message-ID: <20110201000455.GB19534@cmpxchg.org> (raw)
In-Reply-To: <20110131144131.6733aa3a.akpm@linux-foundation.org>

On Mon, Jan 31, 2011 at 02:41:31PM -0800, Andrew Morton wrote:
> On Mon, 31 Jan 2011 15:03:54 +0100
> Johannes Weiner <hannes@cmpxchg.org> wrote:
> > @@ -1111,6 +1111,15 @@ static bool mem_cgroup_check_under_limit(struct mem_cgroup *mem)
> >  	return false;
> >  }
> >  
> > +static bool mem_cgroup_check_margin(struct mem_cgroup *mem, unsigned long bytes)
> > +{
> > +	if (!res_counter_check_margin(&mem->res, bytes))
> > +		return false;
> > +	if (do_swap_account && !res_counter_check_margin(&mem->memsw, bytes))
> > +		return false;
> > +	return true;
> > +}
> 
> argh.
> 
> If you ever have a function with the string "check" in its name, it's a
> good sign that you did something wrong.
> 
> Check what?  Against what?  Returning what?
> 
> mem_cgroup_check_under_limit() isn't toooo bad - the name tells you
> what's being checked and tells you what to expect the return value to
> mean.
> 
> But "res_counter_check_margin" and "mem_cgroup_check_margin" are just
> awful.  Something like
> 
> 	bool res_counter_may_charge(counter, bytes)
> 
> would be much clearer.

That makes sense for the hard limit.  But the oh-so-generic resource
counters also have a soft limit, and you don't ask for that when you
want to charge.  Right now, I do not feel creative enough to come up
with a symmetric-sounding counterpart.

> If we really want to stick with the "check" names (perhaps as an ironic
> reference to res_counter's past mistakes) then please at least document
> the sorry things?

I cowardly went with this option and have a patch below to fold into
this fix.

Maybe it would be better to use res_counter_margin(cnt) >= wanted
throughout the code.  Or still better, make memcg work on pages and
res_counters on unsigned longs so the locking is no longer needed,
together with an API for most obvious maths.  I will work something
out and submit it separately.

---
Subject: [patch fixup] res_counter: document res_counter_check_margin()

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index 5cfd78a..a5930cb 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -182,6 +182,14 @@ static inline bool res_counter_check_under_limit(struct res_counter *cnt)
 	return ret;
 }
 
+/**
+ * res_counter_check_margin - check if the counter allows charging
+ * @cnt: the resource counter to check
+ * @bytes: the number of bytes to check the remaining space against
+ *
+ * Returns a boolean value on whether the counter can be charged
+ * @bytes or whether this would exceed the limit.
+ */
 static inline bool res_counter_check_margin(struct res_counter *cnt,
 					    unsigned long bytes)
 {

WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kamezawa.hiroyu@jp.fujitsu.com, nishimura@mxp.nes.nec.co.jp,
	balbir@linux.vnet.ibm.com, minchan.kim@gmail.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [patch 2/3] memcg: prevent endless loop when charging huge pages to near-limit group
Date: Tue, 1 Feb 2011 01:04:55 +0100	[thread overview]
Message-ID: <20110201000455.GB19534@cmpxchg.org> (raw)
In-Reply-To: <20110131144131.6733aa3a.akpm@linux-foundation.org>

On Mon, Jan 31, 2011 at 02:41:31PM -0800, Andrew Morton wrote:
> On Mon, 31 Jan 2011 15:03:54 +0100
> Johannes Weiner <hannes@cmpxchg.org> wrote:
> > @@ -1111,6 +1111,15 @@ static bool mem_cgroup_check_under_limit(struct mem_cgroup *mem)
> >  	return false;
> >  }
> >  
> > +static bool mem_cgroup_check_margin(struct mem_cgroup *mem, unsigned long bytes)
> > +{
> > +	if (!res_counter_check_margin(&mem->res, bytes))
> > +		return false;
> > +	if (do_swap_account && !res_counter_check_margin(&mem->memsw, bytes))
> > +		return false;
> > +	return true;
> > +}
> 
> argh.
> 
> If you ever have a function with the string "check" in its name, it's a
> good sign that you did something wrong.
> 
> Check what?  Against what?  Returning what?
> 
> mem_cgroup_check_under_limit() isn't toooo bad - the name tells you
> what's being checked and tells you what to expect the return value to
> mean.
> 
> But "res_counter_check_margin" and "mem_cgroup_check_margin" are just
> awful.  Something like
> 
> 	bool res_counter_may_charge(counter, bytes)
> 
> would be much clearer.

That makes sense for the hard limit.  But the oh-so-generic resource
counters also have a soft limit, and you don't ask for that when you
want to charge.  Right now, I do not feel creative enough to come up
with a symmetric-sounding counterpart.

> If we really want to stick with the "check" names (perhaps as an ironic
> reference to res_counter's past mistakes) then please at least document
> the sorry things?

I cowardly went with this option and have a patch below to fold into
this fix.

Maybe it would be better to use res_counter_margin(cnt) >= wanted
throughout the code.  Or still better, make memcg work on pages and
res_counters on unsigned longs so the locking is no longer needed,
together with an API for most obvious maths.  I will work something
out and submit it separately.

---
Subject: [patch fixup] res_counter: document res_counter_check_margin()

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index 5cfd78a..a5930cb 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -182,6 +182,14 @@ static inline bool res_counter_check_under_limit(struct res_counter *cnt)
 	return ret;
 }
 
+/**
+ * res_counter_check_margin - check if the counter allows charging
+ * @cnt: the resource counter to check
+ * @bytes: the number of bytes to check the remaining space against
+ *
+ * Returns a boolean value on whether the counter can be charged
+ * @bytes or whether this would exceed the limit.
+ */
 static inline bool res_counter_check_margin(struct res_counter *cnt,
 					    unsigned long bytes)
 {

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2011-02-01  0:05 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31 14:03 Johannes Weiner
2011-01-31 14:03 ` Johannes Weiner
2011-01-31 14:03 ` [patch 1/3] memcg: prevent endless loop when charging huge pages Johannes Weiner
2011-01-31 14:03   ` Johannes Weiner
2011-01-31 22:27   ` Minchan Kim
2011-01-31 22:27     ` Minchan Kim
2011-01-31 23:48   ` KAMEZAWA Hiroyuki
2011-01-31 23:48     ` KAMEZAWA Hiroyuki
2011-01-31 14:03 ` [patch 2/3] memcg: prevent endless loop when charging huge pages to near-limit group Johannes Weiner
2011-01-31 14:03   ` Johannes Weiner
2011-01-31 22:41   ` Andrew Morton
2011-01-31 22:41     ` Andrew Morton
2011-01-31 23:50     ` KAMEZAWA Hiroyuki
2011-01-31 23:50       ` KAMEZAWA Hiroyuki
2011-02-01  0:04     ` Johannes Weiner [this message]
2011-02-01  0:04       ` Johannes Weiner
2011-02-01  0:24       ` Andrew Morton
2011-02-01  0:24         ` Andrew Morton
2011-02-01  0:34         ` Johannes Weiner
2011-02-01  0:34           ` Johannes Weiner
2011-02-03 12:53         ` [patch 0/2] memcg: clean up limit checking Johannes Weiner
2011-02-03 12:53           ` Johannes Weiner
2011-02-03 12:54           ` [patch 1/2] memcg: soft limit reclaim should end at limit not below Johannes Weiner
2011-02-03 12:54             ` Johannes Weiner
2011-02-03 23:41             ` KAMEZAWA Hiroyuki
2011-02-03 23:41               ` KAMEZAWA Hiroyuki
2011-02-04  4:10             ` Balbir Singh
2011-02-04  4:10               ` Balbir Singh
2011-02-03 12:56           ` [patch 2/2] memcg: simplify the way memory limits are checked Johannes Weiner
2011-02-03 12:56             ` Johannes Weiner
2011-02-03 23:44             ` KAMEZAWA Hiroyuki
2011-02-03 23:44               ` KAMEZAWA Hiroyuki
2011-02-04  4:12             ` Balbir Singh
2011-02-04  4:12               ` Balbir Singh
2011-01-31 22:42   ` [patch 2/3] memcg: prevent endless loop when charging huge pages to near-limit group Minchan Kim
2011-01-31 22:42     ` Minchan Kim
2011-01-31 14:03 ` [patch 3/3] memcg: never OOM when charging huge pages Johannes Weiner
2011-01-31 14:03   ` Johannes Weiner
2011-01-31 22:52   ` Minchan Kim
2011-01-31 22:52     ` Minchan Kim
2011-01-31 23:51   ` KAMEZAWA Hiroyuki
2011-01-31 23:51     ` 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=20110201000455.GB19534@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan.kim@gmail.com \
    --cc=nishimura@mxp.nes.nec.co.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.