1

I'm using t1.micro EC2 instance with Amazon Linux. Since the micro instance has limited RAM (589MB RAM in total), it is insufficient for many operations such as installing & compiling Python packages. Some tutorials suggest me to make use of a Swap file to increase performance, as follow:

sudo fallocate -l 1G /tmp/swapfile
sudo chmod 600 /tmp/swapfile
sudo mkswap /tmp/swapfile
sudo swapon /tmp/swapfile

and remove it by:

sudo swapoff /tmp/swapfile
sudo rm /tmp/swapfile

I think this will increase Disk I/O, but it will benefit the overall performance. Should I enable a large swap file when the OS is booted up & leave it always active? If yes, how to achieve this?

FYI: the output of the free -m command is as follow:

[ec2-user@myhostname ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:           589        340        249          0         13         97
-/+ buffers/cache:        229        360
Swap:            0          0          0
1

Create a swap space by:

sudo dd if=/dev/zero of=/tmp/swapfile bs=1M count=1024 
    (# bs*count = file size)

sudo mkswap /tmp/swapfile

sudo chmod 600 /tmp/swapfile
    (# for security reasons)

sudo swapon /tmp/swapfile

free -h

Remove by:

swapoff /tmp/swapfile

rm -f /tmp/swapfile
  • The main question is, should I do so? I have already listed out how to make swap file in my question. – Raptor May 29 '17 at 7:36
  • 2
    Yes,if you need more space to run programs – FrontENG May 29 '17 at 7:38
  • Apart from increased Disk I/O, is there any drawbacks by doing so? – Raptor May 29 '17 at 7:55
  • The only way is to switch to an instance with more ram. – FrontENG May 29 '17 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.