![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
First Cup of Ubuntu
![]() Join Date: Oct 2007
Beans: 1
|
HOWTO: Clear filesystem memory cache
I have read several forum posts where people have asked "How do I clear/free/dump/purge the memory cache?" A variation of the same answer is almost always given "You don't want to do that ... the Linux Kernel is smarter than you ... Don't try it ... Use dd to create a big file, then delete it ... etc ..." I never could find an answer that just explained how to do it, so I kept searching elsewhere, and here it is.
NOTE: This may cause you to lose data, it may make your system slower, it may kill your cat. Do this at your own risk, and don't be surprised if it doesn't work out the way you wanted it to. With the CYA out of the way, here is how to free up as much memory as possible by dumping the cache. Execute as root, or with sudo: Code:
# sync # echo 3 > /proc/sys/vm/drop_caches As long as you are running a post 2.6.16 kernel, those commands will work. I tested it on Feisty and Gutsy, and it worked perfect. I got this information from AP Lawrence. Enjoy! |
|
|
|
|
|
#2 |
|
Just Give Me the Beans!
![]() Join Date: Oct 2006
Beans: 74
The Feisty Fawn Testing
|
Re: HOWTO: Clear filesystem memory cache
"This invalidates the write cache as well as the read cache, which is why we have the sync command first."
According to the documentation that you sited, this is not true. From the documentation cited in the cited documentation, "this is a non-destructive operation, and dirty objects are not freeable" So, using the drop_caches command is designed to be safe, and running sync just ensures that ALL the cache is clear. If you don't run sync, and unwritten data will stay in the cache. I hope its clear that I'm just getting this from the websites cited, and I can't personally verify this in anyway. |
|
|
|
|
|
#3 |
|
Just Give Me the Beans!
![]() Join Date: Oct 2006
Beans: 74
The Feisty Fawn Testing
|
Re: HOWTO: Clear filesystem memory cache
well, I tried it, nothing seems to have happened really, except now ubuntu is using less ram
I had to ask to get a command that could be run with sudo, so I'm posting it here for reference: sudo echo 3 | sudo tee /proc/sys/vm/drop_caches |
|
|
|
|
|
#4 |
|
Dark Roasted Ubuntu
![]() Join Date: Nov 2006
Location: There and back again
Beans: 1,061
|
Re: HOWTO: Clear filesystem memory cache
Cool tip. I had to shutdown X server for it to really be effective. For GNOME the GNOME display manager will need to be disabled. I'm using Gentoo and the boot system is different for Ubuntu (Ubuntu uses RC, i believe?) but the xdm daemon needs to be stopped:
Code:
sudo /etc/init.d/xdm stop
__________________
|
|
|
|
|
|
#5 |
|
Gee! These Aren't Roasted!
![]() Join Date: Jul 2005
Location: CZW/KRK, Poland
Beans: 184
Xubuntu 7.10 Gutsy Gibbon
|
Re: HOWTO: Clear filesystem memory cache
Hi!
Thanks jmarler. This is exacly what I was looking for copter :]
__________________
"Computers are a lot like air conditioners - they work great until you open windows."
Linux user 394528 && Ubuntu user 6836 |
|
|
|
|
|
#6 |
|
First Cup of Ubuntu
![]() |
Re: HOWTO: Clear filesystem memory cache
Thanks!
I have seen the other treads, and find this one very useful! |
|
|
|
|
|
#7 |
|
First Cup of Ubuntu
![]() Join Date: Jun 2008
Beans: 3
|
Re: HOWTO: Clear filesystem memory cache
Thank you for this. I need to clear the cached memory due to VBOX hogging cached memory, if I open/close multiple virtual machines, the cache does not clear, and once it hits 100%, when I try and start another my system crashes.
|
|
|
|
|
|
#8 |
|
First Cup of Ubuntu
![]() Join Date: Sep 2009
Beans: 4
|
Re: HOWTO: Clear filesystem memory cache
Just wanted to add a note to this. I have the system monitor on my panel, with memory enabled, and as soon as I typed the 2nd command the cached meter dropped instantly. Works great.
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|