6

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.

Oli
  • 293,335

3 Answers3

3

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.

3

since 2.6.16 you can run:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches
Tedy
  • 61
0

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.

psusi
  • 37,551
  • 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
  • 2
    "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
  • 1
    All the "You don't want to" answers are completely untrue. My system fills the RAM with file system cache and starts using the swap partition for running programs, which is ridiculous. Instead of reading those files from disk on demand, it keeps them in RAM uselessly and swaps program memory operations to disk. Talk about inefficient. – Andrew Ensley May 13 '14 at 16:22
  • @Andrew, incorrect: only programs that have been idle for some time are sent to swap because it is better to cache files you are using instead of the programs you aren't. A lot of people a lot smarter than you have spent a lot of time thinking these things through. – psusi May 13 '14 at 17:13