Fastest way to add swap memory

in #witness-category6 years ago

Swap space in Linux is used when the amount of physical memory (RAM) is full. When the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. Swap Memory can be very useful for Steem and EOS node administrators as it can prevent your server from crashing.

I recommend using at least 1gb of Swap Memory, specially if you have a fast SSD drive. So, one of the first things I do when I set up a server is run this little script that installs 1gb of RAM in a couple of seconds.

First, create a file called swap.sh:

sudo nano swap.sh



Then paste this code inside it:

cd
sudo fallocate -l 1G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -h
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf



Exit nano editor with Ctrl X and save it with Y, then make the file executable:

chmod 755 swap.sh



Run the script with:

sudo ./swap.sh



The output should look something like this:

Captura de pantalla 2018-04-19 a la(s) 10.07.40.png

And thats it, you are all set with your new swap space.

Code in Gist

Sort:  

You got a 34.38% upvote from @dailyupvotes courtesy of @hcf27!

Please upvote this comment to support the service.

Many thanks for these recommendations will be very useful, I already speak to my brother to see it to activate this new space. Greetings and a big hug.

Agree, I always setup swap this way, no need to make a separate partition anymore, performance is not an issue, specially if you have ssd, but also with the usual sata hdd. Regards!

Swap space in Linux is used when the amount of physical memory (RAM) is full.

Linux may use swap at any time without RAM being full.

Yes, I believe that this command adjusts how often the swap file should be used, setting a low swappiness will try to avoid it as much as possible. I like to set it to 10.

sudo sysctl vm.swappiness=10

Again gift valuable post..this post really very important for all steemians.. I like your post and good thought..i appreciate overall.. Thanks to sharing for your good post of witness catagory.. Very well done.. Dear... Friend.. @chitty

Excellent post...A swap is a derivative contract through which two parties exchange financial instruments. These instruments can be almost anything, but most swaps involve cash flows based on a notional principal amount that both parties agree to. Usually, the principal does not change hands..........

nice try... dictionary bot!

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64485.37
ETH 3156.53
USDT 1.00
SBD 4.05