A lot of ram. Do I need a swapfile?

Hi guys. I have a 20GB of ram, and 4GB of swapfile. Do I need swapfile if I have a lot of free ram? Maybe be better to delete it from root partition and fstab?

4 Likes

Check your RAM and swap usage:

free -m; swapon -s; zramctl
7 Likes

This all depends on your use case - I think only you can answer that question. If you system never uses more than 75 or 85% of your RAM, then you don’t need a swap file.

As @vgaetera said, Fedora now has zram enabled (see Changes/SwapOnZRAM - Fedora Project Wiki) - so you have a compressed RAM drive that can act as swap.

If you are not shy of storage, it doesn’t hurt to leave the 4 GB swapfile there as long as the priority is swapping on zram.

7 Likes

Actually, disk/file swap can hurt and lowering its priority might not help if some process goes nuts eating all available memory.

2 Likes

I always add it anyway even with 32gb ram. Its not likely that you will miss the few GB used and it can help avoid the system locking up. Usually I notice the system slow down when it starts to swap so I can kill something.

3 Likes

Thanks for answers, everyone, who wrote something in this topic!

4 Likes

Which is where lowering the precedence of swapping (or reducing the swappiness) comes handy.

1 Like

Priority/swappiness can help if you are working on the verge of free RAM.
It cannot help in a situation described above.

1 Like

I think it can. When I am copying files (or usually doing any kind of file operation like saving to file or reading from file), there’s some kind of swankiness which I get to observe. I immediately open up htop and find activity in the swap partition even when my RAM is not even half full.

Reducing swappiness would allow increased preference to using RAM and not swap partition even in those circumstances when there’s ample amount of physical memory in disposal but still somehow swap is picked and used just because it is a file operation.

1 Like

Enable disk swap and try to launch a task which requires huge amount of RAM.
Your other tasks should start swapping, and even if there’s zram, it’s going to be filled up, so swapping continues to disk negatively impacting system responsiveness.

1 Like

Yes, yes. I have observed this even when I am copying a great tons of small-sized files.

1 Like

Swap file/partition is usefull for hibernate too (copy ram into swap, so swap size = ram size), but if you don’t use this feature, you don’t really need swap in most case.

A lot of people (including me) recommends to decrease swapiness kernel parameter to 10 instead of disabling totally swap.

2 Likes

I am running fedora 33 with 32G ram. The only swap I use is the 4G zram it sets up by default in memory. It is a desktop to I don’t need to hibernate or suspend. If I did it would require swap >= memory.

Something I do too when not using a ZRAM.