ECI pods default to 64 MiB of shared memory, which is insufficient for workloads that use /dev/shm for inter-process communication or large in-memory buffers. Mount a memory-backed emptyDir volume to /dev/shm to increase the available shared memory beyond this limit.
How /dev/shm works in ECI pods
/dev/shm is a tmpfs-backed directory that provides fast, memory-based storage for inter-process communication. Deep learning frameworks, databases, and multi-process workloads use it to share large data buffers between processes.
Kubernetes sets /dev/shm to 64 MiB by default, and this limit cannot be changed through standard Kubernetes configurations. Run df -h inside a pod to confirm the default size:
:/$ df -h
Filesystem Size Used Avail Use% Mounted on
overlay 30G 4.1G 26G 14% /
tmpfs 64M 0 64M 0% /dev
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/vda4 30G 4.1G 26G 14% /etc/hosts
overlay 8.8G 5.0G 3.5G 59% /etc/hostname
shm 64M 0 64M 0% /dev/shm
tmpfs 4.0G 12K 4.0G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs 2.0G 0 2.0G 0% /proc/acpi
tmpfs 2.0G 0 2.0G 0% /sys/firmware
To raise this limit, mount a memory-backed emptyDir volume at /dev/shm. Setting medium: Memory and a sizeLimit on the volume replaces the default 64 MiB tmpfs with a tmpfs of your chosen size.
Mount an emptyDir volume at /dev/shm
Keep the following in mind before configuring a larger /dev/shm:
Data is not persisted.
/dev/shmstores data in memory. All data is lost when the container restarts.The volume counts against the pod's memory limit. Writing to
/dev/shmconsumes the same memory pool as the container's processes. If the combined memory usage of the processes and the/dev/shmdata exceeds the container's memory limit, an OOM error occurs.
-
Create a file named
emptydir-shm.yamlwith the following configuration.vim emptydir-shm.yamlThe configuration sets
medium: MemoryandsizeLimit: 256Mion the emptyDir volume and mounts it at/dev/shm, increasing the pod's shm size to 256 MiB.apiVersion: apps/v1 kind: Deployment metadata: name: test labels: app: test spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: name: nginx-test labels: app: nginx alibabacloud.com/eci: "true" spec: containers: - name: nginx image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2 ports: - containerPort: 80 volumeMounts: - mountPath: /dev/shm name: cache-volume volumes: - emptyDir: medium: Memory sizeLimit: 256Mi name: cache-volume -
Create the Deployment.
kubectl create -f emptydir-shm.yaml -
Verify the result.
Connect to the container and run
df -h. The/dev/shmrow should show 256 MiB.shell@Alicloud:~$ kubectl get pod NAME READY STATUS RESTARTS AGE test-765f78d484-68wg9 1/1 Running 0 44m shell@Alicloud:~$ kubectl exec -it test-765f78d484-68wg9 -- bash root@test-765f78d484-68wg9:/# df -h Filesystem Size Used Avail Use% Mounted on overlay 30G 4.1G 26G 14% / tmpfs 64M 0 64M 0% /dev tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 256M 0 256M 0% /dev/shm /dev/vda4 30G 4.1G 26G 14% /etc/hosts overlay 8.8G 4.9G 3.5G 58% /etc/hostname tmpfs 4.0G 12K 4.0G 1% /run/secrets/kubernetes.io/serviceaccount tmpfs 1.9G 0 1.9G 0% /proc/acpi tmpfs 1.9G 0 1.9G 0% /sys/firmware