This is my Ubuntu version.
# uname -a
Linux psh-VirtualBox 5.3.0-42-generic #34~18.04.1-Ubuntu SMP Fri Feb 28 13:42:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
I did the same experiment after setting the swappiness values 1 and 100.
The test is to fill the cache area and then allocate more than free memory in the new process.
However, none of them used the SWAP area.
Even if the swappiness value is 100, isn't the SWAP area used?
When swappiness = 1
# sysctl -w vm.swappiness=1
vm.swappiness = 1
swapoff -a
swapon -a
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
free
total used free shared buff/cache available
Mem: 8152876 995524 7036300 20760 121052 6951560
Swap: 3067108 0 3067108
dd if=/dev/zero of=./file_1 bs=1024 count=6500000
free
total used free shared buff/cache available
Mem: 8152876 994732 356972 20760 6801172 6833516
Swap: 3067108 0 3067108
./memory_allocate_2G # Another Session
free
total used free shared buff/cache available
Mem: 8152876 3055936 129096 20760 4967844 4775416
Swap: 3067108 0 3067108
When swappiness = 100
# sysctl -w vm.swappiness=100
vm.swappiness = 100
swapoff -a
swapon -a
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
free
total used free shared buff/cache available
Mem: 8152876 995892 7049160 20760 107824 6957692
Swap: 3067108 0 3067108
dd if=/dev/zero of=./file_1 bs=1024 count=6500000
free
total used free shared buff/cache available
Mem: 8152876 995236 366380 20760 6791260 6832984
Swap: 3067108 0 3067108
./memory_allocate_2G # Another Session
free
total used free shared buff/cache available
Mem: 8152876 3055936 129096 20760 4967844 4775416
Swap: 3067108 0 3067108
Would my test be wrong?
thank you.
And Our Live Server free info ( Why use swap when there is enough free space? )
swappiness is 10.
Linux Server 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ free
total used free shared buffers cached
Mem: 32901680 29978376 2923304 0 193676 9317964
-/+ buffers/cache: 20466736 12434944
Swap: 7812092 6379492 1432600
free
’s output), your system won’t swap. – Stephen Kitt Sep 23 '20 at 04:58vm.swappiness is 10 of the live server. Here, even though free is sufficient, swap was being used. I didn't understand this part.
At the end of the text, information on the memory usage area has been added.
– P.Lonnie Sep 23 '20 at 10:06sar
in thesysstat
package can help. – Stephen Kitt Sep 23 '20 at 11:10