How to clear memory caches in ubuntu
While performance testing some mysql queries in ubuntu I came across the old problem that even after restarting mysql to clear its own buffers, the OS caches speed up consecutive runs of the same query. In order to get consistent results you need to flush both the mysql buffers and the native OS buffers.
Flushing the mysql buffers is as easy as restarting mysql (
sudo service mysql restart in Maverick). Flushing the OS buffers is also dead easy:
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
I have system-monitor gauges on my taskbar showing cpu, memory and disk activity, and its a beautiful thing to see the cache suddenly get wiped :)blog comments powered by Disqus