From: Kuniyuki Iwashima kuniyu@google.com
[ Upstream commit 9d85c565a7b7c78b732393c02bcaa4d5c275fe58 ]
Initially, trace_sock_exceed_buf_limit() was invoked when __sk_mem_raise_allocated() failed due to the memcg limit or the global limit.
However, commit d6f19938eb031 ("net: expose sk wmem in sock_exceed_buf_limit tracepoint") somehow suppressed the event only when memcg failed to charge for SK_MEM_RECV, although the memcg failure for SK_MEM_SEND still triggers the event.
Let's restore the event for SK_MEM_RECV.
Signed-off-by: Kuniyuki Iwashima kuniyu@google.com Reviewed-by: Eric Dumazet edumazet@google.com Reviewed-by: Shakeel Butt shakeel.butt@linux.dev Link: https://patch.msgid.link/20250815201712.1745332-5-kuniyu@google.com Signed-off-by: Jakub Kicinski kuba@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- What it fixes - Restores a missing tracepoint emission when memory cgroup charge fails for receive allocations. Today, the tracepoint is not emitted for SK_MEM_RECV on memcg charge failure, which breaks observability for memory pressure on receive paths. - The suppression was introduced by d6f19938eb031 (“net: expose sk wmem in sock_exceed_buf_limit tracepoint”), as confirmed by blame on the conditional emission at net/core/sock.c:3335-3336.
- Change details - Current code (before this patch) only emits the tracepoint if: - send path: always, or - receive path: only if memcg charge “succeeded” (`charged == true`): - net/core/sock.c:3335-3336 if (kind == SK_MEM_SEND || (kind == SK_MEM_RECV && charged)) trace_sock_exceed_buf_limit(sk, prot, allocated, kind); - The patch makes the emission unconditional in the suppression path: - Effectively changes the above to: - net/core/sock.c:3336 trace_sock_exceed_buf_limit(sk, prot, allocated, kind); - No other logic or accounting is changed; the uncharge remains correctly guarded by `if (memcg && charged)` (net/core/sock.c:3340), preserving correct memcg accounting.
- Scope and risk - Small, contained one-line change in a well-defined path (the suppress_allocation path of __sk_mem_raise_allocated()). - Functional impact limited to tracing only; no behavior change in networking or memory accounting. - Tracepoints are nop when disabled (static branches), so overhead impact is negligible; when enabled, this restores expected visibility for memcg receive failures.
- Historical/contextual analysis - Originally, the tracepoint was intended to fire on allocation suppression due to either global or memcg limits. - d6f19938eb031 (blame at net/core/sock.c:3335-3336) unintentionally gated the SK_MEM_RECV case on `charged`, suppressing the event specifically when memcg charge failed (the exact condition users need to observe). - A related fix, 8542d6fac25c0 (“Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated”), already corrected a different regression around default `charged` and uncharge gating, and is present in this tree (net/core/sock.c:3340). This new change complements that by fixing the SK_MEM_RECV/memcg-fail emission gap.
- Stable backport criteria - Important bugfix (restores a lost diagnostic signal used by operators for memory pressure analysis and debugging). - Minimal and localized change; no ABI/API or architectural changes. - No side effects on core data path or memory accounting. - Affects a core net tracepoint but only its emission conditions; matches original intent and symmetry with SK_MEM_SEND.
- Applicability/dependencies - Applies cleanly to trees where the conditional exists (introduced by d6f19938eb031). No additional dependencies beyond the already- present tracepoint infrastructure. - For older stable series also missing 8542d6fac25c0, consider backporting that commit as well to avoid other missed events in non- memcg scenarios.
Conclusion: Backporting this commit is low risk and restores expected tracing semantics for a real-world observability regression.
net/core/sock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c index e21348ead7e76..1382bddcbaff4 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3336,8 +3336,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) } }
- if (kind == SK_MEM_SEND || (kind == SK_MEM_RECV && charged)) - trace_sock_exceed_buf_limit(sk, prot, allocated, kind); + trace_sock_exceed_buf_limit(sk, prot, allocated, kind);
sk_memory_allocated_sub(sk, amt);