summaryrefslogtreecommitdiff
path: root/include/linux/res_counter.h
diff options
context:
space:
mode:
authorGlauber Costa <glommer@parallels.com>2012-01-20 08:57:15 +0400
committerDavid S. Miller <davem@davemloft.net>2012-01-23 00:08:45 +0400
commit8cfd14ad1eb52e44cb1fe7b47a68126e45e04026 (patch)
tree5c526f7ced428e65db025ba7af29ca114031c302 /include/linux/res_counter.h
parent376be5ff8a6a36efadd131860cf26841f366d44c (diff)
downloadlinux-8cfd14ad1eb52e44cb1fe7b47a68126e45e04026.tar.xz
cgroup: make sure memcg margin is 0 when over limit
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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r--include/linux/res_counter.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index c9d625ca659e..d06d014afda6 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;
}