[vz7.83.x] net/memcg: fix check for OVER_LIMIT in socket memory accounting

Submitted by Konstantin Khorenko on Dec. 12, 2018, 3:01 p.m.

Details

Message ID 20181212150110.14594-1-khorenko@virtuozzo.com
State New
Series "net/memcg: fix check for OVER_LIMIT in socket memory accounting"
Headers show

Commit Message

Konstantin Khorenko Dec. 12, 2018, 3:01 p.m.
memcg_memory_allocated_add() check for charge success is inverted:
page_counter_try_charge() return 0 in success.

RedHat backported commit 8c2c2358b236 ("net: tcp_memcontrol: properly
detect ancestor socket pressure"), but forgot about
6071ca520106 ("mm: page_counter: let page_counter_try_charge() return
bool") which reverts return values for page_counter_try_charge().

Until this patch UDP traffic simply dropped because of incorrectly
detected memory pressure.

*parent_status = OVER_LIMIT;
 memcg_memory_allocated_add
  sk_memory_allocated_add
   __sk_mem_raise_allocated
    __udp_enqueue_schedule_skb
     __udp_queue_rcv_skb
      udp_queue_rcv_skb
       __udp4_lib_rcv
        udp_rcv
         ip_local_deliver_finish
          ip_local_deliver
           ip_rcv_finish
            ip_rcv
             __netif_receive_skb_core
              __netif_receive_skb
               process_backlog
                net_rx_action
                 __do_softirq
                  call_softirq
                   do_softirq
                    irq_exit

https://jira.sw.ru/browse/PSBM-90144

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 include/net/sock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/include/net/sock.h b/include/net/sock.h
index 18d318988cdd..1b86b37fe884 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1261,7 +1261,7 @@  static inline void memcg_memory_allocated_add(struct cg_proto *prot,
 	struct page_counter *counter;
 
 	memcg_charge_kmem_nofail(prot->memcg, amt);
-	if (page_counter_try_charge(prot->memory_allocated, amt, &counter))
+	if (!page_counter_try_charge(prot->memory_allocated, amt, &counter))
 		return;
 
 	page_counter_charge(prot->memory_allocated, amt);