Increasing Swap on Linux (Debian)

?
R
Bash

Basic recipe to increase swap on Debian Linux based OS. Rules: Max Size: 4GB, Recommended Size: = or x2 the amount of RAM Based on: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04

1# Sanity check on memory and disk levels
2sudo swapon --show
3free -h
4df -h
5
6# Create the swapfile
7sudo fallocate -l 2G /swapfile
8ls -lh /swapfile
9sudo chmod 600 /swapfile
10ls -lh /swapfile
11sudo mkswap /swapfile
12sudo swapon /swapfile
13
14# Sanity check again
15free -h
16sudo swapon --show
17
18# Keep Swap File permanent
19sudo cp /etc/fstab /etc/fstab.bak
20echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
21
22# Change swapiness value to as low as you can, also cache_pressure should drecrease
23cat /proc/sys/vm/swappiness
24sudo sysctl vm.swappiness=30
25sudo sysctl vm.vfs_cache_pressure=50
26
27# Make swapiness persist
28sudo nano /etc/sysctl.conf
29vm.swappiness=30
30vm.vfs_cache_pressure=50

Created on 5/15/2018