lkml.org 
[lkml]   [2009]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectFlushing the (page?) cache for a block device
Hello!

I'd like to do a verification step after writing to a USB stick (block
device level, no filesystem involved). For this to work as intended, I
need to ensure the reads are not satisfied from blocks still in cache,
i.e.: flush "the cache" (page cache IIUC) for the block device in
question (and _only_ this device).
Some research resulted in the following options:

1. Open the target file using O_DIRECT while writing.
Doesn't feel like the right thing to do; only want to flush the
cache, not circumvent it. Might severly limit performance as writes are
synchronous.
Interface isn't very nice (need to ensure alignment to page size
in memory).

2. Use posix_fadvise() with POSIX_FADV_DONTNEED.
Probably works with the current kernel (haven't tested yet), but
there's absolutely no guarantee.
Interface much better than O_DIRECT.

3. Flush the entire page cache using procfs.
Brute force, last resort. Will severly impact performance of my
tool (as it's going to write to several devices in parallel).


Is there a better method I've not found yet? Nr. 2 sounds like the way
to go, but I don't like that it could (silently!) stop working with any
new kernel version.


PS: Not subscribed, so please CC me.

CU Sascha

--
http://sascha.silbe.org/
http://www.infra-silbe.de/
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2009-03-29 15:03    [W:0.037 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site