FlushViewOfFile, lazy writing, cache manager

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Martin Kochanski (nothing_at_nobody.net)
Date: 03/09/04


Date: Tue, 09 Mar 2004 11:59:52 +0000

If I open a file under Windows XP, create a memory-mapped view of it,
alter a few bytes somewhere in the middle of it, go out to lunch and
come back to find there's been a crash or a power failure, then the
altered bytes have not been written to the disk. Either there isn't a
built-in lazy writer thread for dirty pages that are backed by a user
file, or it isn't working (or it's very lazy indeed).

At first sight FlushViewOfFile would appear to be the solution to this
problem, since it is documented as flushing out dirty pages to the disk.

However, a more detailed look at the documentation shows that this is
exactly what FlushViewOfFile does not do. Instead it passes dirty pages
out to the Windows cache manager, which at some undetermined time in the
future may get its lazy writer to write them out. (I am aware that this
can be circumvented by FILE_FLAG_WRITE_THROUGH, but that has other
disadvantages).

So my first question is: does the cache manager's lazy writer write out
pages in any reasonable time, or will they sit there in physical RAM,
marked as dirty, for hours?

The other question is whether any of this actually applies to Windows
XP. One of the claims made for the architectural changes in XP is that
there is now a single memory manager, so that, for example, "cache
coherency with user mapped files is free" (this is a quote from a MS
presentation).

If this is the case, it seems that there should be no difference between
the dirty page being in user mapped memory and in the cache manager's
mapped memory, so that FlushViewOfFile effectively becomes a no-op. My
second question, then, is: in Windows XP (without
FILE_FLAG_WRITE_THROUGH) does FlushViewOfFile do anything at all, and,
if so, what?



Relevant Pages

  • Re: new PC specs for Xilinx tools
    ... How much memory should I get? ... For simulation cache size is very important. ... shows that NC simulations run about 10% faster clock for clock on a Core2 ... If you must use Windows then get a 64 bit ...
    (comp.arch.fpga)
  • Re: NV Cache v Ready Boost
    ... Windows ReadyDrive enables computers shipped with a hybrid hard drive ... USB flash drives, to be used as an additional memory cache in order to ...
    (microsoft.public.windows.vista.performance_maintenance)
  • Re: System Cache Too Big - 219/512 MB. Help!
    ... Swap: http://www.webopedia.com/TERM/s/swap.html ... I need to know how to set the System Cache to something a little ... Memory Management is set to Programs in Windows. ...
    (microsoft.public.windowsxp.general)
  • Re: How does one stop cache flushing?
    ... cache size drops dramaticly and unnesssarily). ... The working set is the memory that has been recently used so Windows expects that it is used again in the near future. ...
    (microsoft.public.windowsxp.general)
  • Re: Determining free memory on FreeBSD 4.8-REL
    ... > How do I determine if my FreeBSD is actually low on memory not? ... You can view all of Inactive, Cache and Free as free memory. ... difference is if the memory might be "dirty" and need to be flushed to ... The other reason is that FreeBSD starts swapping before it absolutely ...
    (freebsd-questions)