]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tcp: Save lock_sock() for memcg in inet_csk_accept().
authorKuniyuki Iwashima <kuniyu@google.com>
Tue, 14 Oct 2025 23:54:54 +0000 (23:54 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 16 Oct 2025 19:04:47 +0000 (12:04 -0700)
commit4a997d49d92ad9dda603f60881faa6c800d435e9
tree8bf9b4d80dcbd6722af778d7b21a8f65a837c838
parent55db64ddd6a12c5157a61419a11a18fc727e8286
tcp: Save lock_sock() for memcg in inet_csk_accept().

If memcg is enabled, accept() acquires lock_sock() twice for each new
TCP/MPTCP socket in inet_csk_accept() and __inet_accept().

Let's move memcg operations from inet_csk_accept() to __inet_accept().

Note that SCTP somehow allocates a new socket by sk_alloc() in
sk->sk_prot->accept() and clones fields manually, instead of using
sk_clone_lock().

mem_cgroup_sk_alloc() is called for SCTP before __inet_accept(),
so I added the protocol check in __inet_accept(), but this can be
removed once SCTP uses sk_clone_lock().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Link: https://patch.msgid.link/20251014235604.3057003-2-kuniyu@google.com
net/ipv4/af_inet.c
net/ipv4/inet_connection_sock.c