Hacker News new | ask | show | jobs
by sid0 5910 days ago
> Insisting on using fixed swap partitions made sense twenty years ago, but it sure as hell doesn't today as long as you do GC.

The main advantage of using fixed swap partitions is that you don't have to go through the file system to access swap. This is why swap files used to be slower on Linux with the 2.4 series of kernels -- with 2.6 and swap files, the kernel builds a map to the LBA at startup for direct physical access, so there's no performance difference any more. Shame on Linux distros that still use swap partitions in 2010.

Windows does the same, which is why Windows doesn't need (and has never supported) swap partitions, either.

However, this sort of map implies that while increasing swap size is easy, reducing the size of swap files is really difficult while the system is online, which is why Windows (and I believe Linux) don't attempt to solve this problem.

1 comments

You can totally reduce the size of swap files on Linux, it's done the same way it is on OS X. It even has a nice syscall: swapoff(2) and a little utility that calls it swapoff(8) that comes with the standard util-linux package.

You create another new swapfile, turn it on, and then turn off the old one. The VM will copy all the old pages still in use in the old file and distribute them among the highest-priority enabled swaps with free space by round-robin. If you create the new swapfile sparsely, you don't even chew much disk space.

I discovered something hilarious in Linux's OOM-killer a while back. It has a bunch of heuristics for picking what process to kill next to save the rest: the very first one is "are any processes blocked in the swapoff syscall?"