net: tcp_memcontrol: properly detect ancestor socket pressure
authorJohannes Weiner <hannes@cmpxchg.org>
Thu, 14 Jan 2016 23:20:59 +0000 (15:20 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Jan 2016 00:00:49 +0000 (16:00 -0800)
When charging socket memory, the code currently checks only the local
page counter for excess to determine whether the memcg is under socket
pressure.  But even if the local counter is fine, one of the ancestors
could have breached its limit, which should also force this child to
enter socket pressure.  This currently doesn't happen.

Fix this by using page_counter_try_charge() first.  If that fails, it
means that either the local counter or one of the ancestors are in
excess of their limit, and the child should enter socket pressure.

Fixes: 3e32cb2e0a12 ("mm: memcontrol: lockless page counters")
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: David S. Miller <davem@davemloft.net>
Reviewed-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/net/sock.h

index e830c10..9ef3d7c 100644 (file)
@@ -1193,11 +1193,13 @@ static inline void memcg_memory_allocated_add(struct cg_proto *prot,
                                              unsigned long amt,
                                              int *parent_status)
 {
-       page_counter_charge(&prot->memory_allocated, amt);
+       struct page_counter *counter;
+
+       if (page_counter_try_charge(&prot->memory_allocated, amt, &counter))
+               return;
 
-       if (page_counter_read(&prot->memory_allocated) >
-           prot->memory_allocated.limit)
-               *parent_status = OVER_LIMIT;
+       page_counter_charge(&prot->memory_allocated, amt);
+       *parent_status = OVER_LIMIT;
 }
 
 static inline void memcg_memory_allocated_sub(struct cg_proto *prot,