by PhilipRoman · 2y ago · 0 comments
I've seen a lot of tools getting this wrong, even earlyoom which, AFAIK only measures memory and swap usage, but not the sustained rate of swapping. My computer can run just fine with all of it's swap used while ram is half empty.
Any implementation of overcommit is inherently unstable and susceptible to a "bank-run" situation, adding or removing swap will not change that. If you want a robust system, preallocate memory for everything and set limits via cgroups.
Memory that is swapped out is a small write operation, which generally is much more resource and wear intensive than a read; a program memory page and disk cache page are not equivalent.
Additionally, the swapped out program memory may be required again and cause an unpredictable delay in program operation; when a user has to wait for a menu to open while it is swapped back in that is suboptimal use of memory.
A modern operating system should have compressed memory rather than swap. Take the pages that would be swapped out for being rarely accessed, if they compress well then free the page and store it in an area for compressed pages. This will get most of the expanded cache benefit from swap without delays, wear, or possibility of the system grinding to a halt.