Live data from Hacker News

Stop making swap partitions—use swap files instead

gist.github.com

141–150 of 257 posts

Re: Stop making swap partitions—use swap files instead

#141

For a while since RAM sizes have gotten so big I would set up linux servers without swap at all. I figured what is a 2GB swap file going to do if the system has already exhausted 128GB of real RAM? I never saw any issues doing this, but I learned that linux ideally wants some swap space, which it will use for some kind of housekeeping stuff.

I have tried to forego swap because I had hoped that it would avoid swap thrashing, where performance goes into the toilet; I'd rather a process was killed but I could still access the system, than be unable to login to it. But I've found that even with no/little swap, the system can get into high memory pressure situations (even easier because it can't swap out unused pages of libraries and the like), and still go i…

Read only pages (most of libraries and binaries) get “paged out” to the file they came from, not swap.

(They obviously don’t page out, they are just discarded and read again when needed)

Re: Stop making swap partitions—use swap files instead

#144
post #103

Earlier quoted context omitted.

or use the system's oom ?

All I want is the oomkiller to always kill firefox. Somehow that's very difficult to achieve.

The oom killer is a monkey with a gun. It’s a last resort when you were going to crash (or worse, hang) anyway.

You should have a much better “plan A” to avoid this situation.

Re: Stop making swap partitions—use swap files instead

#145

Remember when distros used complicated partition setups, one for /root, one for /var one for /home, a swap partition etc. Was always a bad choice because one of them would be at 99% while others would linger below 10% For swap, the best advice is to disable swap on your desktop, unless <8GB RAM. Really, I've never needed it and you probably won't either.

Id always suggest at least 2-4G of swap even if you have plenty of memory 32g+ because for that rare edge case where you'd really not want to OOM.

Yep. Swap + zswap + earlyoom is a great safety need incase things get hairy.

Re: Stop making swap partitions—use swap files instead

#146

Earlier quoted context omitted.

On x64 CPU for laptops the memory bandwidth is rather limited and a fast compressor like lz4 can saturate it. As the result latest SSD are faster then z-ram when using hardware encryption on SSD.

If you care about performance you shouldn't be running from swap period. Swap is just a safety net.

It's OK to care about the performance of the safety net, too.

Re: Stop making swap partitions—use swap files instead

#147

[flagged]

Also, this seems to be based on a email from 2005, about kernel version 2.4 and 2.6, and their differences. Things might have changed since then, and also depends on a lot of factors, not the least what filesystem you use. I'm not sure people should seriously follow advice that basically boils down to "do this always it's best".

Better instead to make yourself informed about the tradeoffs, then make your own choice, for your setup.

Re: Stop making swap partitions—use swap files instead

#148

Earlier quoted context omitted.

On x64 CPU for laptops the memory bandwidth is rather limited and a fast compressor like lz4 can saturate it. As the result latest SSD are faster then z-ram when using hardware encryption on SSD.

If you care about performance you shouldn't be running from swap period. Swap is just a safety net.

Swap is required for hibernation. And with fast ssd or properly tuned zram/zswap one can run task that use 10%-20% more memory than installed RAM. Surely there is a slowdown, but it is not that big especially when SSD can read write more than 5GB/s.

Re: Stop making swap partitions—use swap files instead

#150
I've always thought it a bizarre and unusual "requirement" that swap gets an entire partition. Windows has it as a file too. At least with this approach, if you change the amount of RAM in your computer, you don't need to go resize the swap partition if you want them to match.
Post reply on HN