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.

2
  • 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, 2011 at 18:03
  • That does work to flush it but it does fill up again.
    – Oli
    Jan 11, 2011 at 19:16

3 Answers 3

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
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.

7
  • At worst, you'd have to modify the kernel (maybe just its configuration). But surely it must be possible, even if it's difficult. Jan 11, 2011 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, 2011 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, 2011 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, 2011 at 19: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. May 13, 2014 at 16:22

You must log in to answer this question.

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