If you must use swap (you probably don't need to), then at least set zswap.enabled=1 in the kernel boot options, typically in grub. This will enable lzo compression of swap in memory so there is less writing to disk. Some newer kernels use lz4. Either way, what most folks are actually missing is the correct kernel settings for the amount of memory they have. Sadly, the kernel does not dynamically adjust these based o…
Linux Performance: Why You Should Almost Always Add Swap Space
31–40 of 120 posts
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#32I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?
Meaning the kernel will only swap to save the system.
I've been doing this for years and had no issues.
Edit: Actually in recent kernels, which I am using, 0 means it's disabled. I was thinking of 1.
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#33Yes! That is exactly what I want to happen!
When the system runs out of RAM, things will generally stop functioning, swap enabled or not. The only question is how you want it to stop functioning when that happens.
In almost every situation, I'll easily take the kernel killing whatever single process it thinks is most appropriate to get rid of, and keep everything else up and running smoothly, over grinding the the entire system to a halt by upping the effective memory access time by orders of magnitude.
Simply put: If everything doesn't fit in memory, then don't try to run everything!
Properly designed software nowadays is designed to be able to crash without corrupting data. As far as I'm concerned, it is almost always preferable to kill and restart instead of giving CPR to processes that don't fit in the working memory.
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#34Swap isn’t needed at all in this age. It’s just there for people who can’t afford more RAM and therefore have to resort to hacky solutions like this.
Do you use a laptop? I do and I'm using swap space right now. I would like to buy a laptop with 32 or 64 Gigs of RAM but I can't as most(all?) laptop makers don't ship with a memory controller that permits more than 16 Gigs of RAM. And I can afford to buy more RAM.
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#35I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#36Re: Linux Performance: Why You Should Almost Always Add Swap Space
#37What people often don't realise is that Linux distinguishes between dirty and clean memory, with dirty memory not reflected in swap, and clean memory already stored somewhere on disc, and program code is counted as clean memory that just happens to live somewhere other than swap.
Therefore, under memory pressure (especially if you set swappiness to zero), you will be preferentially swapping out your program code (because it is always clean) in preference to your program data. If you have no swap, then this is what causes the system to grind to a halt when the RAM is full- all your program code gets discarded from RAM, and nothing can run without reading it from disc again.
The recommendation to have a little bit of swap is absolutely fine. However, as the amount of RAM in your system increases, the penalty for running out of RAM increases as well. On larger systems (for example 256GB RAM), I recommend using something like EarlyOOM[1] to kill off tasks before the pathological swapping case occurs. Otherwise, you could end up with an unresponsive system. If you have lots of RAM, the kernel OOM killer waits far too late, and the system is already unresponsive.
Re: Linux Performance: Why You Should Almost Always Add Swap Space
#38I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?