Conversation

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?
11
61
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
8
Replying to and
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
Replying to and
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