| The article is from 2018 and has had interesting discussion here before [1]. My conclusion is: In production, in a datacenter, when code is stable and compute-per-dollar efficiency matters? Yeah, sure, I can believe that swap makes sense. On a dev machine? Not on mine for sure. If you think swap is a net positive on a dev machine, then try pasting the following (wrong) code in a bash prompt on Linux: echo '
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
for (int i = 0; ; i++) {
char *mem = malloc(1 << 30);
if (mem == NULL)
return 0;
memset(mem, 42, 1 << 30);
printf("%5d GiB\n", i);
}
}
' | cc -O3 -o crash_my_laptop -x c -
./crash_my_laptop
We can discuss the results in a couple of hours, when you recover control of your machine.
(Note: with no swap and no z-ram, it crashes after 10 seconds; no side effects.)[1] https://news.ycombinator.com/item?id=40582029 https://news.ycombinator.com/item?id=39650114 https://news.ycombinator.com/item?id=38263901 https://news.ycombinator.com/item?id=31104126 https://news.ycombinator.com/item?id=29159755 https://news.ycombinator.com/item?id=23455051 https://news.ycombinator.com/item?id=16145294 https://news.ycombinator.com/item?id=16109058 |
> We can discuss the results in a couple of hours, when you recover control of your machine. (Note: with no swap and no z-ram, it crashes after 10 seconds; no side effects.)
That might be true for this contrived example. But my real-world experience is exactly the opposite.
In a case of memory over-usage (in my case because of working in a huge bazel project and several browsers open + some electron apps):
- without swap, the system at one point just got immediately so incredibly slow, that the only thing I could reasonably still do was to restart my machine, while
- with swap, the system (at higher memory usage) just got noticably slower and I could close some app / the browser to get into the normal usable regime again.