To be clear, I don’t blame the poster of this comment at all for the content of their post – this is accepted as “common knowledge” by a lot of Linux sysadmins and is probably one of the most likely things that you will hear from one if you ask them to talk about swap. It is unfortunately also, however, a misunderstanding of the purpose and use of swap, especially on modern systems.

You are viewing a single thread.
View all comments View context

I’ve run Arch without swap for many years without issues. The key of course is that you need enough RAM for what you are trying to do with your computer.

There’s no reason why a 32GB RAM + 0GB swap system should have more problems than a 16GB RAM + 16GB swap system with the same workload. If anything, the former is going to run much better.

I run a lot of VMs; I typically run 2 at the same time in addition to running other programs in the background, my usecase is more eccentric than most users in the Linux space which is already pretty niche

What is finicky about a swap file?

It’s just this:

mkswap -U clear --size 4G --file /swapfile
swapon /swapfile

Done

I’m using BTRFS with LUKS-based Full Disk Encryption, the last time I used swapfiles with BTRFS with FDE it was in 2019 and it was painful to say the least, I rememeber spending several weeks scouring Stack and the Arch forums in order to get it to work properly.

  • usecases and preferences will differ from user to user, so I wouldn’t advise assuming a one-size-fits-all solution

If anything it’s way easier to create a file in your filesystem than having to (re-)partition your drive to have a swap partition. Much more flexible too if you want to change your swap configuration in the future.

swapfiles are great in that you can resize them at will, however after trying all 3 options I found myself questioning when would I even want to resize swap for a single system, so at a certain point I felt that swapfiles were more of a gimmick cause again you don’t really want to depend on swap if can.

  • if you’re consistently reaching your physical memory limits, upgrading your ram will most likely be the best bet for both system stability and hardware durability
permalink
report
parent
reply
2 points

I run a lot of VMs; I typically run 2 at the same time in addition to running other programs in the background, my usecase is more eccentric than most users in the Linux space which is already pretty niche

If what you’re doing involves using close to all of your system memory, it does make sense to add swap. So your use case is a good example actually.

I also have an old Arch PC that I use to run various VMs on (currently 6 VMs in use). It does have a swapfile, but the most swap I’ve ever seen in use is about 1GB.

I’m using BTRFS with LUKS-based Full Disk Encryption, the last time I used swapfiles with BTRFS with FDE it was in 2019 and it was painful to say the least, I rememeber spending several weeks scouring Stack and the Arch forums in order to get it to work properly.

Weird. Sounds like you may have painted yourself a bit into a corner by using BTRFS then. I use trusty old ext4 on top of LUKS FDE, no issues with swapfiles whatsoever.

That brings me to another downside of swap partitions: encryption. You can leak sensitive data through your swap partition, so it should be encrypted. If you use a plain partition, without LUKS in between, information in your swap is exposed. So you need to do more configuration to setup LUKS on your swap partition.

If you use a swapfile on an already encrypted filesystem though, you don’t have to worry about it.

when would I even want to resize swap for a single system

Maybe your requirements change (e.g. “I want to be able to hibernate”), maybe your memory configuration changes, maybe you’ve underestimated or overestimated how much swap you need.

Case in point: the Arch PC I mentioned above only uses upto 1GB of swap, but it has a 16GB swapfile. This discussion has brought to my attention that perhaps I should downsize the swapfile a bit and free up disk space.

you don’t really want to depend on swap if can

That is my position too. It’s always better to have a properly sized system, or limit what you push on an existing system. High swap usage rarely results in a good experience.

permalink
report
parent
reply

Linux

!linux@programming.dev

Create post

A community for everything relating to the linux operating system

Also check out !linux_memes@programming.dev

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

Community stats

  • 2.7K

    Monthly active users

  • 456

    Posts

  • 3.2K

    Comments