]> www.infradead.org Git - users/willy/linux.git/commitdiff
net: Define sk_memcg under CONFIG_MEMCG.
authorKuniyuki Iwashima <kuniyu@google.com>
Fri, 15 Aug 2025 20:16:18 +0000 (20:16 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 Aug 2025 02:20:59 +0000 (19:20 -0700)
Except for sk_clone_lock(), all accesses to sk->sk_memcg
is done under CONFIG_MEMCG.

As a bonus, let's define sk->sk_memcg under CONFIG_MEMCG.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Link: https://patch.msgid.link/20250815201712.1745332-11-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/sock.h
net/core/sock.c

index 3bc4d566f7d0088f415e6f95d780d0adcfe6736f..1c49ea13af4ab2103e85b472af88659a6b27696c 100644 (file)
@@ -443,7 +443,9 @@ struct sock {
        __cacheline_group_begin(sock_read_rxtx);
        int                     sk_err;
        struct socket           *sk_socket;
+#ifdef CONFIG_MEMCG
        struct mem_cgroup       *sk_memcg;
+#endif
 #ifdef CONFIG_XFRM
        struct xfrm_policy __rcu *sk_policy[2];
 #endif
index 5537ca2638588329cc6412d37e7c8b7fe1e38f24..ab6953d295dfa903e059c654a7917fefb18aa41e 100644 (file)
@@ -2512,8 +2512,10 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
 
        sock_reset_flag(newsk, SOCK_DONE);
 
+#ifdef CONFIG_MEMCG
        /* sk->sk_memcg will be populated at accept() time */
        newsk->sk_memcg = NULL;
+#endif
 
        cgroup_sk_clone(&newsk->sk_cgrp_data);
 
@@ -4452,7 +4454,9 @@ static int __init sock_struct_check(void)
 
        CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_rxtx, sk_err);
        CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_rxtx, sk_socket);
+#ifdef CONFIG_MEMCG
        CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_read_rxtx, sk_memcg);
+#endif
 
        CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_write_rxtx, sk_lock);
        CACHELINE_ASSERT_GROUP_MEMBER(struct sock, sock_write_rxtx, sk_reserved_mem);