To use /proc/sys/vm/drop_caches, just echo a number to it.
To free pagecache:
| [root@host]# echo 1 > /proc/sys/vm/drop_caches |
To free dentries and inodes:
| [root@host]# echo 2 > /proc/sys/vm/drop_caches |
To free pagecache, dentries and inodes:
| [root@host]# echo 3 > /proc/sys/vm/drop_caches |
This is a non-destructive operation and will only free things that are completely unused. Dirty objects will continue to be in use until written out to disk and are not freeable. If you run "sync" first to flush them out to disk, these drop operations will tend to free more memory.
Be careful doing this. While it SHOULD be non-destructive, when I was playing around with this to free up memory to allocate for huge pages on a production Oracle DB server I had an unexpected/unplanned reboot. Fortunately it was during a planned maintenance window, so I didn't have to update my resume. I'm not sure if the reboot was a kernel issue, or if it was an Oracle reaction to the cache dropping (it was many moons ago, so my memories are a bit blurred).
ReplyDeleteAlso realize that all kinds of stuff that you had cached in memory will have to be re-read from disk the next time you need to access it, so you might take a performance hit.