increase desktop responsiveness on linux while swapping
As far as I know this is not an issue specific to Linux, its the way that SWAP (or virtual memory) works. If the OS needs to look up data in the hard drive as opposed to the RAM, it will slow down. Nothing you can do about that, accessing the disk is way slower than accessing the RAM.
You won't be able to set the priority with which processes are swapped, that is determined by the kernel which will try to maximize efficiency, you won't be able to do it better. What you can do is set the CPU priority of a process and that might help. Your system is being lowed down because of the time it takes to read from/to SWAP, this means that the CPU will have to wait for the relevant data to be retrieved by the process requesting it before it can continue. If you set your DE to have a higher priority for CPU access, that should push its operations to the top and speed things up a little.
So, CPU priority is set with the nice
and renice
commands:
Renice alters the scheduling priority of one or more running processes.
The following who parameters are interpreted as process ID's, process
group ID's, or user names. Renice'ing a process group causes all pro‐
cesses in the process group to have their scheduling priority altered.
Renice'ing a user causes all processes owned by the user to have their
scheduling priority altered. By default, the processes to be affected
are specified by their process ID's.
The priorities go from -20 (highest priority) to 20 (lowest priority). To change the priority of a running process, you could do:
renice -15 $PID
where $PID
is the PID of the process whose priority you want to increase. You can use pgrep
to find out which that is. For example:
renice -15 $(pgrep gnome-session)
The other option would be to set the system's 'swappiness' which determines when it will start swapping. A swappiness value of 1 means that it will only swap to avoid out of memory errors. Higher values means it will start swapping even when there still is physical memory available. You can set this to a relatively low value to make your system swap as little as possible. Add this line to /etc/sysctl.conf
:
vm.swappiness=1
CAREFUL: That is not a good idea if you don't have a lot of RAM, swap is a Good Thing generally, you will need to play around with the values a bit to find the right balance for your system.