Home > Net >  Is docker shm-size subject to deploy memory limits
Is docker shm-size subject to deploy memory limits

Time:06-10

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

CodePudding user response:

how does that relate to the memory limits set on the container.

Doesn't.

Will the container use:

It will use as much as postgres:14 uses.

The amount of files that can be created inside /dev/shm directory will be limited to 2gb.

The amount of memory that processes in the container may allocate will be limited to 24gb.

These are separate limits. Just like you would run a process inside cgroup limited to 24gb and mount a tmpfs filesystem with size=2gb.

These are limits. Nothing will be allocated if there is no actual need.

  • Related