I understand that when RAM fills up and the kernel starts moving pages back and forth from disk to RAM, programs will become less responsive. In my case however the whole system freezes (or lags horribly, with the mouse moving every 10 seconds or so) every time it goes into swap. I assume this is because the OS is either too busy moving stuff or it's moving its own parts to swap.
Why can't we protect the main components of the OS including the graphical interface (X) from swapping (by keeping them fixed in RAM) so that we have at least a responsive OS while we suffer lags in the rest of our applications? (Or if the issue is the kernel being too busy, setting the swapping priority lower?)