Linux: how to explicitly unswap everything possible?
Solution 1:
I'd recommend allowing the normal Linux memory control swap in the things that are actually used, as they are used.
The only thing I can think off is to turn swap off, then on again
sudo swapoff -a
sudo swapon -a
That assumes you have enough spare physical memory to contain everything in swap...
Solution 2:
You can tune it echoing some number between 0 to 100 into /proc/sys/vm/swappiness
.
This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase agressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.
The default value is 60.
Solution 3:
Linux does a fine job managing memory and you shouldn't stand in its way. The vm.swappiness setting (mentioned previously) doesn't get in its way. You're more likely to experience odd issues doing things any other way.
What did you launch that was so memory hungry? Can it be tuned? If it doesn't have it's own memory limit directives you can look at ulimit as well.
Solution 4:
If you have the memory available for all your applications, it is ok to set the swappiness to 0 so things won't swap out. For example, qemu-kvm is a big target the VMM to get swapped out, because it "appears" to be idle most of the time. I've see up to 80% of the memory of a qemu-kvm memory get written to swap. The VMs running in qemu-kvm will become near-unresponsive because they are running out of swap (although the guest has no idea this is happening). The guest VM will think it's performing most excellently, even though in truth it is dragging along terribly. When I bunch of VMs "wake up" and start doing things, it can spike the load average up to over 30, even on enterprise grade hardware with ample fast memory and disk. I guess this is a failing in the out-of-the-box qemu-kvm design.
Hope this helps someone.