Re: Is there a way to flush the file cache?




Jean-David Beyer wrote:
Tony Lawrence wrote:
General Schvantzkoph wrote:
On Thu, 28 Dec 2006 13:29:24 -0800, Tony Lawrence wrote:

General Schvantzkoph wrote:
I'm writing a system exerciser that checks memory and disk I/O. Is there a
C call that flushes the file cache so that I can be assured that my freads
are coming from the disk and not the RAM. I'm using a sync() but I don't
think that does the whole job, it guarantees that the disk writes happen
but I don't think it clears out the file cache.

Well, of course it can't guarantee that some random app hasn't written
data, if that's what you mean..

What I want to do is the following,

1) Create a file and write it to the disk.
2) Read that file off of the disk and then check it.

I'm trying to check the SATA interfaces so it's important that the file go
to and from the disks. The file cache interferes with this because if the
file is present in the cache the program will get the cached copy not the
copy that is on the disk. The sync() call forces the disk writes to happen
immediately which is half of the battle. The other half is to purge the
file cache so that all subsequent file reads come from the disk. Is there
a way to do this?

O, I see now: you are checking disk performance or maybe even checking
disk integrity.

No, sync won't help with that (because the read can still come from
cache). What you need to do is overwrite the cache with new data
unrelated to the blocks you want to read. That could be as simple as a
well placed "ls -lR".. or much more complex. See
http://www.linuxjournal.com/article/7105

On my machine, I have 8 GBytes RAM, and usually over 3/4 of it are used by
IO buffers and cache. It would take a lot to flush all that. In fact, sync
does not do it.

Right. A "sync" is a request, it doesn't mean "stop everything else
you are doing, write all your buffers to disk and get back to me when
you are done".


Apparently newer kernels have made this easier:
http://linux-mm.org/Drop_Caches

And of course that would require a sync first. I don't know how this
is implemented, but I would guess that it doesn't actually throw away
the cache until sync or a cache overwrite allows it; it probably just
marks the cache as invalid so that subsequent reads would have to go to
the source. I assume that something somewhere ties this all together
so that if you have synced and then dropped, your reads will get
correct data, but I don't know that. It would be simple enough to test
in a VM with artificially constrained memory (or somebody with more
energy than I have could paw through the source and see how it works).

--
Tony Lawrence
Unix/Linux/Mac OS X Resources
http://aplawrence.com

.



Relevant Pages

  • Re: Caching control
    ... |> | invalidate/unmap them in order to discard the data from memory. ... |> writing out to disk. ... | easy to discard as clean disk cache. ... stating that a specific amount of RAM can be used only for I/O ...
    (comp.os.linux.development.system)
  • PROBLEM: sata_sil24 lockups under heavy i/o
    ... a total of 4) and started heavy i/o (extending a software raid5 device) ... system recovers the disk transfer speed is reduced from UDMA/100 to ... Cache Line Size: 32 bytes ... parport_pc: Current parallel port base: 0x378 ...
    (Linux-Kernel)
  • Re: Scheduler: Process priority fed back to parent?
    ... Mac OS X has a special cache ... on disk of things that get loaded on boot. ... >>initial priority is a guess, and isn't set until the priority info has ... This prefetch activity could be turned on/off ...
    (Linux-Kernel)
  • Re: Pull request for FS-Cache, including NFS patches
    ... Would a disk cache on SSD make any sense? ... including NFS patches ... Allow you to reduce the latency of slow network links by diverting ...
    (Linux-Kernel)
  • Re: 2 questions: IWP, and indexing
    ... using GTRR script steps in the web interface. ... I have a portal on the student layout that shows enrollment ... "Flush Cache to Disk performs an immediate flush of the FileMaker Pro ...
    (comp.databases.filemaker)