How to Change the Swappiness Value in Linux

By 

Updated on

4 min read

Change Swappiness in Linux

Swap space is a part of the hard disk that is used when the RAM memory is full. The swap space can be a dedicated swap partition or a swap file .

When a Linux system runs out of physical memory, inactive pages are moved from the RAM to the swap space.

Swappiness is a Linux kernel setting that controls how aggressively the kernel moves memory pages from RAM to swap. A higher value increases swapping, while a lower value keeps pages in RAM for longer.

This article explains how to check and change the swappiness value in Linux, both temporarily with sysctl and permanently with a persistent sysctl configuration.

Quick Reference

TaskCommand
Check current swappinesscat /proc/sys/vm/swappiness
Check via sysctlsysctl vm.swappiness
Set swappiness temporarilysudo sysctl vm.swappiness=10
Set swappiness permanentlyAdd vm.swappiness=10 to /etc/sysctl.d/99-swappiness.conf
Apply sysctl changessudo sysctl --system

Checking the Swappiness Value

To check the current swappiness value on your system, use the following cat command:

Terminal
cat /proc/sys/vm/swappiness

The default swappiness value on most Linux distributions is 60:

output
60

Another command you can use to check the swappiness value is sysctl:

Terminal
sysctl vm.swappiness
output
vm.swappiness = 60

Changing the Swappiness Value

Swappiness can have a value between 0 and 100:

  • 0 — the kernel avoids swapping for as long as possible and only uses swap when there is no other option.
  • 10–30 — light swapping, recommended for desktops and workstations where responsiveness matters.
  • 60 — the default, suitable for most general-purpose systems.
  • 80–100 — aggressive swapping, suitable for systems where swap throughput is more important than latency.

Accessing swap memory is much slower than accessing physical memory. A lower swappiness value generally improves system responsiveness on desktop systems.

WorkloadRecommended value
Desktop / workstation10–15
General server30–60
Database server (MySQL, PostgreSQL)1–10
Systems with fast NVMe swap20–40

The optimal value depends on your workload and available RAM. Adjust in small increments and monitor performance after each change.

Change Swappiness Temporarily

To set the swappiness value at runtime without a reboot, use sysctl as root or with sudo :

Terminal
sudo sysctl vm.swappiness=10

This change takes effect immediately but will be lost after a reboot.

Verify the change took effect:

Terminal
sysctl vm.swappiness
output
vm.swappiness = 10

Change Swappiness Permanently

To make the change persistent across reboots, create a dedicated sysctl drop-in file instead of editing the main configuration file directly:

Terminal
sudo nano /etc/sysctl.d/99-swappiness.conf

Add the following line:

/etc/sysctl.d/99-swappiness.confsh
vm.swappiness=10

Save the file and apply the change without rebooting:

Terminal
sudo sysctl --system

You can still use /etc/sysctl.conf, but a dedicated file in /etc/sysctl.d/ is easier to maintain and less likely to be replaced during upgrades.

Troubleshooting

Change does not survive a reboot
The sysctl vm.swappiness=N command sets the value only for the current session. To make it permanent, add vm.swappiness=N to a file such as /etc/sysctl.d/99-swappiness.conf and run sudo sysctl --system.

Permission denied when running sysctl
Changing kernel parameters requires root privileges. Prefix the command with sudo, or switch to root with sudo -i first.

Swappiness value has no visible effect
Swappiness influences when swapping starts, not whether it happens at all. If your system has plenty of free RAM, the kernel will not swap regardless of the swappiness setting. The effect is most visible when RAM usage is high.

Value resets after an update or upgrade
Some system packages replace /etc/sysctl.conf during upgrades. Use a dedicated drop-in file instead: create /etc/sysctl.d/99-swappiness.conf with the line vm.swappiness=10. Drop-in files are preserved across upgrades.

FAQ

What is the best swappiness value for Linux?
It depends on the workload. For a desktop, 10–15 reduces unnecessary swapping and improves responsiveness. For a database server, 1–10 keeps data in RAM. The default of 60 is a reasonable starting point for general servers.

What does swappiness 0 mean?
A value of 0 tells the kernel to avoid swapping as long as possible — but it does not disable swap entirely. The kernel will still use swap if it runs out of RAM. To disable swap completely, run sudo swapoff -a.

How do I check the swappiness value in Ubuntu?
Run cat /proc/sys/vm/swappiness or sysctl vm.swappiness. Both work on Ubuntu, Debian, Fedora, and other Linux distributions.

Will changing swappiness improve performance?
On systems with sufficient RAM, lowering swappiness can reduce disk I/O caused by unnecessary swapping, which improves responsiveness. On systems with very little RAM, swapping is inevitable and the value has less impact.

Do I need to reboot after changing swappiness?
Not if you use sudo sysctl vm.swappiness=N — the change takes effect immediately. To also persist it across reboots, add vm.swappiness=N to /etc/sysctl.d/99-swappiness.conf and run sudo sysctl --system.

Conclusion

Lowering swappiness from the default of 60 to 10 is a common tuning step for desktop systems and database servers. Use sysctl vm.swappiness=N for a temporary change, and /etc/sysctl.d/99-swappiness.conf with sudo sysctl --system for a permanent one. For related memory management, see the swap file guide .

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page