[FLINK-39924] Size jemalloc narenas from container CPU allowance Apache Flink containers load jemalloc via LD_PRELOAD but don't configure narenas. jemalloc's default is 4 * ncpus, where ncpus is read from /proc/cpuinfo, the host CPU count, not the container's CPU limit. In CPU limited pods on large hosts this over-provisions arenas and causes RSS fragmentation, since each arena holds dirty pages for dirty_decay_ms before releasing them to the OS. Determine the effective CPU count from the cgroup CPU quota directly (cpu.max for v2, cpu.cfs_quota_us / cpu.cfs_period_us for v1), since nproc honors cpuset but not CPU quotas. Fall back to nproc when no quota is set. Skip the override entirely when the user has supplied narenas in MALLOC_CONF, and append narenas to any other user-supplied MALLOC_CONF value.
The commands shown during these steps serve as an example and assume that you have checked out flink and flink-docker in the same folder and version 1.11. Please substitute your folder structure and version.
flink/flink-dist/target/flink-1.11-SNAPSHOT-bin: tar czf flink-1.11.tgz flink-1.11-SNAPSHOTcp flink/flink-dist/target/flink-1.11-SNAPSHOT-bin/flink-1.11.tgz flink-dockerdocker run -it -p 9999:9999 -v `pwd`:/data python:3.7.7-slim-buster python -m http.server 9999Dockerfile ./add-custom.sh -u http://localhost:9999/data/flink-1.11.tgz -n flink-1.11 (If you are on a Mac or Windows, use host.docker.internal instead of localhost)host.minikube.internal which you can look up via minikube ssh "cat /etc/hosts".flink-docker/dev/flink-1.11-debian): docker build -t flink:1.11-SN .docker run -it flink:1.11-SN jobmanager