Skip to content

Commit 8542d6f

Browse files
Tengteng Yangkuba-moo
authored andcommitted
Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated
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 2def8ff ("sock: Code cleanup on __sk_mem_raise_allocated()"). The fix changes the default value of charged to true while preserving existing logic. Fixes: 2def8ff ("sock: Code cleanup on __sk_mem_raise_allocated()") Signed-off-by: Abel Wu <[email protected]> Signed-off-by: Tengteng Yang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 90b83ef commit 8542d6f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/core/sock.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,16 +3284,16 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
32843284
{
32853285
struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL;
32863286
struct proto *prot = sk->sk_prot;
3287-
bool charged = false;
3287+
bool charged = true;
32883288
long allocated;
32893289

32903290
sk_memory_allocated_add(sk, amt);
32913291
allocated = sk_memory_allocated(sk);
32923292

32933293
if (memcg) {
3294-
if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
3294+
charged = mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge());
3295+
if (!charged)
32953296
goto suppress_allocation;
3296-
charged = true;
32973297
}
32983298

32993299
/* Under limit. */
@@ -3378,7 +3378,7 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
33783378

33793379
sk_memory_allocated_sub(sk, amt);
33803380

3381-
if (charged)
3381+
if (memcg && charged)
33823382
mem_cgroup_uncharge_skmem(memcg, amt);
33833383

33843384
return 0;

0 commit comments

Comments
 (0)