Linux: How to clear the cache from memory

Linux has a supposedly good memory management feature that will use up any “extra” RAM you have to cache stuff. This section of the memory being used is SUPPOSED to be freely available to be taken over by any other process that actually needs it, but unfortunately my Linux (three distros now, Mandriva 32 bit, and Mandriva 64 bit, and Opensuse 11 64 bit) thinks that cache memory is too important to move over for anything else that actually needs it.

I have 6 GB RAM in my computer. Whenever there is no cache being stored in the memory (i.e. when I first boot the computer), everything runs great. But as soon as it fills up with cache, my computer starts feeling like a 700mhz P2 running windows 98 stuffed full of malware. It’s terrible..

Up until just now, I have been forced to restart every time this happens because I simply cannot get any work done while in this state of retardation. I can close every single program I’m running – and even then, simply right clicking would require some extended thinking before loading the context menu. Ridiculous.

Luckily, I found a way to clear out the cache being used. Simply run the following command as root and the cache will be cleared out.

Linux Command

sync; echo 3 > /proc/sys/vm/drop_caches

Thank you ariel for posting in the comments below about including the sync command before dropping caches.