Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I run a few Ubuntu servers that have a load of django sites running on them. The sites and the httpd start at boot and after that (apart from me SSHing in to update it or using bzr to update websites) nothing else gets run on it.

At the moment over half the ram is allocated as cache. This isn't a problem because cache usually makes space or a little bit of it slips into swap (again, this doesn't really bother me) but I don't see the need for it.

Is there a quick way to disable the cache? This is more of an experiment than anything else so it would be handy to know how to turn it back on again.

share|improve this question
    
I don't think you can disable it but you can flush it with sync && echo 1 > /proc/sys/vm/drop_caches –  karthick87 Jan 11 '11 at 18:03
    
That does work to flush it but it does fill up again. –  Oli Jan 11 '11 at 19:16
add comment

3 Answers 3

up vote 2 down vote accepted

This blog post by Andrea Righi suggests that there isn't a config option in the kernel, but it also sketches out a little glibc wrapper library to just set the O_DIRECT flag on every call to open().

This should have the same effect as disabling the read-buffer completely.

Additionally, the OpenOffice wiki has a couple of methods to do cold-start testing. This isn't what you want, but I thought I include it anyway.

share|improve this answer
add comment

since 2.6.16 you can run:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches
share|improve this answer
add comment

No, and you don't want to. The cache only uses memory that otherwise would be sitting idle. As soon as it is needed, it will be freed and given to the process that wants it, so you can consider cache memory to be free, which is why the free command prints a line with the cache factored in.

share|improve this answer
    
At worst, you'd have to modify the kernel (maybe just its configuration). But surely it must be possible, even if it's difficult. –  Stefano Palazzo Jan 11 '11 at 18:21
1  
"you don't want to" I do. I've already gone over everything you've said in the OP and I still want to. –  Oli Jan 11 '11 at 19:15
    
There is a knob you can tune to increase the amount of ram it will try to keep in the free column instead of the cache column, but short of a massive rewrite of the kernel beyond all recognition, you can not disable the cache entirely. –  psusi Jan 11 '11 at 19:27
    
If you still want to then you did not understand what I said. The cache memory can be considered to be free for all intents and purposes. It is not being used up at something else's expense. It is your thinking that is flawed, not the cache. –  psusi Jan 11 '11 at 19:30
    
Where is that knob? I think instruction on how to set it would answer the question perfectly (just turn it all the way to eleven, and there shouldn't be any more caching) –  Stefano Palazzo Jan 12 '11 at 11:30
show 2 more comments

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.