Here is the following info:
Do I need more swap?
No, disk caching only borrows the ram that applications don't currently want. It will not use swap. If applications want more memory, they just take it back from the disk cache. They will not start swapping.
But I conducted an experiment that show something different. Just take a look:
# free -m total used free shared buffers cached Mem: 1001 941 59 0 2 127 -/+ buffers/cache: 811 189 Swap: 2347 693 1654
There's 811MiB in RAM and 693MiB in SWAP. Now is the time to close some apps, and I got something like this:
root:~# free -m total used free shared buffers cached Mem: 1001 531 469 0 4 126 -/+ buffers/cache: 400 600 Swap: 2347 361 1986
So, now it's 400MiB in RAM, and 361 in SWAP. If I run
swapoff, there should be 400+361=761 MiB in RAM, but that's not going to happen:
root:~# swapoff -a root:~# free -m total used free shared buffers cached Mem: 1001 860 140 0 6 251 -/+ buffers/cache: 602 398 Swap: 0 0 0
There's only 602MiB in RAM, and the question is where the hell is the other 159MiB ?
I thought it's because of the ZRAM feature. The following are statistics of SWAP devices before running
root:~# swapon -s Filename Type Size Used Priority /dev/mapper/debian_crypt-swap partition 2097148 99620 10 /dev/zram0 partition 153596 135072 70 /dev/zram1 partition 153596 135092 70
But I also checked the normal SWAP partition, and the effect was more or less the same, just the amount of cached data was smaller (60MiB).
Is there a way to prevent SWAP from collecting cached data?