Free up Memory by Clearing Memory and Swap Cache on Linux

Linux does an admirable job of managing memory under most circumstances.  On occasion – possibly on a server without a scheduled reboot cycle, it can be beneficial to periodically flush various cache to disk.  This would not be an ideal recommendation for a production server, to for example have this run as a chron job – namely because it will likely interfere with user activity.  Depending on the load this will result in the server hitting the disk pretty hard and potentially impacting stability.

sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches
swapoff -a && swapon -a

A little more information on swap files here


About the author

Lima is the visual nautical indicator for "stop instantly."


Leave a Reply