Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Glauber Costa and committed by
David S. Miller
8cfd14ad 376be5ff

+4 -1
+4 -1
include/linux/res_counter.h
··· 142 142 unsigned long flags; 143 143 144 144 spin_lock_irqsave(&cnt->lock, flags); 145 - margin = cnt->limit - cnt->usage; 145 + if (cnt->limit > cnt->usage) 146 + margin = cnt->limit - cnt->usage; 147 + else 148 + margin = 0; 146 149 spin_unlock_irqrestore(&cnt->lock, flags); 147 150 return margin; 148 151 }