To swap, or not to swap

yes swapfile is reliable. main advantage is probably that you can easily resize the file

1 Like

This is necessary if you wish to hibernate a PC, hence it's the default.

This provides some leeway in the case of RAM exhaustion without having so much that the PC grinds to a halt when trying to swap out 16 or 32GB of RAM.

It's use-case dependent.

Do you want to hibernate your PC? If so, you need swap to fit your RAM. Otherwise, if you have "a lot" of RAM then much less swap space will do fine.

3 Likes

I've not seen any horror stories, or positive reports. To suggest it is ready for general consumption.

I hadn't planned to use hibernate, on my rig. But its proved useful.

Especially when I have been interrupted, i.e answer door etc, taking longer than I thought, or side tracked several times, to that, where was I, moment.

Disk (sda) space is not a factor, any more, I also have 2Tb SSHD (sdb) with two partitions for data back up and Timeshift. 32Gb of ram, the mobo gives the option to increase to 64Gb, I doubt I will need that much. Yet fondly remember my underpowered lappies 2Gb of ram being swamped, almost daily. lol.

Apart from a cursory look through the BIOS of my rig to disable hibernate mode, the machine is running sweetly. So, left as is.

Do you want to hibernate your PC? If so, you need swap to fit your RAM. Otherwise, if you have "a lot" of RAM then much less swap space will do fine.

I'm accessing my future options, currently swap tops this list.

I have tried smaller swap partitions in the past, generally there were no problems, but occasionally the lappy or my older rig (Haswell model) would freeze up. Then it expired a few weeks after fitting another 16GB ram. It was configured with 32Gb ram, 8Gb swap partition and swappiness at 5 and pressure cache at 50. Hey ho thats life.

Exactly what kind of positive reports do you expect from people using a swap file?

1 Like

I take it you do not favour this method.

A swap partition or a file is really, really slow when it is being accessed. There is nothing positive to report about either even when everything is working.

They both work the same in my experience. Actually no I have never used a swap partition. Only a swap file. But I do not currently use swap.

Something more fun to play with is zswap and zram. systemd-swap makes it easy.

1 Like

Yes. It is very mature.

Just make sure your filesystem supports it.

Yes ! /swapfile : fstab | SOLUTION : systemd-swap ! Thank You all!

systemd-swap creates swap space when needed.

2 Likes

just a minor correction, kernel.org says otherwise

(https://www.kernel.org/doc/Documentation/power/interface.txt)

so should work even if swap if smaller then ram (and not all ram used?), but I dont have any experience with hibernation so maybe I'm wrong

(arch wiki: https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#About_swap_partition/file_size)

2 Likes

Yes, but swap partitions should be faster than swap files (no underlying filesystem overhead), and are IMHO preferable to swap files.
I don't use either, but prefer zram, or on low RAM devices, swap partition+zswap.

As I use hibernation from time to time, I can only confirm that this is true. My laptop has 16 GB of RAM, but swapfile is only about 7 GB. Still, it hibernates and wakes without any problem. Sure thing, it's likely to fail to do so if over 10 GB of ram would be consumed at the moment of initiation of hibernation. But I'm not going to do things this way. For me, hibernation is just a better way to save an extra battery juice in case I know I would need it.

1 Like

Interesting. That would mean there's compression happening, which would make sense.

I think I'd still err on the side of having enough swap for the full RAM just in case. If image_size is "best effort" it won't always compress RAM into 2/5 of the space and a 4GB laptop running Firefox and Thunderbird is already getting towards filling its RAM.

1 Like

In theory sure, but when a system is swapping heavily, reaction time is in the tens of thousands of milliseconds, so "faster" might not mean much at that point. Swap files are more convenient and flexible, so if the user only intends to use it for "just in case" scenarios, I think swap files are probably better.

For low memory systems that expect to use swap frequently, swap partitions are probably better.

1 Like

I find it much easier to either create a swap partition (you don't have to use it, swapon/swapoff) or even better, leave a small empty space on your HDD/SSD which can also serve as space for a backup OS.
It's true though that both are rather slow and in the end it doesn't matter all too much.
zram is a good alternative if you don't need a lot of swap space.

2 Likes

swap might be needed if you have 4GB of ram. That if you plan to compile some large programs/software.

It is probably best to have enough ram to avoid using swap at all. Of that will depend on budget and the amount of memory your system can accept.

16GB seems top be the sweet spot for most users, but YMMV.

What's the greatest advantage?

  • Swap partition: If the storage is filled, the swap won't.
  • Swap file: If the swap is filled it will be scaled till needed.

You can always add swapfiles to the system. You can even add one with a lower priority and use it as an overflow, but if you're filling your swap you have a different issue.

1 Like

Could that be interesting to have?

Forum kindly sponsored by