Freeing up RAM (memory) in Linux

Very often I used to find that my Linux box(s), Fedora & Ubuntu both started reserving more RAM over a period of time since its boot. And the actual RAM left free was less.

I knew it was holding some caches for itself so that it could find the programs loading “quickly” and something like that (Sorry for my newbie language).

The most common way to free up RAM is Rebooting! But I wanted to avoid it, so did a little “googling” and I came up with an interesting solution – Tell linux to flush all the caches.

# Flush file system buffers by executing
sync;

# free page cache
echo 1 > /proc/sys/vm/drop_caches;

# free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches

# free page cache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches

I’ve created a simple bash script, which u can download.

References

  1. http://www.linuxarticles.org/2010/10/release-memory-in-linux-unused-or-cached/
  2. http://www.hdfgroup.org/HDF5/faq/linux-mem.html

15 thoughts on “Freeing up RAM (memory) in Linux”

  1. Hi. I’m trying to make it simpler by just double-clicking it and do the job unsuccesfully. It works if i run it as root from terminal, or if I open it as root(right-click –> open as root –> type password) and then run it.
    But I was wondering if this could be easier, double-click it and that’s all.
    I’d appreciate an answer if anyone knows how to do that..

    1. I’m not really sure how to do it – But the script will have to accept root / authentication just like yumex does.

      Or you could simply add ur user id as admin

  2. Thanks! Although I prefer to use sysctl for that. For example, in Ubuntu I use:

    sudo sysctl vm.drop_caches=1
    sudo sysctl vm.drop_caches=2
    sudo sysctl vm.drop_caches=3

  3. You can delete the cache entries, but this will make no difference to the amount of memory your applications can use. The caching will free up memory as soon as an application needs the memory. So the only thing you do is slowing things down because all the cached applications will have to be searched for on the harddisk again.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.