4 ms·
For modern Linux servers with large amounts of RAM, my rule of thumb is between 1/8 and 1/32 of RAM, depending on what the machine is for. For example, one of
by kijin 1y ago
For modern Linux servers with large amounts of RAM, my rule of thumb is between 1/8 and 1/32 of RAM, depending on what the machine is for.
For example, one of my database servers has 128GB of RAM and 8GB of swap. It tends to stabilize around 108GB of RAM and 5GB of swap usage under normal load, so I know that a 4GB swap would have been less than optimal. A larger swap would have been a waste as well.
- man8alexd 1y agoThe proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens. Another rule of thumb is that performance degradation due to the active working set spilling into the swap is exponential - 0.1% excess causes 2x degradation, 1% - 10x degradation, 10% - 100x degradation (assuming 10^3 difference in latency between RAM and SSD).
- kijin 1y agoI would approach the issue from the other direction. Start by buying enough RAM to contain the active working set for the foreseeable future. Afterward, you can start experimenting with different swap sizes (swapfiles are easier to resize, and they perform exactly as well as swap partitions!) to see how many inactive anonymous pages you can safely swap out. If you can swap out several gigabytes, that's a bonus! But don't take that for granted. Always be prepared to move everything back into RAM when needed.
- ChocolateGod 1y agoI no longer use disk swap for servers, instead opting for Zram with a maximum is 50% of RAM capacity and a high swapiness value. It'd be cool if Zram could apply to the RAM itself (like macOS) rather than needing a fake swap device.
- cmurf 1y agozswap https://docs.kernel.org/admin-guide/mm/zswap.html https://docs.kernel.org/admin-guide/mm/zswap.html The cgroup accounting also now works in zswap.
- ChocolateGod 1y agoZswap requires a backing disk swap, Zram does not.
- cmurf 1y agoThe backing disk or file will only be written to if cache eviction on the basis of LRU comes into play, which is fine because that's probably worth the write hit. The likelihood of thrashing, the biggest complaint about disk based swap, is far reduced. zram based swap isn't free. Its efficiency depends on the compression ratio (and cost).
- LargoLasskhyfv 1y agoLookie lookie! Isn't it spooky? https://github.com/CachyOS/CachyOS-Settings/blob/master/usr/lib/udev/rules.d/30-zram.rules https://github.com/CachyOS/CachyOS-Settings/blob/master/usr/... Resulting in https://i.postimg.cc/hP37vvpJ/screenieshottie.png https://i.postimg.cc/hP37vvpJ/screenieshottie.png Good enough...
- ChocolateGod 1y agoYeh. I haven't yet figured out how to get zram to apply transparently to containers though, anything in another memory cgroup will never get compressed unless swap is explicitly exposed to it.