5

I have a small VPS with 6GB RAM hosting a couple of websites.

Recently I have noticed that my cached memory size is quite high - see below:

    Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.1%id,  0.0%wa,  0.2%hi,  0.4%si,  0.0%st
    Mem:   6113256k total,  5949620k used,   163636k free,   398584k buffers
    Swap:  1048564k total,      104k used,  1048460k free,  3586468k cached

After investigating if there is some method to have this flushed or cleared I stumbled upon a command which is:

    sync; echo 3 > /proc/sys/vm/drop_caches

I read it could be useful to add this to a chron-task/job. Is this method recommended or could this lead to potential problems?

The only concern I have is that I use one Magento installation on Memcached - could this have any negative effects on it?

I am certainly not a pro therefore I would very much appreciate some expert advise.

PS: My VPS runs on CentOS 5 x64 and I have WHM + NGINX installed.

0

3 Answers 3

7

Dropping your caches will likely impact your server's performance as it has to reread frequently accessed data back into the caches after every cache drop.

There is no real reason to drop your caches. To the Linux kernel memory being used for cache is essentially free and will be passed on to applications whenever they need it. Take a look at this website for more information.

Regarding the data stored in memcached - this safe from the effects of dropping the page/dentries/inodes caches.

2
  • Thank you very much Lain for your insight - really appreciated. I currently have 4 CPU's assigned and 6GB RAM - would you advise not to run this operation on a "once a day" basis? Is the impact that severe? Also what do you think about my current usage - I was told the "5949620k used" that are being displayed are not the actual RAM in use - I would need to detract both "buffered" and "cached" results to that actual number to have the real Ram usage. Is that correct?
    – TheDave
    Oct 7, 2012 at 8:46
  • 2
    @TheDave: Unless you specifically want to benchmark the cold cache situation, you should never use it.
    – janneb
    Oct 7, 2012 at 8:47
4

As said, there is little point in dropping caches unless you have a very compelling reason to do so. If you are not seeing any performance problem, leave it as it is.

If you are of the curious type, then you can tweak the parameter vm.vfs_cache_pressure. The default value is 100 which means that kernel will try to reclaim cache at a fair rate compared to reclaiming swap. Increasing the value would lead cached memory to be reclaimed faster and reducing it would lead to reclaiming swap faster, but remember this is just how kernel's aggressiveness to clear cache or swap is. Actual results vary from environment to environment.

In stead of echoing 3, you can also echo 1 or 2. If I remember correctly, echoing 1 will clear page cache and 2 will clear dentry and inode cache. 3 will clear pagecache, dentry and inode caches.

0
2

There's no real harm to having that level of cached RAM. It's what Linux does.

Are you seeing any performance gain following dropping the caches? If not, then it's not worth scheduling it.

As a side, you can control what's in the cache with a little more granularity using the vmtouch utility.

0

Not the answer you're looking for? Browse other questions tagged .