Tuesday, October 28, 2008

Clearing Linux' Memory Cache

Note to self: Here are some commands you can use to clear the memory cache on a Linux system. The following command sequence will do the following: - display the memory stats - flush filesystem buffers - drop cached memory - display the memory stats again
$ free $ sudo sync $ sudo echo 3 | sudo tee /proc/sys/vm/drop_caches $ free
Or, if you like one-liners:
free; sudo sync; sudo echo 3 | sudo tee /proc/sys/vm/drop_caches; free
This is the ouput that i got. The values in bold are my commands, if you look at the underlined values, you will see the memory drop.
linux01:~ $ free
             total       used       free     shared    buffers     cached
Mem:       2061568    2029968      31600          0     429284    1247252
-/+ buffers/cache:     353432    1708136
Swap:      1036152        104    1036048
linux01:~ $ sudo sync
linux01:~ $ sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
linux01:~ $ free
             total       used       free     shared    buffers     cached
Mem:       2061568     724828    1336740          0        340     392092
-/+ buffers/cache:     332396    1729172
Swap:      1036152        104    1036048
I tested this on SLES10 and Centos5 and Ubuntu8.04. My Ubuntu 6.06 and 7.10 boxes do not seem to have the file /proc/sys/vm/drop_caches . Sources: 1 and 2.

Monday, October 27, 2008

Enable Time Sync from inside a Linux VM

Note to self: Command to enable VMware Time Synchronisation on a Linux VM without a GUI (with VMware Tools installed):
vmware-guestd --cmd "vmx.set_option synctime 1 0"
To disable it you have to turn around the last two parameters, like this:
vmware-guestd --cmd "vmx.set_option synctime 0 1"
If you want to apply a setting that is already current you will get the message:
"Invalid old value"
This is tested on RedHat Enterprise Linux 5 and SUSE Linux Enterprise Server 10. Source: Timekeeping best practices for Linux on kb.vmware.com