3 ms·
This rule of thumb is outdated by two decades. The proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workloa
by man8alexd 8mo ago
This rule of thumb is outdated by two decades.
The 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.
- tremon 8mo agoThat's not useful as a rule of thumb, since you can't know the size of "all inactive anonymous pages" without doing extensive runtime analysis of the system under consideration. That's pretty much the opposite of what a rule of thumb is for.
- man8alexd 8mo agoYou are right, it is not a rule of thumb, and you can't determine optimal swap size right away. But you don't need "extensive runtime analysis". Start with a small swap - a few hundred megabytes (assuming the system has GBs of RAM). Check its utilization periodically. If it is full, add a few hundred megabytes more. That's all.
- ZoomZoomZoom 8mo agoIt's not like it's easy to shuffle partitions around. Swap files are a pain, so you need to reserve space at the end of the table. By the time you need to increase swap the previous partition is going to be full. Better overcommit right away and live with the feeling you're wasting space.
- man8alexd 8mo agoExactly opposite. Don't use swap partitions, and use swap files, even multiple if necessary. Never allocate too much swap space. It is better to get OOM earlier then to wait for unresponsive system.
- ZoomZoomZoom 8mo agoSwap partition is set and forget. Can be detected by label automatically, never fails. Swap file means fallocating, setting extended attributes (like `nocow`), finding file offset and writing it to kernel params, and other gotchas, like btrfs not allowing snapshotting a subvolume with an active swap file. Technically it's preferable, won't argue with that.
- direwolf20 8mo agoHast thou discovered our lord and savior LVM?
- rascul 8mo ago> Swap files are a pain Easier than partitions: mkswap --size 2G --file swap.img swapon swap.img
- ZoomZoomZoom 8mo agoYeah, until you need to hibernate to one. I understand that calculating file offsets is not rocket science, but still, all the dance required is not exactly uninvolved and feels a bit fragile.