Skip to main content

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

Note
Note

For a stake pool that you operate in the Mainnet environment, calculating the slot leader schedule for the current epoch may require a minimum of 16 GB combined memory and/or swap space in addition to the memory that Cardano Node may already use.

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:

  • Using a terminal window, type:
    cat /proc/swaps

If the output lists a filename containing the text zram then zRAM is enabled.

To install zRAM:

  1. Using a terminal window, type:
    sudo apt install zram-config
  2. By 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-swapping
  3. Press CTRL+S and then press ENTER to save changes that you made in step 2, and then press CTRL+X to exit the nano editor.
  4. Reboot the computer.

Increasing Disk Swap File Size

The following example creates a 12 GB swap file.

# Stop the Cardano Node instance
sudo systemctl stop cardano-node

# Disable swapping
sudo swapoff /swap.img

# Verify that swapping is off
swapon --show

# Remove the existing swap file
sudo rm /swap.img

# Create a new 12 GB swap file
# Edit the swap file size as needed
sudo fallocate -l 12G /swap.img

# Set permissions on the swap file
sudo chmod 600 /swap.img

# Verify that the swap file exists
ls -lh /swap.img

# Set up the swap file
sudo mkswap /swap.img

# Enable swapping
sudo swapon /swap.img

# Verify that the swap file increased in size
swapon --show

# Restart the Cardano Node instance
sudo systemctl start cardano-node

Adjusting 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.