6 ms·
Yes, that is quite a strange recommendation and the recommendation of "until the swap space used exceeds twice the physical RAM" is really crazy. The best reco
by seiji 11y ago
Yes, that is quite a strange recommendation and the recommendation of "until the swap space used exceeds twice the physical RAM" is really crazy. The best recommendation for production servers is to disable your swap/page file completely then just let your entire system crash on OOM.
Often times it's better to have a dead system (you do have HA and auto-failover, right?) than to let difficult-to-track-down "slowness" into real time systems.
- Dylan16807 11y agoIf your failover doesn't take extreme slowdowns into account, you've still screwed up. It's more complicated than just turning off swap. Even without swap, when you run extremely low on memory the page cache will be squeezed to nothing and you'll thrash. And I don't think there's a way to set a minimum page cache on Linux. So in other words, I would not rely on the OOM killer ever kicking in. In a situation with more memory use over time a small swap can act as a canary, letting you know you're nearing a performance drop, while a swapless server could suddenly hit a molasses wall without dying.
- aidenn0 11y agoThrashing the page cache is typically much less horrible than swap thrashing, so swap off is still an improvement. If you want a canary, why not just directly monitor the page cache size?
- Dylan16807 11y agoI suppose it depends how big your binaries are, but once those are getting culled from memory things are not pretty. Keep in mind that if your swap is not huge, it will very often fill will cold data and you won't have swap thrashing despite running out of memory. Good point about measuring the page cache directly.
- aidenn0 11y agoAh yes. We can agree that both small swap and no swap are superior to the "2x RAM" nonsense that still pops up as a recommendation though.
- codewaffle 11y agoIt's always a fun time when a process eats all your memory, your machine crashes, and failover launches it on another identical machine (only to repeat the process)
- brian_cunnie 11y agoThe recommendation (swap == 2 x RAM) was more common in the nineties when RAM was much more expensive. It was a reflection that the resident set size (RSS) of a process is often a fraction of its Virtual Memory footprint (often an order of magnitude smaller), so a process could run effectively even with most of its data swapped out to disk. There was a fair amount of interesting engineering to make swap effective.. For example, for the code (text) segment, which was read-only, you'd use the file itself (e.g. a.out) as the swap for the text (code) portion, and if you'd try to `rm a.out` while it was running, you'd get a "text file busy error".