OK, before you mark my thread a duplicate I want to say, that I know this very good answer: How do I clean or disable the memory cache?
But this is not case for me.

I am making some performance tests between in-memory application and disk-using application. So I want to have guarantee, that every time application tries to fetch something from disk, system really fetches this from disk, not from memory cache. (I want to have performance factor, by how much worse application operates, when it has to read from disk.)
I know, that I can clean cache by sync && echo 3 > /proc/sys/vm/drop_caches command, but cleaning every minute by cron is to slow for me, because cache is getting filled very quickly again.

So I have a question: Can't you really disable this feature? Or maybe go around it? It really can mess up my tests results.

PS: I am using Ubuntu 12.04 64-bit.

  • I think these are answers to different problems... – Michał Herman Feb 23 '14 at 20:04
  • I really think that it is not possible in general. Maybe there could be some mmap() magic that makes the map to the disk volatile and so forcing a rewrite/reread every time, but I suspect that caching the filesystem content is so tied to the basic memory manager that it is impossible to avoid it. I can be wrong --- will see. – Rmano Mar 25 '14 at 15:19

You can disable it with hdparm, open your text editor and edit the /etc/hdparm.conf and uncomment the "write_cache = off" line. Reboot, to check if it worked, type sudo hdparm -i /dev/sdX ( use your drive leter ), and check the AdvancedPM line, in the end says the state of the write cache.

EDIT: you can check the hdparm -i /dev/sdX to see how is the write_cache option before changing.

EDIT2: use -o sync when mounting a partition to avoid writing the cache, I don't know about the reading part.

  • This will disable the internal cache of the disk. Linux will happily continue to cache the filesystem data in main memory... – Rmano Mar 25 '14 at 15:17
  • 1
    Can you try mounting the drive with the -o sync parameter? supposedly it turns off the write cache. – fpinto Mar 25 '14 at 16:06
  • Yep --- -o sync is a good idea for writes. I doubt it will stop caching read blocks... (please update the answer) – Rmano Mar 25 '14 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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