Write-through the hard disk cache to persistent media (+)



Is there a reliable method to ensure that data is commited to physical media
when writing files?

MSDN says:
CreateFile

FILE_FLAG_WRITE_THROUGH
Instructs the system to write through any intermediate cache and go directly to disk.
If FILE_FLAG_NO_BUFFERING is not also specified, so that system caching is in effect,
then the data is written to the system cache, but is flushed to disk without delay.

If FILE_FLAG_NO_BUFFERING is also specified, so that system caching is not in effect,
then the data is immediately flushed to disk without going through the system cache.
The operating system also requests a write-through the hard disk cache to persistent
media. However, not all hardware supports this write-through capability.

I try to get the described behaviour (i.e. FFNB|FFWT to ensure data is
actually stored on plates) but something strange happens. I have a small test
program that writes a preallocated contigous 100MB file (the same file for
all runs) in 32KB blocks sequentially and collects timing data with QPF+QPC.
IO is done synchronously, OS is WinXP Sp2, using 7200 RPM SATA WD drive.

If write caching is enabled I get these results (timing in microsecs). They
don't change whether FFWT flag is set or not.
631
551
581
744
655
538
560
558
668
556
835
544
546
553
503
512
507
....

If write caching is disabled (with a checkbox in Control Panel) I get these
results. Again nothing changes when FFWT is set.
13211
8754
8701
9023
8562
8763
8777
8789
8736
8787
8782
8782
8784
8788
8779
8749
8768
....

I expect to get the results similar to second ones when running with write
cache enabled and oppening file with FFWT|FFNB. I guess that timing ways less
than rotational delay witnesses that no write-through HDD cache actually
happens.

Is there a reliable method to ensure that data is commited to physical media
when writing files?
.



Relevant Pages

  • Re: How to prove data written to disk media?
    ... the hard disk cache to persistent media. ... >> present on the physical media (be it a hard disk or flash disk). ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to prove data written to disk media?
    ... > present on the physical media (be it a hard disk or flash disk). ... Just reading back what is in a cache is unacceptable. ... For example, IDE hard-disks have their own cache, but ...
    (microsoft.public.win32.programmer.kernel)
  • 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)