Freeing Memory buffers and cache in Linux


#!/bin/bash
sync
echo 3 > /proc/sys/vm/drop_caches

Why would you want to do that? Linux uses buffers and cache intelligently – unused memory is wasted memory.
Yes, I do understand all of this. I found this to be useful when hibernating with TuxOnIce. Calling this script before hibernating results in much faster hibernates and resumes.
If using ArchLinux and hibernate-script a good place to put this would be /etc/hibernate/common.conf – add the following at this point in the file:

### misclaunch
# OnSuspend 20 echo "Good night!"
# OnResume 20 echo "Good morning!"
OnSuspend 95 /path/to/above/script

Advertisements
Freeing Memory buffers and cache in Linux

3 thoughts on “Freeing Memory buffers and cache in Linux

  1. /usr/src/linux/Documentation/filesystems/proc.txt recommends to `sync’ before dropping caches: «as this is a non-destructive operation and dirty objects are not freeable, the user should run `sync’ first.»

  2. For suspend2ram users:
    -/etc/hibernate/common.conf
    +/etc/hibernate/hibernate.conf

    And there is better place to do that:
    -OnSuspend 5 /path/to/above/script
    +OnSuspend 95 /path/to/above/script

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