[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.
1 file changed
tree: 8700c7b0a3a71d91629c7857bf36b6faaed49064
  1. .github/
  2. testing/
  3. .gitignore
  4. add-custom.sh
  5. add-version.sh
  6. docker-entrypoint.sh
  7. Dockerfile-ubuntu.template
  8. generator.sh
  9. LICENSE
  10. README.md
README.md

flink-docker / dev-master

Building a custom docker image

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.

  1. Compress Flink in flink/flink-dist/target/flink-1.11-SNAPSHOT-bin: tar czf flink-1.11.tgz flink-1.11-SNAPSHOT
  2. Copy the compressed distro to this project's root: cp flink/flink-dist/target/flink-1.11-SNAPSHOT-bin/flink-1.11.tgz flink-docker
  3. Start web server docker run -it -p 9999:9999 -v `pwd`:/data python:3.7.7-slim-buster python -m http.server 9999
  4. Generate Dockerfile ./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)
    • If you want to build the docker image inside Minikube, then you have to specify the resolved host.minikube.internal which you can look up via minikube ssh "cat /etc/hosts".
  5. Generate docker image (in flink-docker/dev/flink-1.11-debian): docker build -t flink:1.11-SN .
  6. Run custom Flink docker image: docker run -it flink:1.11-SN jobmanager