GCC - VM Machine - allocate more /dev/shm memory

Viewed 509

I would like to start a VM on google cloud console with more memory in /dev/shm. Thing is the only way I've figured out how to do this is by passing somewhere the argument --shm-size to the docker run command. But I don't know where to do this when creating a VM instance with a specific docker image on Google Cloud Console. Any ideas ? Would it be possible to resize /dev/shm when while running the container ?

1 Answers

You can change size of /dev/shm while your VM instance is running (after VM creation) with a command sudo mount -o remount,size=8G /dev/shm, also you can use startup-script to apply this command during each boot. Please have a look on my steps below:

  1. create a VM instance (optional):
gcloud compute instances create instance-1 --zone=europe-west3-a --machine-type=e2-medium --image=ubuntu-2004-focal-v20210223 --image-project=ubuntu-os-c
loud
  1. SSH into the VM instance:
gcloud compute ssh instance-1 --zone=europe-west3-a
  1. change size of /dev/shm:
instance-1:~$ df | grep shm
tmpfs            2014932       0   2014932   0% /dev/shm
instance-1:~$ sudo mount -o remount,size=8G /dev/shm
instance-1:~$ df | grep shm
tmpfs            8388608       0   8388608   0% /dev/shm
  1. add a startup-script (optional):
#!/bin/bash
mount -o remount,size=8G /dev/shm
  1. restart the VM instance, SSH and check /dev/shm (optional):
$ gcloud compute ssh instance-1 --zone=europe-west3-a
instance-1:~$ df | grep shm
tmpfs            8388608       0   8388608   0% /dev/shm

Alternatively you can try to change /etc/fstab and create your custom image.

Related