1

I am developing an application similar to a database with its own system for managing memory and that persists data by writing it into a file on disk.

In order to read/write from this file I am using a std::fstream. However, due to testing purposes, I would like to force it to read/write directly from disk instead of the disk cache. Is there an easy way to do it?

Thanks.

Calypso
  • 21
  • 1
  • 3
    I'm not sure C++ even knows what a disk is... – DeiDei May 13 '18 at 09:51
  • I agree in that probably C++ has no way to do so. But maybe some Linux command... – Calypso May 13 '18 at 09:58
  • Possible duplicate of [How to purge disk I/O caches on Linux](https://stackoverflow.com/questions/9551838/how-to-purge-disk-i-o-caches-on-linux) – hlt May 13 '18 at 09:58
  • I am already running `sync && echo 3 > /proc/sys/vm/drop_caches && blockdev --flushbufs /dev/sda && hdparm -F /dev/sda` before testing as you suggest. This flushes disk cache but does not disable it, so the program eventually starts hitting the cache again. – Calypso May 13 '18 at 10:11
  • You may also want to check out https://superuser.com/questions/242928/disable-linux-read-and-write-file-cache-on-partition – hlt May 13 '18 at 10:14
  • Thanks! The pagecache-management.sh tool is what I was looking for. – Calypso May 13 '18 at 13:30

0 Answers0