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
Monday 21st July, 2008 at 11:11 am
/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.»
Monday 21st July, 2008 at 12:08 pm
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
Monday 21st July, 2008 at 2:58 pm
Thanks for comment – have adjusted posts accordingly