All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated
@ 2025-05-27  3:04 yangtengteng
  2025-05-29  4:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: yangtengteng @ 2025-05-27  3:04 UTC (permalink / raw)
  To: edumazet, kuniyu, pabeni, willemb, davem, kuba, horms, wuyun.abel,
	shakeel.butt
  Cc: netdev, linux-kernel, zhoufeng.zf, wangdongdong.6, zhangrui.rod,
	yangzhenze, yangtengteng

From: Tengteng Yang <yangtengteng@bytedance.com>

When a process under memory pressure is not part of any cgroup and
the charged flag is false, trace_sock_exceed_buf_limit was not called
as expected.

This regression was introduced by commit 2def8ff3fdb6 ("sock:
Code cleanup on __sk_mem_raise_allocated()"). The fix changes the
default value of charged to true while preserving existing logic.

Fixes: 2def8ff3fdb6 ("sock: Code cleanup on __sk_mem_raise_allocated()")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Signed-off-by: Tengteng Yang <yangtengteng@bytedance.com>
---
v1:
- Fix compilation error caused by mismatched parentheses
---
 net/core/sock.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index 347ce75482f5..9cfed4635d81 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3235,16 +3235,16 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 {
 	struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL;
 	struct proto *prot = sk->sk_prot;
-	bool charged = false;
+	bool charged = true;
 	long allocated;
 
 	sk_memory_allocated_add(sk, amt);
 	allocated = sk_memory_allocated(sk);
 
 	if (memcg) {
-		if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
+		charged = mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge());
+		if (!charged)
 			goto suppress_allocation;
-		charged = true;
 	}
 
 	/* Under limit. */
@@ -3329,7 +3329,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 
 	sk_memory_allocated_sub(sk, amt);
 
-	if (charged)
+	if (memcg && charged)
 		mem_cgroup_uncharge_skmem(memcg, amt);
 
 	return 0;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v2] Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated
  2025-05-27  3:04 [PATCH net-next v2] Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated yangtengteng
@ 2025-05-29  4:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-29  4:10 UTC (permalink / raw)
  To: yangtengteng
  Cc: edumazet, kuniyu, pabeni, willemb, davem, kuba, horms, wuyun.abel,
	shakeel.butt, netdev, linux-kernel, zhoufeng.zf, wangdongdong.6,
	zhangrui.rod, yangzhenze

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 27 May 2025 11:04:19 +0800 you wrote:
> From: Tengteng Yang <yangtengteng@bytedance.com>
> 
> When a process under memory pressure is not part of any cgroup and
> the charged flag is false, trace_sock_exceed_buf_limit was not called
> as expected.
> 
> This regression was introduced by commit 2def8ff3fdb6 ("sock:
> Code cleanup on __sk_mem_raise_allocated()"). The fix changes the
> default value of charged to true while preserving existing logic.
> 
> [...]

Here is the summary with links:
  - [net-next,v2] Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated
    https://git.kernel.org/netdev/net/c/8542d6fac25c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-29  4:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27  3:04 [PATCH net-next v2] Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated yangtengteng
2025-05-29  4:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.