2

I am wondering, is there a syscall, or has this ever been discussed, to move memory pages from swap back to RAM, given there is enough free RAM? I am thinking of something like the infamous

swapoff -a
swapon -a

but in a safer fashion (if there is not enough RAM, don't move back the remaining pages) and possible only when the computer is idle.

I see the question "How do I get the memory content back into RAM" quite often, so I'm wondering if others have also thought about a more intelligent solution?

Possible use cases: An application uses up all RAM, resulting in the memory of the other apps being swapped out. After that application is terminated, there would be enough space in RAM again for the remaining applications. The user experience would greatly improve if their memory resides on a fast device when it needs to be accessed (no laggy behaviour), so it would be beneficial if the unswapping took place during the computer's idle time already. Prominent examples are window managers, desktop environments, browsers or other memory intensive applications.

3
  • 1
    mlock(2) should do that.
    – mosvy
    Aug 7 '19 at 14:22
  • You could use the application or access the data that's been swapped out. (If you're not accessing it why shouldn't it stay on swap?)
    – roaima
    Aug 7 '19 at 14:41
  • @roaima I edited the question to address a possible use case.
    – quazgar
    Aug 7 '19 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.