Skip to content

Use mem_cgroup_from_sk in homa_rpc_alloc_server - #146

Open
randomizedcoder wants to merge 1 commit into
PlatformLab:mainfrom
randomizedcoder:fix/rpc-memcg-without-config-memcg
Open

randomizedcoder wants to merge 1 commit into
PlatformLab:mainfrom
randomizedcoder:fix/rpc-memcg-without-config-memcg

Conversation

@randomizedcoder

@randomizedcoder randomizedcoder commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

struct sock has sk_memcg only when CONFIG_MEMCG is set (since 6.18). In a kernel without memory cgroups (x86_64 and i386 defconfig, for example), homa_rpc_alloc_server doesn't compile:

net/homa/homa_rpc.c:134:22: error: 'struct sock' has no member named 'sk_memcg'

The out-of-tree build only passes because distro kernels enable memcg.

Fix: from 6.18, read it with mem_cgroup_from_sk(). Under CONFIG_MEMCG that returns sk->sk_memcg; without it, it returns NULL, so the allocation takes the existing non-accounted path. Before 6.18 the field is unconditional and mem_cgroup_from_sk() doesn't exist, so a LINUX_VERSION_CODE check reads the field directly. Behaviour is unchanged when memcg is on, and the stripped output is the 6.18+ form.

Checked:

  • 886/886 unit tests pass.
  • The module builds against 6.17.8 and 7.3, normally, with __STRIP__=1, and against a KASAN/lockdep 7.3 kernel. The previous version of this commit reproduces the 6.17 mem_cgroup_from_sk error.
  • The stripped files build in a 7.3 tree (defconfig + HOMA=m, W=1; gcc + sparse, clang, i386) with no warnings, once a separate one-line fix for a new set-but-unused variable in homa_pool.c (from the pool rework) is applied too; that one will follow as its own PR.

No test, since it's a build fix.

🤖 Generated with Claude Code

@johnousterhout

Copy link
Copy Markdown
Member

This PR doesn't build on Homa's main branch (6.17.8): mem_cgroup_from_sk isn't present in that version of Linux. Can you modify it to behave properly when mem_cgroup_from_sk isn't present?

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>
@randomizedcoder
randomizedcoder force-pushed the fix/rpc-memcg-without-config-memcg branch from e550056 to 07b4cc6 Compare November 7, 2026 17:55
randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 7, 2026
Homa's README and CI name 6.17.8, and the matrix tested 6.12, 6.18 and
7.x, so it could not catch code that only builds on 6.18 and later
(PlatformLab#146). BTF is off in this tree: its libbpf fails on current glibc, and
a compile check doesn't need BTF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 7, 2026
Homa's README and CI name 6.17.8, and the matrix tested 6.12, 6.18 and
7.x, so it could not catch code that only builds on 6.18 and later
(PlatformLab#146). BTF is off in this tree: its libbpf fails on current glibc, and
a compile check doesn't need BTF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@randomizedcoder

Copy link
Copy Markdown
Contributor Author

Thanks John, fixed. mem_cgroup_from_sk arrived in 6.18, along with the CONFIG_MEMCG guard on sk_memcg, so it now uses a LINUX_VERSION_CODE check and reads the field directly before 6.18. The stripped output is unchanged. Our test matrix was missing 6.17.8, so we've added it; this now builds there, and the old commit reproduces your error.

randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 8, 2026
…fork #29)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 8, 2026
nixpkgs 2026-11-07: kernels 6.12.116, 6.18.62, 7.3.3 (gcc 16.2, clang
21.1.8 unchanged). The kernel table in nix/README.md was missing the
6_17 tarball series added for Homa main's 6.17.8.

Checked: nix flake check; homa-tests 886/886; homa-module-7_3, -6_12,
-6_17, -debug; homa-build-matrix (6.1, 6.6, 6.18 fail as before);
homa-microvm-test PASS on 7.3.3; analysis-netdev W=1 shows only the
PlatformLab#146 and PlatformLab#149 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 8, 2026
nixpkgs 2026-11-07: kernels 6.12.116, 6.18.62, 7.3.3 (gcc 16.2, clang
21.1.8 unchanged). The kernel table in nix/README.md was missing the
6_17 tarball series added for Homa main's 6.17.8.

Checked: nix flake check; homa-tests 886/886; homa-module-7_3, -6_12,
-6_17, -debug; homa-build-matrix (6.1, 6.6, 6.18 fail as before);
homa-microvm-test PASS on 7.3.3; analysis-netdev W=1 shows only the
PlatformLab#146 and PlatformLab#149 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
randomizedcoder added a commit to randomizedcoder/HomaModule that referenced this pull request Nov 9, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants