Swap space is effectively overflow for your memory and typically it will only store memory that’s been allocated but is not in use. If you run your memory down to a level where not all running programs can keep themselves and the memory they need ‘most’ of the time in RAM, you really will know about it and typically your machine will start to grind to a halt.
The reason you need lots of swap (these days) is that applications, X based applications in particular, tend to leak memory. Sometimes directly and sometimes indirectly into the X server itself. (Firefox is a prime culprit) If the memory leaks are ‘direct’ you can generally recover this memory by restarting the application, but if it leaks into X, you’ll need to log out and in again - which can be inconvenient if you are “doing” things.
However, leaked memory generally does nothing, so it will happily swap out without affecting performance, hence you can sometimes see swap usage in the Gb range, but actually all the system has done it swap out leaked memory, so there are no ill effects.
You will find there is a kernel parameter called “swappiness”, which controls the kernel’s affinity for swapping … the higher this number, the more aggressively the kernel will swap stuff out, move this number to zero and it will only swap as an alternative to OOMing on you. (I set my KVM hosts to zero because if a KVM host starts to swap , the virtual machines tend to get very upset in terms of performance …)
Try;
cat /proc/sys/vm/swappiness
It will probably say “60” , which is the norm for desktops.
To change it, as root do;
echo [value in the 0-100 range] > /proc/sys/vm/swappiness
If you want to change it / see how it affects your system … generally this is not going to cause any damage as such, but I’d recommend staying away from “0” and “100”.