Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 7 down vote accepted

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.

share|improve this answer
    
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 '12 at 8:46
2  
@TheDave: Unless you specifically want to benchmark the cold cache situation, you should never use it. –  janneb Oct 7 '12 at 8:47
    
Thank you very much for your insights janneb! –  TheDave Oct 7 '12 at 8:49
add comment

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.

share|improve this answer
    
Thank you very Much Mr. Chakraborty, very insightful ! –  TheDave Oct 7 '12 at 11:35
add comment

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.

share|improve this answer
    
Thank you for your insight @ewwhite –  TheDave Oct 7 '12 at 8:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.