Why is my swap used even if my physical RAM isn't full?
Sometimes I have observed in Ubuntu's System Manager that without the physical RAM being used completely, the swap memory starts getting used.
Why is it so?
Solution 1:
From the Ubuntu Wiki Swap Faq
A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.
I feel that the linux kernel does this optimally, and quite well, so you need not worry at all. You could reduce swappiness to increase your RAM usage, but I would not recommend that.
Solution 2:
The OS sends pages to swap just in case
. It does this so that if swap is needed it can remove the "swapped" pages from memory without the delay of writing them to disk.
I have no proof of this, but I would assume it does this when it has some spare time, so it can do it without impacting normal operations.