← Back to context

Comment by hackingonempty

9 hours ago

> If you need a little breathing room, just use a swapfile.

You should always use a swap file/partition, even if you don't want any swapping. That's because there are always cold pages and if you have no swap space that memory cannot be used for apps or buffers, it's just wasted.

I always thought I had to add a swap file to avoid crashing with OOM. I wasn't aware of the cold pages overhead.

Sometimes that crashing is what I want: a dedicated server running one (micro)service in a system that'll restart new servers on such crashes (e.g. Kubernetes-alike). I'd rather have it crash immediately rather than chugging along in degraded state.

But on a shared setup like OP shows, or the old LAMP-on-a-vps, i'd prefer the system to start swapping and have a chance to recover. IME it quite often does. Will take a few minutes (of near downtime) but will avoid data corruption or crash-loops much easier.

Basically, letting Linux handle recovery vs letting a monitoring system handle recovery