Shared Memory

Overview

There are two types of shared memory objects in Linux: System V and POSIX. The containers in a pod share the IPC namespace of the pod infrastructure container and so are able to share the System V shared memory objects. This document describes how they can also share POSIX shared memory objects.

POSIX Shared Memory

POSIX shared memory requires that a tmpfs be mounted at /dev/shm. The containers in a pod do not share their mount namespaces so we use volumes to provide the same /dev/shm into each container in a pod. The following example shows how to set up POSIX shared memory between two containers.

shared-memory.yaml

  1. ---
  2. apiVersion: v1
  3. id: hello-openshift
  4. kind: Pod
  5. metadata:
  6. name: hello-openshift
  7. labels:
  8. name: hello-openshift
  9. spec:
  10. volumes: (1)
  11. - name: dshm
  12. emptyDir:
  13. medium: Memory
  14. containers:
  15. - image: kubernetes/pause
  16. name: hello-container1
  17. ports:
  18. - containerPort: 8080
  19. hostPort: 6061
  20. volumeMounts: (2)
  21. - mountPath: /dev/shm
  22. name: dshm
  23. - image: kubernetes/pause
  24. name: hello-container2
  25. ports:
  26. - containerPort: 8081
  27. hostPort: 6062
  28. volumeMounts: (3)
  29. - mountPath: /dev/shm
  30. name: dshm
1specifies the tmpfs volume dshm.
2enables POSIX shared memory for hello-container1 via dshm.
3enables POSIX shared memory for hello-container2 via dshm.

Create the pod using the shared-memory.yaml file:

  1. $ oc create -f shared-memory.yaml