Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Force cache flush in Linux?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
RiBBiT
Apprentice
Apprentice


Joined: 18 May 2005
Posts: 215
Location: Sweden

PostPosted: Tue Jul 04, 2006 9:56 pm    Post subject: Force cache flush in Linux? Reply with quote

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:
Code:
$ cp null null2

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
View user's profile Send private message
dmitchell
Veteran
Veteran


Joined: 17 May 2003
Posts: 1159
Location: Austin, Texas

PostPosted: Tue Jul 04, 2006 10:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
RiBBiT
Apprentice
Apprentice


Joined: 18 May 2005
Posts: 215
Location: Sweden

PostPosted: Tue Jul 04, 2006 10:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
sundialsvc4
Guru
Guru


Joined: 10 Nov 2005
Posts: 436

PostPosted: Thu Jul 06, 2006 12:40 am    Post subject: Reply with quote

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
View user's profile Send private message
RiBBiT
Apprentice
Apprentice


Joined: 18 May 2005
Posts: 215
Location: Sweden

PostPosted: Thu Jul 06, 2006 1:07 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum