10 Comments

Purge memory trick

Purge Memory

Linux does a good job when it comes to memory allocation. If memory isn’t being used or hasn’t been used for awhile it gets put into a cache where it can readily pulled. At times though this cache can become pretty big (especially for a program that has a memory leak). If a good number of programs are being used or if memory is limited then Linux will begin using hard disk swap which can really bog down performance. In these instances, it may help to purge the memory.

In the terminal type free -m to see memory usage. Flushing the filesystem buffers and to drop extra caches can be done by doing:

sudo sync
sudo echo 3 | sudo tee /proc/sys/vm/drop_caches

Look once more at free -m and memory usage should be improved. Freeing memory is most effective by shutting down whatever programs can be. To be really effective shutdown X server first.

This can be put in a script if you need to regularly do this:

Resources

About these ads

About Gen2ly

<3's linux

10 comments on “Purge memory trick

  1. Sweet, thanks.

  2. [...] karena link yang diberikan google di awal pencarian belum banyak yang terjelajahi. Ternyata ada cara lain yang menurut saya “lebih elegan”. Saya anggap begitu karena tidak harus menunggu agak [...]

  3. Excellent! =)

  4. This is considerably more complex that it needs to be (I dare say that you’re a tad sudo happy. ;P)

    ‘sync’ normally shouldn’t require root privileges.
    ‘echo’ really doesn’t (and is internal in most shells).
    All ‘tee’ does it show you the 3—which doesn’t accomplish much.

    So the crux of this is: “echo 3 >/proc/sys/vm/drop_caches”

    Which doesn’t have the affect that i’d hoped (i was looking for something to discourage swap use—à la “swapoff -a ; swapon -a”, but less aggressive); but it may be helpful, nonetheless. Thanks! ☺

  5. Oh i suppose the purpose of tee was for the file writing to happen during sudo (which i rarely use). So, for the sudo fans:

    sudo sh -c ‘echo 3 >/proc/sys/vm/drop_caches’

    or

    echo 3 | sudo tee /proc/sys/vm/drop_caches

  6. Thanks a lot for this help. It works just fine.

  7. Thanks. Just what I was looking for.

  8. [...] karena link yang diberikan google di awal pencarian belum banyak yang terjelajahi. Ternyata ada cara lain yang menurut saya “lebih elegan”. Saya anggap begitu karena tidak harus menunggu agak [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 51 other followers

%d bloggers like this: