How to Configure Swappiness and Swap on Fedora

Adjust how aggressively Fedora uses swap space by tuning the `vm.swappiness` kernel parameter and, optionally, adding a swap file when physical RAM is limited.

Story / scenario

You have 32 GB of RAM installed, but your laptop still stutters when you switch between a heavy IDE and a dozen browser tabs. You check the system monitor and see swap usage climbing. You assume the machine is running out of memory. The reality is often simpler. The kernel is moving data to swap faster than you want, or you are missing swap entirely and the OOM killer is terminating your workflow. Fedora defaults to a compressed swap device called zram, which changes how you think about memory management. This article covers how to tune swappiness, add disk swap, and work with zram so your system behaves the way you expect.

What's actually happening

Swappiness controls the kernel's preference for swapping anonymous pages out of RAM. The value ranges from 0 to 200. The default on Fedora is 60. A lower value tells the kernel to keep pages in RAM longer. A higher value encourages the kernel to move pages to swap sooner. The number is not a percentage of memory usage. It is a weighting factor in the kernel's reclaim algorithm.

Fedora Workstation enables zram by default. zram creates a compressed block device in RAM. The kernel treats this device like swap, but the data stays in memory, compressed. This avoids disk I/O latency. On modern hardware, compression is often faster than writing to an SSD. The trade-off is CPU usage for compression and decompression. If your CPU is already saturated, zram might add overhead. Disk swap is slower but frees up RAM entirely.

Check zramctl before changing swappiness. If zram is active, disk swap is a secondary fallback.

Check the current configuration

Here's how to inspect your current swap setup and swappiness value.

# Show current swappiness value
cat /proc/sys/vm/swappiness

# Show active swap devices and their priorities
swapon --show

# Show zram device details if present
zramctl

The swapon --show output lists every active swap device. The PRIO column indicates priority. Higher numbers mean the kernel uses that device first. zram usually gets a high priority, like 100. Disk swap should have a lower priority so the kernel prefers zram.

Run zramctl first. If you see a device like /dev/zram0, Fedora is using compressed swap. You do not need to create a swap file unless you require hibernation or have a specific workload that benefits from disk swap.

Adjust swappiness

Here's how to change the value temporarily to test the effect.

# Apply new swappiness value immediately for testing
sudo sysctl vm.swappiness=10

A value of 10 is common on desktop systems with plenty of RAM. It keeps the working set in memory while still allowing the kernel to swap under pressure. A value of 60 is balanced. A value of 100 forces the kernel to swap aggressively, which can help latency-sensitive applications by keeping hot data in RAM and pushing cold data out.

Setting swappiness to 0 does not disable swap. It just tells the kernel to avoid swap unless absolutely necessary. The kernel will still swap if memory is exhausted. To disable swap entirely, use swapoff.

Make the swappiness change permanent.

# Write config to drop-in directory so it survives reboot
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf

# Reload sysctl to apply without reboot
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

Files in /etc/sysctl.d/ are user-modified. Files in /usr/lib/sysctl.d/ ship with packages. Always edit /etc/. Manual edits to /usr/lib/ get overwritten on updates.

Reboot before you debug. Half the time the symptom is gone after a clean boot with the new settings.

Add a swap file

Fedora Workstation uses btrfs by default. btrfs compresses files by default, and swap cannot be compressed. You must disable compression on the swap file. Use dd or truncate with chattr +C. Do not use fallocate. fallocate creates a preallocated file that btrfs compresses, which breaks swap.

Here's how to create a swap file safely on btrfs.

# Create a 2 GiB file filled with zeros
# Use dd instead of fallocate because fallocate fails on btrfs
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress

# Disable compression on the swap file for btrfs compatibility
# This prevents the filesystem from compressing the swap data
sudo chattr +C /swapfile

# Set permissions so only root can read/write the swap file
sudo chmod 600 /swapfile

# Set up the file as a swap area
sudo mkswap /swapfile

# Enable the swap file
sudo swapon /swapfile

Set priority to prefer zram.

# Set priority lower than zram so zram is preferred
# zram usually gets priority 100, so 10 ensures disk is secondary
sudo swapon -p 10 /swapfile

Make the swap file persistent.

# Append fstab entry to mount swap on boot with priority
echo '/swapfile none swap sw,pri=10 0 0' | sudo tee -a /etc/fstab

Set the priority before you reboot. If disk swap has higher priority than zram, you lose the performance benefit of compression.

Verify it worked

Here's how to confirm the swap file is active and the priority is correct.

# Verify swap devices and priorities
swapon --show

# Check total memory and swap usage in human-readable format
free -h

Look at the PRIO column in swapon --show. The zram device should have a higher priority than the swap file. If the priorities are wrong, the kernel might use disk swap first, causing latency spikes.

Run journalctl -xe if you suspect memory pressure. Look for Out of memory messages. If you see those, your system is running out of RAM. Swappiness tuning helps manage pressure, but it cannot create more memory.

Read the actual error before guessing. journalctl -xe shows the context around the failure.

Common pitfalls

If you run sudo swapon /swapfile and see swapon: /swapfile: swapon failed: Invalid argument, you likely created the file with fallocate on a btrfs filesystem. btrfs compresses files by default, and swap cannot be compressed. Use dd or truncate with chattr +C to disable compression.

If you see swapon: /swapfile: swapon failed: Operation not permitted, check the permissions. The swap file must be owned by root and have mode 600. Run sudo chmod 600 /swapfile.

If you add disk swap and your system becomes slower, check the priority. Disk swap should have a lower priority than zram. If disk swap has higher priority, the kernel writes to disk instead of compressing in RAM.

Swappiness 0 does not disable swap. It just makes the kernel very reluctant. Under memory pressure, it will still swap. To disable swap, use swapoff -a. Disabling swap entirely can cause the OOM killer to terminate processes more aggressively.

Read the error message. "Invalid argument" on swapon almost always means filesystem incompatibility or wrong permissions.

Tune zram

Fedora uses zram-generator to set up zram at boot. The generator reads configuration from /etc/systemd/zram-generator.conf. You can adjust the fraction of RAM used for zram or the compression algorithm.

Here's how to tune zram size and algorithm.

# /etc/systemd/zram-generator.conf
[zram0]
# Use 50% of total RAM for zram
zram-size = ram / 2

# Use zstd for better compression ratio
# zstd is slower than lz4 but saves more RAM
compression-algorithm = zstd

Edit the generator config, not sysctl. zram size is managed by systemd, not vm.swappiness. The zstd algorithm is often better than lz4 on modern CPUs. It provides higher compression ratios, which means more effective swap space. The CPU overhead is usually acceptable.

Reboot to apply zram changes. The generator runs at boot.

When to use this vs alternatives

Use swappiness 10 when you have ample RAM and want to minimize disk I/O on desktop workloads.

Use swappiness 60 when you are running a mixed workload and want the kernel to balance memory pressure evenly.

Use swappiness 100 when you are running a database server with large datasets and want to force the kernel to swap aggressively to keep hot data in RAM.

Use zram when you are on a laptop or SSD-based system and want swap performance without disk wear.

Use disk swap when you need to hibernate the system or when RAM is extremely limited and compression overhead is too high.

Use a swap file when you need flexible sizing and are on a modern Fedora installation with LVM or btrfs.

Use a swap partition when you are managing legacy storage layouts or require strict separation of swap from the root filesystem.

Trust the package manager. Manual file edits drift, snapshots stay.

Where to go next