(toiminnot)

hwechtla-tl: Configuring on-disk swap for fedora 33

Kierre.png

Mikä on WikiWiki?
nettipäiväkirja
koko wiki (etsi)
viime muutokset


Background

Fedora 33 doesn't use on-disk swap by default. Instead, it configures a zram device to compress memory when it's low (see https://fedoraproject.org/wiki/Changes/SwapOnZRAM). I find this very questionable.

Why?

Because for me the point of swap was never to extend the memory for an actively used memory workload. The point of swap is to have a place where to store memory that is not actually actively used - to avoid worrying whether you're filling your memory with all those processes that just sit there (and /tmp, also). Having everything in RAM means that all that crap doesn't have anywhere to go to. For instance, it means that if some stupid program leaves data in your /tmp (assuming it's on tmpfs), that data will consume central memory from useful stuff until /tmp is cleaned up. "Useful stuff" includes all processes that are actively using their memory, but also files (such as shared libraries) that are being used a lot and thus are cached in memory.

You can probably guess that I disagree with the change's rationale ("Swap is useful, except when it's slow").

I noticed that there's very little documentation available for those who would like to use real, disk-based swap on F33. I also noticed that while the user can request on-disk swap at installation (it's just not there by default), it's configured in a suboptimal way (see https://www.reddit.com/r/Fedora/comments/jpp7nm/zram_and_swap_partition_fedora_33/gbj57pg/?utm_source=reddit&utm_medium=web2x&context=3). Basically, when you run out of in-memory swap, there's no way to evict stuff from that swap to disk swap, so the in-memory swap just sits there eating precious memory.

How?

The easiest way to use on-disk swap is to configure a swapfile. I think you will need a swap partition for hibernate and kernel core dumps to work, but let's suppose you're not interested in those. F33 ships with btrfs by default, so you need to do an extra chattr for the swapfile.

# SIZE_IN_GB=16   # example, change
# touch /swapfile
# chmod 600 /swapfile
# chattr +C /swapfile
# dd if=/dev/zero of=/swapfile bs=1024 count=$(($SIZE_IN_GB * 1024 * 1024))
# mkswap /swapfile
# swapon /swapfile
# systemctl stop swap-create@zram0.service

That configures the swap for you temporarily. You can see the list of swaps and total swap by:

# swapon
# free

To make the changes permanent (so that it's done the same way in the next boot), you need to:

# echo /swapfile swap swap defaults 0 0 >> /etc/fstab
# echo -e '[zram0]\nhost-memory-limit=0' > /etc/systemd/zram-generator.conf



Pikalinkit:


kommentoi (viimeksi muutettu 12.04.2021 10:49)