Linux – How to see if the disk cache is disabled on Linux

cachedisk-cachelinuxperformance

I have an ubuntu linux virtual machine here and I think there is no disk cache.

For example this is the output from free -m:

             total       used       free     shared    buffers     cached
Mem:           512         98        413          0          0          0
-/+ buffers/cache:         98        413
Swap:            0          0          0

If I create large files, read large files, read all the files in my home directory (2.2GB of files), I always see 0 for 'buffers', 'cached' and the "buffers/cache" line is always the same as the line above it.

Likewise top and htop both show no disk cache being used.

I tried to drop all the caches with:

echo 3 > /proc/sys/vm/drop_caches

and I get an error of echo: write error: Operation not permitted (even when running as root).

So it looks like the cache is disabled, however I thought it wasn't possible to do that. Is it possible to disable the disk cache? Is there anyway to confirm if I have disk cache or not? Maybe I've just been unlucky and haven't seen any disk cache usage yet.

Note: This is a hosted VPS / virtual machine. Some things are disabled, like swap (that's right I can't swapon, the swapon system call returns EPERM). Is it possible to do that with the disk cache? Is there some way to see if that has been done?

Best Answer

Your VPS is running under Virtuozzo/OpenVZ. In this setup, it's not a true fully-segregated VM as would be the case with say Xen or VMware. With OpenVZ and Virtuozzo, there is one single instance of the kernel running (instead of one per VM), and this kernel is responsible for maintaining separation between all of the processes running under the different guest VMs. This includes managing the disk caching layer. Because this function is operating outside of your VM, you don't have any visibility into what your cache looks like.

I'm not sure if this is an issue specifically with your host's implementation of OpenVZ or if it's just a side-affect of how OpenVZ does virtualization.

As an aside, I checked on the one OpenVZ VM I have access to, and wasn't able to see cache info there either. If you need access to this information, I'd recommend moving to a VPS provider that uses Xen or some other real hypervisor.