How can I disable the prefetch cache?

6,603

Solution 1

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.

Solution 2

since 2.6.16 you can run:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches
Share:
6,603

Related videos on Youtube

Oli
Author by

Oli

Hi, I'm Oli and I'm a "full-stack" web-dev-op. Eurgh. I'm also allergic to jargon BS. I spend most of my professional time writing Django websites and webapps for SMEs. I write a lot of Python outside of Django sites too. I administer various Linux servers for various tasks. I contribute to the open source projects that I use when I can. I'm a full-time Linux user and that has lead to helping other people live the dream. I am an official Ubuntu Member and I earnt my ♦ on SE's own Ask Ubuntu in 2011's moderator election. That's probably where I spend most of my unpaid time. I also run thepcspy.com which has been my place to write for the last decade or so. If you need to contact me for extended help, you can do so via my website, just remember that I have bills so if I feel your request is above and beyond normal duty, I might ask for remuneration for one-on-one support. For more social contact, you can usually find me (or just my computer) lurking in the Ask Ubuntu General Chat Room and on Freenode in #ubuntu and #ubuntu-uk under the handle Oli or Oli``.

Updated on September 17, 2022

Comments

  • Oli
    Oli over 1 year

    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.

    • Admin
      Admin over 13 years
      I don't think you can disable it but you can flush it with sync && echo 1 > /proc/sys/vm/drop_caches
    • Admin
      Admin over 13 years
      That does work to flush it but it does fill up again.
  • flo
    flo over 13 years
    At worst, you'd have to modify the kernel (maybe just its configuration). But surely it must be possible, even if it's difficult.
  • Oli
    Oli over 13 years
    "you don't want to" I do. I've already gone over everything you've said in the OP and I still want to.
  • psusi
    psusi over 13 years
    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
    psusi over 13 years
    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.
  • flo
    flo over 13 years
    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)
  • Andrew Ensley
    Andrew Ensley almost 10 years
    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.
  • psusi
    psusi almost 10 years
    @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.