Tip of the day: drop_caches

| No Comments | No TrackBacks
OK, so as you know, I'm a systems architect at a service provider. I'm going to start posting tips that I get from various other people, and stuff that I generally don't want to forget and might be useful to other people here. The first in this hopefully regular series is about the drop_caches tunable. It's available in kernel 2.6.16 and above, and exists in /proc/sys/vm.

If you echo various values to it, various kernel cache data structures are dropped. This is a non-destructive operation, so if you still see stuff hanging out after it, it's likely that it was dirty cache. Anyhow, on to the values:

1 - drop the pagecache
2 - drop the dentry and inode caches
3 - drop both the dentry and inode caches, as well as the pagecache.

Here's an example of the impact on the pagecache by doing this:

[root@rugrat ~]# free
total used free shared buffers cached
Mem: 2060656 1448748 611908 0 239620 649220
-/+ buffers/cache: 559908 1500748
Swap: 4194296 41056 4153240
[root@rugrat ~]# echo 3 > /proc/sys/vm/drop_caches
[root@rugrat ~]# free
total used free shared buffers cached
Mem: 2060656 615108 1445548 0 244 89128
-/+ buffers/cache: 525736 1534920
Swap: 4194296 41056 4153240

Note how the pagecache went from ~650MB to around ~89MB after dropping it. In practicality, you would likely never want to do this. However, if you are performing testing on the machine in question, you likely want to test the efficiency of the hardware ,and not the kernel's caching mechanisms.

Labels: , ,

No TrackBacks

TrackBack URL: http://blog.jds2001.org/cgi-bin/mt-tb.cgi/215

Leave a comment