Skip to content

Optimizing Swap with ZRAM on Raspberry Pi OS

By default, Raspberry Pi OS uses a swap file on the SD card, which can reduce performance and shorten the card's lifespan. ZRAM is a solution that creates a compressed swap partition in RAM, improving both performance and longevity.

1. Disable Default Swap Setting

sudo apt-get install chkconfig
sudo chkconfig dphys-swapfile off

2. Enable Swap on ZRAM

Load the ZRAM module:

sudo modprobe zram

Set a 128MB ZRAM swap space:

echo $((128*1024*1024)) | sudo tee /sys/zram0/disksize

Create and enable the swap:

sudo mkswap /dev/zram0
sudo swapon -p 10 /dev/zram0

With ZRAM enabled, your Raspberry Pi will benefit from faster swap performance and reduced SD card wear.

Enjoy optimizing your Raspberry Pi!