I’ve been seeing this odd phrase, swap file, ever since I installed EOS and joined this forum; I’d never heard of it before and only know swap partitions. Now I’m wondering what the differences really are - and no, obviously I don’t mean the difference between a file and a partition in general; I’m curious as to when one would choose a swap partition, when a file.
Any recommended reading (novice to intermediate level), any personal experiences?
As for my own machines, both have swap partitions the exact same size as the amount of memory, but barely use any of it as I never use hibernation. I could probably shrink them to a few hundred megs
As for swap size, this is entirely dependent on how much memory your system has and how much you consume with your system applications and workflow. Have you come remotely close to running out of memory? If not a relatively small swap file will probably do.
With systems having more memory these days than most people use, swap size = memory size is a bit out dated.
There’s a ton of technical differences, but IMO, it comes down to:
If you have a tendency to install and remove ram, and use hibernate, swapfile is a lot easier than swap partition. If you double your ram, with a swapfile you delete the existing, recreate it as double the size, remake it into swap, and change some UUID’s in files. Done. With a partiton, you need to boot from external media, resize a partition from somewhere to get this extra space, possibly move partitions around to put the free space beside the swap partition, then extend the partition. Major hassle, IF you can even shrink anything to get the space. This is, and was, my primary reason for switching from swap partition to swap file back when I still used HDD’s.
RAM is always cleared on power-off, -> hibernation works nonetheless (if there is some physical swap to store the contents to).
I played around with zram settings on my first install of systemd-swap to benchmark against the default zswap settings and am pretty sure that hibernation works in both cases. But, this was quite some time ago, so I wouldn’t swear on it .
The swap-on-zram will have higher priority, thus being favored over drive based swap and I’m pretty sure that if you have two swaps: swap-on-zram, and swap-on-drive, the kernel is smart enough to know it can’t hibernate to a zram device, and will instead use drive based swap.