Skip to content

Commit

Permalink
cgroup: make sure memcg margin is 0 when over limit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Glauber Costa authored and David S. Miller committed Jan 22, 2012
1 parent 376be5f commit 8cfd14a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/linux/res_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8cfd14a

Please sign in to comment.