Today when I tried to compile an opensource software in my DigitalOcean VPS, I encountered a weird problem: every time when I ‘make’ it, the command ends with error message “Killed”. However, I didn’t press “CTRL+C” all the time. Then I keyed in command ‘top’ and I saw ‘gcc’ used up my memory! So I decided to add a swap file to enlarge my memory. Since DigitalOcean uses SSD for storage. Swap won’t make system “too slow”.
First, check how much space that is still available in my server.
Next, we add a file for swap.
dd if=/dev/zero of=/myswap bs=1024 count=1024k
This command means we copy 1024k blocks from /dev/zero to /myswap. Size of a single block is 1024 bytes. By the way, /dev/zero is a file with infinite large size. You can copy unlimited ‘0’ from there.
Then we make that file as our swap file.
#you should see your swap file "myswap" here if you succeed
#let it automatically mounted when system starts
#in this file, append the following line at the end of the file
#/myswap swap swap defaults 0 0
#give appropriate privilege
chown root:root /myswap
chmod 0600 /myswap
Now, the memory should be extended by 1G. And I successfully re-compile the software.