Post

increase swap memory

increase swap memory

increase swap memory of raspberry pi & Debian-based distros


  • all steps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
free -h # check the amount of swap memory

sudo nano /etc/dphys-swapfile   # edit this file

CONF_SWAPSIZE=200   #  find this line 

CONF_SWAPSIZE=1024  #  change from 200 into 1024

CTRL + X, then Y and Enter  # to Save and exit 

sudo dphys-swapfile swapoff  # Disable current swap

sudo dphys-swapfile setup    # Apply new swap size

sudo dphys-swapfile swapon   # Enable new swap

free -h # check if the swap size has increased

step by step

  • check the amount of swap memory
    1
    
    free -h
    

  • edit this file
    1
    
    sudo nano /etc/dphys-swapfile
    

  • find this line
    1
    
    CONF_SWAPSIZE=200
    

  • change from 200 into 1024
    1
    
     CONF_SWAPSIZE=1024 
    
  • Save and exit with
  • (CTRL + X, then Y and Enter)

  • Disable current swap
    1
    
     sudo dphys-swapfile swapoff 
    

  • Apply new swap size
    1
    
     sudo dphys-swapfile setup
    

  • Enable new swap
    1
    
     sudo dphys-swapfile swapon
    

  • check if the swap size has increased
    1
    
    free -h
    

Increase Swappiness (Use Swap More Frequently)

  • Swappiness controls how aggressively Linux swaps memory to disk. A higher value makes the system use swap more often, which can help when RAM is limited

*Check Current Swappiness (Default is usually 60.)

1
cat /proc/sys/vm/swappiness

  • Set Swappiness to 80
1
sudo nano /etc/sysctl.conf

  • Add this line at the bottom
1
vm.swappiness=80

  • Save and exit, apply changes
1
CTRL + X, then Y and Enter 

  • apply changes
1
sudo sysctl -p

This should help your Raspberry Pi run smoother with more available virtual memory


This post is licensed under CC BY 4.0 by the author.