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.

inet: Cleanup on charging memory for newly accepted sockets

If there is no net-memcg associated with the sock, don't bother
calculating its memory usage for charge.

Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Link: https://lore.kernel.org/r/20230620092712.16217-1-wuyun.abel@bytedance.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Abel Wu and committed by
Jakub Kicinski
53bf9164 ca4fa874

+10 -7
+10 -7
net/ipv4/inet_connection_sock.c
··· 706 706 out: 707 707 release_sock(sk); 708 708 if (newsk && mem_cgroup_sockets_enabled) { 709 - int amt; 709 + int amt = 0; 710 710 711 711 /* atomically get the memory usage, set and charge the 712 712 * newsk->sk_memcg. 713 713 */ 714 714 lock_sock(newsk); 715 715 716 - /* The socket has not been accepted yet, no need to look at 717 - * newsk->sk_wmem_queued. 718 - */ 719 - amt = sk_mem_pages(newsk->sk_forward_alloc + 720 - atomic_read(&newsk->sk_rmem_alloc)); 721 716 mem_cgroup_sk_alloc(newsk); 722 - if (newsk->sk_memcg && amt) 717 + if (newsk->sk_memcg) { 718 + /* The socket has not been accepted yet, no need 719 + * to look at newsk->sk_wmem_queued. 720 + */ 721 + amt = sk_mem_pages(newsk->sk_forward_alloc + 722 + atomic_read(&newsk->sk_rmem_alloc)); 723 + } 724 + 725 + if (amt) 723 726 mem_cgroup_charge_skmem(newsk->sk_memcg, amt, 724 727 GFP_KERNEL | __GFP_NOFAIL); 725 728