Add Swap in CentOS

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.

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.

Now, the memory should be extended by 1G. And I successfully re-compile the software.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">