How to Change the Swappiness Value in Linux

When memory pressure rises, Linux must choose between reclaiming cached file pages and moving inactive anonymous pages to a configured swap area. That swap area can be a disk-backed partition, a swap file , or a compressed RAM device such as zram.
Swappiness is the Linux kernel setting that influences this choice by assigning a relative cost to swap I/O and filesystem paging. Lower values treat swap as more expensive, while higher values treat it as cheaper.
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
| Task | Command |
|---|---|
| Check current swappiness | cat /proc/sys/vm/swappiness |
| Check via sysctl | sysctl vm.swappiness |
| Set swappiness temporarily | sudo sysctl vm.swappiness=10 |
| Set swappiness permanently | Add vm.swappiness=10 to /etc/sysctl.d/99-swappiness.conf |
| Apply sysctl changes | sudo sysctl --system |
| See which swap devices are active | sudo swapon --show |
Checking the Swappiness Value
To check the current swappiness value on your system, use the following cat
command:
cat /proc/sys/vm/swappinessThe default swappiness value on most Linux distributions is 60:
60Another command you can use to check the swappiness value is sysctl
:
sysctl vm.swappinessvm.swappiness = 60Changing the Swappiness Value
Swappiness is not a percentage, and it is not a switch that turns swapping on and off. The kernel treats it as the relative cost of swap I/O compared to filesystem I/O. On kernels 5.8 and newer, the value ranges from 0 to 200, and 100 is the break-even point where the kernel assumes that swapping a page out and reading a file page back in cost the same. Values below 100 tell the kernel that swap is the more expensive option, and values above 100 tell it that swap is cheaper than going back to the filesystem.
The default of 60 biases the kernel toward dropping file-backed pages before it swaps anonymous memory, which is a reasonable compromise when swap lives on a disk.
Before kernel 5.8 the upper limit was 100. On an older kernel, such as the 5.4 series in Ubuntu 20.04, writing a larger value fails. Run uname -r if you are not sure which kernel you are on.
Here is what the range looks like in practice:
- 0 - the kernel avoids swapping for as long as possible and only starts once free and file-backed pages drop below the zone high watermark.
- 10–30 - light swapping, recommended for desktops and workstations where responsiveness matters.
- 60 - the default, suitable for most general-purpose systems.
- 100 - swap I/O and filesystem I/O are treated as equally expensive.
- 133–180 - swap is treated as cheaper than filesystem paging, a range worth testing when zram or zswap is faster than filesystem I/O.
Accessing swap on a disk is much slower than accessing physical memory, so a lower swappiness value generally improves responsiveness on desktop systems backed by a swap partition or swap file.
| Workload | Starting range |
|---|---|
| Desktop / workstation with disk swap | 10–15 |
| General server | 30–60 |
| Database server (MySQL, PostgreSQL) | 1–10 |
| Systems with fast NVMe swap | 20–40 |
| Systems using zram or zswap | 100–180 |
These values are starting points, not fixed recommendations. The optimal value depends on your workload, available RAM, and swap device. 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
:
sudo sysctl vm.swappiness=10This change takes effect immediately but will be lost after a reboot.
Verify the change took effect:
sysctl vm.swappinessvm.swappiness = 10Change Swappiness Permanently
To make the change persistent across reboots, create a dedicated sysctl drop-in file instead of editing the main configuration file directly:
sudo nano /etc/sysctl.d/99-swappiness.confAdd the following line:
vm.swappiness=10Save the file and apply the change without rebooting:
sudo sysctl --systemYou 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.
Checking How Much Swap Is in Use
Swappiness matters when the system is under memory pressure and has active swap, so it is worth looking at the current state before and after a change. The quickest way is the free
command:
free -h total used free shared buff/cache available
Mem: 15Gi 6.2Gi 1.1Gi 412Mi 8.4Gi 8.5Gi
Swap: 4.0Gi 128Mi 3.9GiThe Swap row shows 4 GiB of swap with only 128 MiB in use, so the kernel has barely touched it. Lowering swappiness on a machine in this state will not produce a visible difference, because there is still memory available and the kernel is not under pressure to reclaim anything.
To see which devices provide that swap space, run swapon:
sudo swapon --showNAME TYPE SIZE USED PRIO
/swapfile file 4G 128M -2The PRIO column matters once more than one swap device is active, because the kernel fills higher priority devices first. For a wider view of memory usage, see our guide on checking memory usage in Linux
.
Swappiness on Systems With zram
The advice to lower swappiness assumes that swap lives on a disk, and that assumption no longer holds everywhere. Fedora has enabled a zram swap device by default since Fedora 33, and Pop!_OS configures one during installation. zram is a compressed block device that lives in RAM, so swapping to it costs a compression pass rather than a disk write.
You can tell the two apart from the swapon output. A zram-backed system looks like this:
NAME TYPE SIZE USED PRIO
/dev/zram0 partition 4G 0B 100Because reading a page back from zram is often cheaper than reading an evicted page from the filesystem, values above 100 can make sense. A value of 10 may cause the kernel to reclaim file cache that the workload will soon need again, but the result depends on the workload and storage.
The kernel documentation gives a formula for choosing a value: if swap I/O is on average twice as fast as filesystem I/O, set swappiness to 133, which is two thirds of the 200-point scale. To test that value without making it persistent, run:
sudo sysctl vm.swappiness=133The change lasts until the next reboot. Run your usual workload and compare memory pressure, swap activity, and responsiveness before deciding whether to keep it.
Pop!_OS provides one distribution-specific example. Its zram service uses zstd compression and applies a swappiness of 180 with vm.page-cluster=0 only after creating its zram device. The service applies these values at runtime instead of storing them in a generic sysctl drop-in, so they are not left active if the service is disabled.
The vm.page-cluster setting controls how many pages the kernel reads back from swap in one attempt. It is a logarithmic value, so 0 means a single page and the default of 3 means eight pages. Pop!_OS uses 0 with zstd, but this value should not be copied based only on the presence of a zram device.
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.
Setting a value above 100 fails
The 0 to 200 range arrived in kernel 5.8. On anything older, the maximum is 100 and a larger value is rejected with sysctl: setting key "vm.swappiness": Invalid argument. Check the running kernel with uname -r and stay at 100 or below on those systems.
Swappiness value has no visible effect
Swappiness changes the balance between reclaiming file-backed pages and swapping anonymous pages under memory pressure. If the system is not under memory pressure, changing the value may not produce a visible difference.
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 and on where swap lives. For a desktop with disk swap, 10 to 15 is a common starting range. For a database server, start between 1 and 10 and monitor memory pressure. On a system that swaps to zram, values above 100 are worth testing when swap I/O is faster than filesystem paging. The default of 60 is a reasonable starting point for general servers.
Can the swappiness value be higher than 100?
Yes, on kernel 5.8 and newer. The range was extended to 200 so that the setting can describe systems where swap is faster than the filesystem, such as zram and zswap. On older kernels, 100 is still the maximum.
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.
What swappiness should I use on Linux Mint?
Linux Mint uses a disk-backed swap file or partition rather than zram, so the desktop guidance applies: set vm.swappiness=10 in /etc/sysctl.d/99-swappiness.conf and run sudo sysctl --system. Run sudo swapon --show first to confirm there is no /dev/zram0 entry.
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?
No, 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
Use sysctl vm.swappiness=N for a temporary change, and /etc/sysctl.d/99-swappiness.conf with sudo sysctl --system for a permanent one. Before you copy the familiar advice to drop the value to 10, run sudo swapon --show and check what is backing your swap. On a machine that swaps to zram, values above 100 may be worth testing.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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