]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
memcg: net: track network throttling due to memcg memory pressure
authorShakeel Butt <shakeel.butt@linux.dev>
Thu, 16 Oct 2025 16:10:35 +0000 (09:10 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 22 Oct 2025 01:51:39 +0000 (18:51 -0700)
The kernel can throttle network sockets if the memory cgroup associated
with the corresponding socket is under memory pressure.  The throttling
actions include clamping the transmit window, failing to expand receive or
send buffers, aggressively prune out-of-order receive queue, FIN deferred
to a retransmitted packet and more.  Let's add memcg metric to track such
throttling actions.

At the moment memcg memory pressure is defined through vmpressure and in
future it may be defined using PSI or we may add more flexible way for the
users to define memory pressure, maybe through ebpf.  However the
potential throttling actions will remain the same, so this newly
introduced metric will continue to track throttling actions irrespective
of how memcg memory pressure is defined.

Link: https://lkml.kernel.org/r/20251016161035.86161-1-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Daniel Sedlak <daniel.sedlak@cdn77.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kacinski <kuba@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/admin-guide/cgroup-v2.rst
include/linux/memcontrol.h
include/net/sock.h
kernel/cgroup/cgroup.c
mm/memcontrol.c

index 0e6c67ac585a0894f40b6f169d0e920ddd925899..3345961c30ac37b75900afd67c3d9e3787b19f68 100644 (file)
@@ -1515,6 +1515,10 @@ The following nested keys are defined.
           oom_group_kill
                 The number of times a group OOM has occurred.
 
+          sock_throttled
+                The number of times network sockets associated with
+                this cgroup are throttled.
+
   memory.events.local
        Similar to memory.events but the fields in the file are local
        to the cgroup i.e. not hierarchical. The file modified event
index 5ca97fece69079948d195ba69576592666b37417..d37e7c93bb8c185eb0dc6373472d3e8679f76d75 100644 (file)
@@ -52,6 +52,7 @@ enum memcg_memory_event {
        MEMCG_SWAP_HIGH,
        MEMCG_SWAP_MAX,
        MEMCG_SWAP_FAIL,
+       MEMCG_SOCK_THROTTLED,
        MEMCG_NR_MEMORY_EVENTS,
 };
 
index 60bcb13f045c3144609908a36960528b33e4f71c..ff7d49af16193cdaf0cfca3d7d477b4d7c154830 100644 (file)
@@ -2635,8 +2635,12 @@ static inline bool mem_cgroup_sk_under_memory_pressure(const struct sock *sk)
 #endif /* CONFIG_MEMCG_V1 */
 
        do {
-               if (time_before64(get_jiffies_64(), mem_cgroup_get_socket_pressure(memcg)))
+               if (time_before64(get_jiffies_64(),
+                                 mem_cgroup_get_socket_pressure(memcg))) {
+                       memcg_memory_event(mem_cgroup_from_sk(sk),
+                                          MEMCG_SOCK_THROTTLED);
                        return true;
+               }
        } while ((memcg = parent_mem_cgroup(memcg)));
 
        return false;
index 6ae5f48cf64e34e263afb45647848c53ec97a12f..351e9af14ad75c44c85c3083ff9f4677e7bac697 100644 (file)
@@ -4704,6 +4704,7 @@ void cgroup_file_notify(struct cgroup_file *cfile)
        }
        spin_unlock_irqrestore(&cgroup_file_kn_lock, flags);
 }
+EXPORT_SYMBOL_GPL(cgroup_file_notify);
 
 /**
  * cgroup_file_show - show or hide a hidden cgroup file
index 75d1715628f7aec04edf4275c7a6cbb47e2215f9..1a95049d8b88e458219ea0c72af2d3fe0ee429c7 100644 (file)
@@ -81,6 +81,7 @@ struct cgroup_subsys memory_cgrp_subsys __read_mostly;
 EXPORT_SYMBOL(memory_cgrp_subsys);
 
 struct mem_cgroup *root_mem_cgroup __read_mostly;
+EXPORT_SYMBOL(root_mem_cgroup);
 
 /* Active memory cgroup to use from an interrupt context */
 DEFINE_PER_CPU(struct mem_cgroup *, int_active_memcg);
@@ -4464,6 +4465,8 @@ static void __memory_events_show(struct seq_file *m, atomic_long_t *events)
                   atomic_long_read(&events[MEMCG_OOM_KILL]));
        seq_printf(m, "oom_group_kill %lu\n",
                   atomic_long_read(&events[MEMCG_OOM_GROUP_KILL]));
+       seq_printf(m, "sock_throttled %lu\n",
+                  atomic_long_read(&events[MEMCG_SOCK_THROTTLED]));
 }
 
 static int memory_events_show(struct seq_file *m, void *v)