View previous topic :: View next topic |
Author |
Message |
RiBBiT Apprentice


Joined: 18 May 2005 Posts: 215 Location: Sweden
|
Posted: Tue Jul 04, 2006 9:56 pm Post subject: Force cache flush in Linux? |
|
|
I am currently doing some programming with threads, one thread that reads a series of data off disk and one that uses this data. The purpose is of course to let these two threads (I/O intensive and CPU intensive respectively) work in parallel. The "problem" is that after one run the files on the disk will be cached in RAM, so performing further timing tests on the code will be of no use. Is there a way to force a complete "cache flush" in Linux so that I can run the program multiple times, and each time be sure that all files are actually read from disk? I could of course try to "manually" fill the cache with other stuff (playing with `dd` perhaps?), but if there is a better way I'd like to know.
EDIT:
Code: | $ dd if=/dev/zero of=null ibs=1000000 count=700 |
and then for each flush:
gives reasonable results, but a complete cache flush command would be better (and faster). _________________ Comix - GTK Comic Book Viewer [ http://comix.sourceforge.net ] |
|
Back to top |
|
 |
dmitchell Veteran


Joined: 17 May 2003 Posts: 1159 Location: Austin, Texas
|
Posted: Tue Jul 04, 2006 10:24 pm Post subject: |
|
|
From http://wiki.kernelnewbies.org/Linux_2_6_16
Quote: | Add /proc/sys/vm/drop_caches. Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. This is mainly useful for benchmarking, for getting consistent results between filesystem benchmarks without rebooting. To free pagecache: "echo 1 > /proc/sys/vm/drop_caches", to free dentries and inodes: "echo 2 > /proc/sys/vm/drop_caches", to free pagecache, dentries and inodes: "echo 3 > /proc/sys/vm/drop_caches". As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first |
_________________ Your argument is invalid. |
|
Back to top |
|
 |
RiBBiT Apprentice


Joined: 18 May 2005 Posts: 215 Location: Sweden
|
Posted: Tue Jul 04, 2006 10:34 pm Post subject: |
|
|
Thanks, that's exactly what I'm looking for! Good luck for me that it was just recently added to the kernel. _________________ Comix - GTK Comic Book Viewer [ http://comix.sourceforge.net ] |
|
Back to top |
|
 |
sundialsvc4 Guru

Joined: 10 Nov 2005 Posts: 436
|
Posted: Thu Jul 06, 2006 12:40 am Post subject: |
|
|
It would be good for your tests, perhaps, but it would create an un-realistic benchmark of how the application would actually perform in practice. Ideally, an application would not only expect "normal" system cache behavior, but would seek to exploit it... arranging disk writes to favor cacheing and so-on. |
|
Back to top |
|
 |
RiBBiT Apprentice


Joined: 18 May 2005 Posts: 215 Location: Sweden
|
Posted: Thu Jul 06, 2006 1:07 am Post subject: |
|
|
This is about reading data that is private to (i.e. created by and AFAIK only used by) the application in question. I am interested in the worst case scenario where these files are not present in the cache, since that is the likely scenario. Having all files ready in cache is not normal system behaviour in this case. _________________ Comix - GTK Comic Book Viewer [ http://comix.sourceforge.net ] |
|
Back to top |
|
 |
|