How to Check and Configure Swap Space Priorities in Linux Terminal

When physical RAM becomes depleted, the Linux kernel relies on swap space—either designated swap partitions or swap files—to store inactive anonymous memory pages. If your workstation or server features multiple storage drives (such as an ultra-fast NVMe SSD alongside a secondary SATA SSD or a mechanical hard drive), Linux by default assigns swap priorities in chronological order of activation. Knowing how to query and configure swap priorities ensures that the Linux kernel actively pages memory to your fastest storage media first, falling back to secondary drives only when high-speed swap space is fully exhausted.

Understanding Linux Swap Priority Architecture

Swap priorities operate on a defined numerical scale from -1 down to -32768 for default unassigned devices, and from 0 up to 32767 for manually assigned priorities:

  • Higher Numbers Equal Higher Priority: Linux always allocates pages to the swap area with the highest numerical priority value. A swap space assigned priority 10 will be filled completely before Linux writes a single byte to a swap area assigned priority 1.
  • Equal Priorities Enable Striping (RAID 0 Behaviour): If you assign two or more swap devices the exact same priority value (for example, two separate NVMe SSD drives both set to priority 10), the Linux kernel interleaves page writes across both devices in a round-robin fashion, significantly boosting combined swap I/O throughput.
  • Automatic Negative Priorities: If no priority is explicitly set, the kernel assigns negative integers beginning with -2, decrementing by one for each subsequent swap area activated.

How to View Current Swap Priorities

You can audit the active swap devices and their corresponding priority rankings using swapon:

swapon --show=NAME,TYPE,SIZE,USED,PRIO

Alternatively, inspect the kernel’s live virtual memory proc file:

cat /proc/swaps

The resulting table displays the device or filename path, storage type (partition or file), total size, current consumption, and the active Priority integer.

Configuring Swap Priority Temporarily with swapon

If you are activating a temporary swap file or testing performance, use the -p (priority) flag with swapon:

  1. Turn off the swap device if it is currently mounted:
    sudo swapoff /dev/nvme0n1p2
  2. Reactivate the device while specifying your target priority value:
    sudo swapon -p 100 /dev/nvme0n1p2
  3. Activate a secondary, slower backup swap file on an HDD with a lower priority:
    sudo swapon -p 10 /swapfile_hdd
  4. Verify the assignment by running swapon --show. The NVMe partition will display priority 100, ensuring the kernel exhausts its capacity before touching the HDD swap file.

Persisting Swap Priorities Across Reboots in /etc/fstab

To ensure your custom swap hierarchy survives system reboots, configure the priority parameter within your filesystem table (/etc/fstab):

  1. Open /etc/fstab in a text editor with root privileges:
    sudo nano /etc/fstab
  2. Locate your existing swap entries. By default, they typically specify sw or defaults under the fourth (options) column.
  3. Append pri=<value> to the options column, separated by a comma. For example:
    # Fast NVMe Swap (Primary)
    UUID=3b8a1e2f-4c5d-6e7a-8b9c-0d1e2f3a4b5c  none  swap  sw,pri=100  0  0
    
    # Slower SATA Swap (Secondary Fallback)
    /swapfile_sata                              none  swap  sw,pri=50   0  0
    
    # Mirrored High-Speed Striped Swap (Equal Priority)
    /dev/nvme0n1p3                              none  swap  sw,pri=100  0  0
  4. Save and exit the text editor (in nano, press Ctrl + O then Ctrl + X).
  5. Test and apply the changes immediately without restarting:
    sudo swapoff -a && sudo swapon -a
  6. Confirm your new persistent priorities with swapon --show.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.