Home | Blog | How To Configure Swap Memory on Your Server
Rok Černec
Blockchain
Reading time: 3 min
Date: 7th Mar 2017

How To Configure Swap Memory on Your Server

If you are running a node with 1GB RAM, this can quickly be consumed by Ark processes so in order to provide some additional “power” we can configure swap partition that will act as a memory support in case our memory gets filled up. Best is if you have SSD drive as its much quicker than conventional old HDD drives. Also worth mentioning is that if you have a drive with only a few GB (eg. 10GB) don’t allocate too much for swap as this space will become reserved for swap so in case of 10GB allocate only 1–2 GB for swap, if you have drives with more (20GB,40GB,..) you can allocate 2–8GB of swap.

OK now to commands. First we need to check if you maybe already have swap file running and if you do you don’t need to configure it, else follow additional steps. Check with command : free -m

It should say something like: Swap: 0 0 0

If it does we first need to allocate space for swap drive with the command, where size is replaced by the amount of swap memory you want to have eg. 1G, 2G, 4G, 8G: sudo fallocate -l <size> /swapfile

our example: sudo fallocate -l 2G /swapfile

We will allocate 2GB for swap memory. Now we need to run some additional commands to configure and enable swap run this commands one after another: sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile

Now to make this swapfile “permanent” and not erased after server reboots we need to configure 1 additional file (we’ll run it in nano editor) by adding a line to it. Run: sudo nano /etc/fstab

A file will open move down to the last line and paste this at the end

/swapfile none swap sw 0 0

It should look like this:

After you paste the above line press CTRL+X , followed by pressing ‘Y’ and [enter] to rewrite current file. You are done!

Now we can confirm that swap is setup successfully with the same command: free -m

Swap file should now be set to the amount you decided to and will persist even on reboots:

Tweaking Swappiness

The swappiness is responsible for how often your system swaps data out of RAM to the swap space — default is set at 60, but we’d want that as low as possible so setting it to 0 is preferred with swap turned on to not have out of memory errors. You can check the current swappiness level with this command: cat /proc/sys/vm/swappiness

It will most likely return the value of 60. Now we need to change it to 0 with this command: sudo sysctl vm.swappiness=0

To change this permanently (else it won’t stick after you reboot) we need to modify one of the files, run: sudo nano /etc/sysctl.conf

File will open — move to the last line (empty) and paste this: vm.swappiness=0

Should look something like this:

CTRL+X to close, followed by ‘Y’ and [enter].

That’s it — you are done!

If you have any additional questions or problems don’t hesitate to join our Slack and one of the crew members or community members will gladly help you out!

ARK.io

Stay up to date
By submitting this form you agree to receive email updates. Find out how we process your data here.
Download
Visit our download page to learn more about our latest releases
2021 © ARK.io | All rights reserved An ARK.io Product