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.
1
1
10
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
In your scenario, are you also thinking on smaller, less scalable systems. Fx many mobile OS' cant rely on same conditjons like desktop and such more scalable systems. Not that i disagree on the swap issues.
1
Yes, it would work far better for most environments, particularly on mobile and embedded devices where traditional hard drives aren't in use. The current approach is awful. It's almost as if they designed it to read from a tape drive, but clearly the swap isn't on a tape drive.
1
2
Iterating *once* through the page tables and reading the pages in whatever order they end up being would be better on modern desktops / servers, mobile devices and embedded. Can do better than that by having a scheduler optimizing the order by spending CPU time to save I/O time.


