Skip to content

Commit 07b4cc6

Browse files
Use mem_cgroup_from_sk in homa_rpc_alloc_server
Since Linux 6.18, struct sock has an sk_memcg field only when CONFIG_MEMCG is set, so homa_rpc_alloc_server failed to compile in kernels without memory cgroups (such as x86_64 and i386 defconfig). Use mem_cgroup_from_sk, which returns NULL in that case. That function doesn't exist before 6.18, where sk_memcg is unconditional, so keep reading the field there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5cb0ec2 commit 07b4cc6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎homa_rpc.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk,
117117
u64 id = homa_local_id(h->sender_id);
118118
struct homa_rpc_bucket *bucket;
119119
struct homa_rpc *srpc = NULL;
120+
struct mem_cgroup *memcg;
120121
int msg_length;
121122
int err;
122123

@@ -140,8 +141,13 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk,
140141
}
141142

142143
/* Initialize fields that don't require the socket lock. */
143-
if (hsk->sock.sk_memcg) {
144-
struct mem_cgroup *old = set_active_memcg(hsk->sock.sk_memcg);
144+
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 18, 0)
145+
memcg = hsk->sock.sk_memcg;
146+
#else
147+
memcg = mem_cgroup_from_sk(&hsk->sock);
148+
#endif
149+
if (memcg) {
150+
struct mem_cgroup *old = set_active_memcg(memcg);
145151

146152
srpc = kzalloc(sizeof(*srpc), GFP_ATOMIC | __GFP_ACCOUNT);
147153
set_active_memcg(old);

0 commit comments

Comments
 (0)