Increasing Swap File Size
Increasing Swap File Size
The following common scenarios encountered by stake pool operators may require increasing swap file size:
Running low on RAM for cardano-node processes
Checking slot leader schedule is crashing due to not enough RAM
Enabling zRAM
zRAM is a Linux kernel module that creates compressed swap devices on memory, allowing much faster access to data than a traditional swap using SSD or HDD devices.
To check whether zRAM is enabled:
In a terminal window, type:
cat /proc/swapsIf the output lists a filename containing the text zram then zRAM is enabled.
To install zRAM:
In a terminal window, type:
sudo apt install zram-configBy default, zRAM creates a swap device half the size of your real RAM. If needed, to customize zRAM configuration options type:
sudo nano /usr/bin/init-zram-swappingPress
CTRL+Sand then pressENTERto save changes that you made in step 2. PressCTRL+Xto exit the nano editor.Reboot the computer.
Increasing Disk Swap File Size
Here is an example to create a 12GB swapfile.
#Stop cardano-node first
sudo systemctl stop cardano-node
sudo swapoff /swapfile
#Verify swapfile is off
swapon --show
#12gb swapfile. Change if you wish.
sudo fallocate -l 12G /swapfile
#Verify swapfile exists
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
#Verify swapfile increased in size
swapon --show
#Restart cardano-node
sudo systemctl start cardano-node#Stop cardano-node first
sudo systemctl stop cnode
sudo swapoff /swapfile
#Verify swapfile is off
swapon --show
#12gb swapfile. Change if you wish.
sudo fallocate -l 12G /swapfile
#Verify swapfile exists
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
#Verify swapfile increased in size
swapon --show
#Restart cardano-node
sudo systemctl start cnodeAdjusting the Swappiness Parameter
The swappiness parameter defines how aggressively the Linux kernel swaps memory pages. Higher values increase the swapping of memory pages. Lower values decrease the amount of swap. Decreasing the amount of swap increases the aggressiveness of the Linux kernel in freeing up memory using other techniques when memory usage is high, including randomly killing processes. For details on adjusting the swappiness parameter appropriately for your system, see Tuning Your Swap Settings for example.