3 ms·
> RAM is not stressed: of the 1015MiB of RAM, 182MiB are free, and only 6MiB of swap is used. We typically don't worry about RAM on Linux systems until the sw
by dsr_ 11y ago
> RAM is not stressed: of the 1015MiB of RAM, 182MiB are free, and only 6MiB of swap is used. We typically don't worry about RAM on Linux systems until the swap space used exceeds twice the physical RAM
That's a bad metric. The question is rarely "does this machine use too much swap". The problem comes when performance is degraded because pages that were evicted out to disk are now needed again, and those processes wait for I/O. swapin and swapout are the relevant figures.
edit: (If you're only using 6M of swap, it doesn't really matter, of course. But if a system uses any substantial amount of swap, you want to check rate, not quantity.)
- deleted 11y ago[deleted]
- seiji 11y agoYes, 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".
- BrianCunnie 11y agoYou're absolutely correct. Time permitting, I may go back and adjust my description.
- brian_cunnie 11y agoYou're absolutely correct--amount of swap isn't as good a metric as how much it's stressed (how much is being swapped in/swapped out). Time permitting I may update the blog, and with your permission use your comment)