[RHEL7,COMMIT] net/memcg: fix check for OVER_LIMIT in socket memory accounting

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

Details

Message ID 201812121503.wBCF38SB014686@finist-ce7.sw.ru
State New
Series "net/memcg: fix check for OVER_LIMIT in socket memory accounting"
Headers show

Commit Message

Konstantin Khorenko Dec. 12, 2018, 3:03 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.1.3.vz7.83.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.1.3.vz7.83.2
------>
commit b88c664def12e0c613e70d440437283f81605e1f
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Wed Dec 12 17:31:23 2018 +0300

    net/memcg: fix check for OVER_LIMIT in socket memory accounting
    
    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);