Linux handles low memory situations just fine, but it's much
better if you
have an appropriately sized swap partition and let the kernel do its job
No, by default Linux can hang at low memory condition. Huge swap space will not help you
if a leak occurs. With a large swap space, the hang can happen later, but it can still
happen. Another point is that the swap space is slow. With fast leaks and slow swap space,
freezing is possible throughout the entire swap filling time. A typical problem:
"once all the ram is used up the whole system freezes as swap starts getting full,
but really the whole system is completely locked-up. I thought my swapfile was too small
so I made it match my ram (12 GB) but the system still gets frozen" [1].
If you didn't mean for the program to use as much memory as it
tried to, the
correct solution would be to use cgroups.
1. This is not configured by default.
2. This can be inconvenient even for advanced users.
3. Quick leaks can happen unexpectedly.
[1]
https://github.com/hakavlad/nohang/issues/85#issue-564348496