Monday, August 26, 2019

Linux: Why to drop caches and how? Host or virtual machine

Repost of an old post

Excerpt from stackoverflow: "The reason to drop caches like this is for benchmarking disk performance, and is the only reason it exists. When running an I/O-intensive benchmark, you want to be sure that the various settings you try are all actually doing disk I/O, so Linux allows you to drop caches rather than do a full reboot."

How to drop caches on the host?
sync; echo 3 > /proc/sys/vm/drop_caches

How to drop caches on a virtual machine and measure the difference in RAM?
user90> free -mt
              total        used        free      shared  buff/cache   available
Mem:           3002         440        1908           9         652        2375
Swap:          2047           0        2047
Total:         5050         440        3956
user90> sudo  sync
user90> free -mt               total        used        free      shared  buff/cache   available
Mem:           3002         440        1905           9         655        2375
Swap:          2047           0        2047
Total:         5050         440        3953
user90> sudo sysctl -w vm.drop_caches=3
vm.drop_caches = 3
user90> free -mt
              total        used        free      shared  buff/cache   available
Mem:           3002         440        2385           9         176        2394
Swap:          2047           0        2047
Total:         5050         440        4433
user90> 
Other than for benchmarking freeing up RAM is not a very useful exercise.