Sometimes (especially when system works on heavy load) Linux buffers and caches contains a lot of objects. This behaviour is generally highly desirable but let’s take a look at following scenario.
Web server is a victim of a DDoS attack. Most of free RAM is used by caches. DDoS has ended and we quickly need to free some RAM for our main application and database system. Cache will warm-up again but it take some time. We need to initiate cache warm-up now!
Linux kernel offers easy to use mechanism for Virtual Memory and Cache management. It’s functions are available by /proc. To free slab objects (dentries and inodes) and pagecache use this command:
# echo 3 > /proc/sys/vm/drop_caches
Cache dropping is more effective when you force sync just before cache drop.
# sync && echo 3 > /proc/sys/vm/drop_caches
Now you have significantly more free RAM. As an optional task you can free system swap (turn off swap and turn it on again). After this operation you should notice better system performance (after cache warm-up).