Sandbox cgroup silently disables transparent huge pages (THP)
Problem
Processes launched by Claude Code cannot use transparent huge pages (THP), even when the host system has transparent_hugepage/enabled=always and defrag=always. The same binary run from a regular user shell gets full THP promotion; run from Claude Code it gets zero.
This silently breaks performance measurement and verification of THP-related optimizations.
Reproduction
- Set up THP on the host:
sudo sh -c 'echo always > /sys/kernel/mm/transparent_hugepage/enabled'
sudo sh -c 'echo always > /sys/kernel/mm/transparent_hugepage/defrag'
- Compile and run this test program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#define SIZE (10 * 1024 * 1024)
int main() {
void *p = mmap(NULL, SIZE, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) { perror("mmap"); return 1; }
madvise(p, SIZE, MADV_HUGEPAGE);
memset(p, 0, SIZE);
char cmd[128];
snprintf(cmd, sizeof(cmd),
"grep AnonHugePages /proc/%d/smaps | awk '{s+=$2}END{printf \"AnonHugePages: %%d kB\\n\",s}'",
getpid());
system(cmd);
munmap(p, SIZE);
return 0;
}
- Run from a regular shell →
AnonHugePages: 10240 kB(correct) - Run from Claude Code →
AnonHugePages: 0 kB(broken)
madvise(MADV_HUGEPAGE) returns 0 (success) in both cases, so the caller has no way to detect the failure.
Likely cause
The Claude Code sandbox likely runs processes in a cgroup (v2) that has THP disabled. This could be:
memory.numa_stator a cgroup-level THP restriction- A seccomp filter that allows
madvisebut neutersMADV_HUGEPAGE - A memory cgroup controller setting that prevents hugepage allocation
Impact
- Cannot verify THP-related performance optimizations from within Claude Code
- Benchmarks run from Claude Code show different memory behavior than the user's environment
madvisereturning success when the hint is silently ignored makes debugging very difficult
Environment
- Host: Ubuntu, kernel 7.0.0-12-generic
- CPU: AMD Ryzen AI Max+ 395
- Claude Code: CLI (latest)
Suggestion
If THP must be disabled in the sandbox for resource management reasons, it would help if madvise(MADV_HUGEPAGE) returned an error instead of silently succeeding. Alternatively, documenting this limitation would save users from debugging phantom performance differences.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗