Okay, why does `swapoff` exist on Linux? It's completely useless as far as I can tell. It's been running for 24h to swap in like 1.5GB of used swap or so, on a largely idle server with >32GB free RAM. How can it be *this* hilariously inefficient?
Conversation
Replying to
It iterates through the swapped pages one by one and in the worst case it has to walk through the page tables for every process to look for the uses of the page. It would often be far more efficient to walk through the page tables a single time, but it doesn't know how to do it.
1
1
8
There's a swap cache to track the pages in swap efficiently, but if they're not cached, dealing with them is incredibly expensive. The way it works is especially horrific with a modern SSD or even more so with in-memory swap like zram. You're really far better off just rebooting.
Usually, reading in the pages from swap is triggered by a page fault, so it already has the metadata to deal with the page and doesn't need to find it. They don't bother storing any metadata with the pages to deal with them quickly because it's not needed for the normal usage.
1
2
There could probably be a swapoff scheduler iterating through page tables and keeping a read queue full while also optimizing the order. It just isn't implemented, and there's no way they're going to sacrifice performance elsewhere in order to do any better than that approach.
1
6
Show replies

