Is docker shm-size subject to deploy memory limits
Answer a question
I'm using docker and docker-compose to conduct a few performance tests on a Postgres instance. I've read somewhere that the /dev/shm mounted inside the container is a separate space from the host's one. I can't seem to find any explanation on how does that relate to the memory limits set on the container.
Minimal example follows:
version: "3.9"
services:
postgres:
image: postgres:14
shm_size: '2gb'
deploy:
resources:
limits:
memory: '24gb'
Will the container use:
- up to 24gb (2 for shm and remaining 22 for applications in the container)
- up to 26gb (2 for shm from a separate pool, deducted from the host and 24 for the app)
- ? some other scenario
Answers
TLDR: With cgroupsv2 --memory will also take into account the size of /dev/shm.
On cgroupsv2 the size of contents inside /dev/shm get added to /sys/fs/cgroup/memory.current
Thus the --memory flag applies to ram used by the container + the contents inside /dev/shm.
Also a post to reference (using cgroupsv1 tho) https://www.sobyte.net/post/2022-04/k8s-pod-shared-memory/
Example:
podman run -it --entrypoint /bin/bash --shm-size=3GB --memory=512MB -v /tmp:/tmp1 bash
dd if=/dev/random of=/dev/shm/test bs=1024 count=102400
#total system free mem -100MB
dd if=/dev/random of=/dev/shm/test bs=1024 count=1024000
#total system free mem -400MB+write_error (or crash)
更多推荐



所有评论(0)