diff mbox

[2/3] cgroup: make sure memcg margin is 0 when over limit

Message ID 1327071436-20763-3-git-send-email-glommer@parallels.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Glauber Costa Jan. 20, 2012, 2:57 p.m. UTC
For the memcg sock code, we'll need to register allocations
that are temporarily over limit. Let's make sure that margin
is 0 in this case.

I am keeping this as a separate patch, so that if any weirdness
interaction appears in the future, we can now exactly what caused
it.

Suggested by Johannes Weiner 

Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
CC: Johannes Weiner <hannes@cmpxchg.org>
CC: Michal Hocko <mhocko@suse.cz>
CC: Tejun Heo <tj@kernel.org>
CC: Li Zefan <lizf@cn.fujitsu.com>
---
 include/linux/res_counter.h |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

Comments

Tejun Heo Jan. 20, 2012, 5:08 p.m. UTC | #1
On Fri, Jan 20, 2012 at 06:57:15PM +0400, Glauber Costa wrote:
> For the memcg sock code, we'll need to register allocations
> that are temporarily over limit. Let's make sure that margin
> is 0 in this case.
> 
> I am keeping this as a separate patch, so that if any weirdness
> interaction appears in the future, we can now exactly what caused
> it.
> 
> Suggested by Johannes Weiner 
> 
> Signed-off-by: Glauber Costa <glommer@parallels.com>
> CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> CC: Johannes Weiner <hannes@cmpxchg.org>
> CC: Michal Hocko <mhocko@suse.cz>
> CC: Tejun Heo <tj@kernel.org>
> CC: Li Zefan <lizf@cn.fujitsu.com>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
Johannes Weiner Jan. 24, 2012, 8:12 a.m. UTC | #2
On Fri, Jan 20, 2012 at 06:57:15PM +0400, Glauber Costa wrote:
> For the memcg sock code, we'll need to register allocations
> that are temporarily over limit. Let's make sure that margin
> is 0 in this case.
> 
> I am keeping this as a separate patch, so that if any weirdness
> interaction appears in the future, we can now exactly what caused
> it.
> 
> Suggested by Johannes Weiner 
> 
> Signed-off-by: Glauber Costa <glommer@parallels.com>
> CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> CC: Johannes Weiner <hannes@cmpxchg.org>
> CC: Michal Hocko <mhocko@suse.cz>
> CC: Tejun Heo <tj@kernel.org>
> CC: Li Zefan <lizf@cn.fujitsu.com>

Thanks,

Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index c9d625c..d06d014 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -142,7 +142,10 @@  static inline unsigned long long res_counter_margin(struct res_counter *cnt)
 	unsigned long flags;
 
 	spin_lock_irqsave(&cnt->lock, flags);
-	margin = cnt->limit - cnt->usage;
+	if (cnt->limit > cnt->usage)
+		margin = cnt->limit - cnt->usage;
+	else
+		margin = 0;
 	spin_unlock_irqrestore(&cnt->lock, flags);
 	return margin;
 }