Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sock: Code cleanup on __sk_mem_raise_allocated()

Code cleanup for both better simplicity and readability.
No functional change intended.

Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20231019120026.42215-1-wuyun.abel@bytedance.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Abel Wu and committed by
Paolo Abeni
2def8ff3 f6e12277

+12 -10
+12 -10
net/core/sock.c
··· 3039 3039 */ 3040 3040 int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) 3041 3041 { 3042 - bool memcg_charge = mem_cgroup_sockets_enabled && sk->sk_memcg; 3042 + struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL; 3043 3043 struct proto *prot = sk->sk_prot; 3044 - bool charged = true; 3044 + bool charged = false; 3045 3045 long allocated; 3046 3046 3047 3047 sk_memory_allocated_add(sk, amt); 3048 3048 allocated = sk_memory_allocated(sk); 3049 - if (memcg_charge && 3050 - !(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt, 3051 - gfp_memcg_charge()))) 3052 - goto suppress_allocation; 3049 + 3050 + if (memcg) { 3051 + if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge())) 3052 + goto suppress_allocation; 3053 + charged = true; 3054 + } 3053 3055 3054 3056 /* Under limit. */ 3055 3057 if (allocated <= sk_prot_mem_limits(sk, 0)) { ··· 3106 3104 */ 3107 3105 if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) { 3108 3106 /* Force charge with __GFP_NOFAIL */ 3109 - if (memcg_charge && !charged) { 3110 - mem_cgroup_charge_skmem(sk->sk_memcg, amt, 3107 + if (memcg && !charged) { 3108 + mem_cgroup_charge_skmem(memcg, amt, 3111 3109 gfp_memcg_charge() | __GFP_NOFAIL); 3112 3110 } 3113 3111 return 1; ··· 3119 3117 3120 3118 sk_memory_allocated_sub(sk, amt); 3121 3119 3122 - if (memcg_charge && charged) 3123 - mem_cgroup_uncharge_skmem(sk->sk_memcg, amt); 3120 + if (charged) 3121 + mem_cgroup_uncharge_skmem(memcg, amt); 3124 3122 3125 3123 return 0; 3126 3124 }