Commit 53bf9164 authored by Abel Wu's avatar Abel Wu Committed by Jakub Kicinski

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: default avatarAbel Wu <wuyun.abel@bytedance.com>
Link: https://lore.kernel.org/r/20230620092712.16217-1-wuyun.abel@bytedance.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ca4fa874
...@@ -706,20 +706,23 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern) ...@@ -706,20 +706,23 @@ struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern)
out: out:
release_sock(sk); release_sock(sk);
if (newsk && mem_cgroup_sockets_enabled) { if (newsk && mem_cgroup_sockets_enabled) {
int amt; int amt = 0;
/* atomically get the memory usage, set and charge the /* atomically get the memory usage, set and charge the
* newsk->sk_memcg. * newsk->sk_memcg.
*/ */
lock_sock(newsk); lock_sock(newsk);
/* The socket has not been accepted yet, no need to look at
* newsk->sk_wmem_queued.
*/
amt = sk_mem_pages(newsk->sk_forward_alloc +
atomic_read(&newsk->sk_rmem_alloc));
mem_cgroup_sk_alloc(newsk); mem_cgroup_sk_alloc(newsk);
if (newsk->sk_memcg && amt) if (newsk->sk_memcg) {
/* The socket has not been accepted yet, no need
* to look at newsk->sk_wmem_queued.
*/
amt = sk_mem_pages(newsk->sk_forward_alloc +
atomic_read(&newsk->sk_rmem_alloc));
}
if (amt)
mem_cgroup_charge_skmem(newsk->sk_memcg, amt, mem_cgroup_charge_skmem(newsk->sk_memcg, amt,
GFP_KERNEL | __GFP_NOFAIL); GFP_KERNEL | __GFP_NOFAIL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment