Do Windows flush commands flush the disk write-cache in addition to the Windows write-cache?

Aaron 51 Reputation points
2021-10-27T18:35:34.1+00:00

There are two write-caches:

Windows has its own write-cache stored in RAM, which it will write to the specified disk at its own pace, in order to increase write performance to the disk.

Additionally, disks themselves generally have a write-cache that is managed by the firmware on the disk. For my purposes, I'm specifically interested in NVMe drives; these drives sometimes have DRAM caches, which are a form of volatile memory.
What I'm wondering, is if when a Windows "flush" command is called, does it just flush the OS-managed write-cache, or also the disk's write-cache, ensuring data is written to persistent storage? I'm curious about the FSCTL_LOCK_VOLUME command, which "flushes all cached data to the volume before locking it". And I am also curious about CM_REQUEST_DEVICE_EJECT, which just "prepares a local device instance for safe removal", according to Windows docs.

So does either the eject or lock volume function--or any other Windows function for that matter--actually send a command to the NVMe drive to flush its device write-cache? I can see in the NVMe specification that there is a flush command to flush its write-cache, but I don't know what Windows calls actually will send this command!

Windows for business Windows Client for IT Pros Devices and deployment Other
{count} votes

1 answer

Sort by: Most helpful
  1. RJR 1 Reputation point
    2022-11-17T06:01:30.29+00:00

    After some searching, I found the following MS File Buffering (AKA System File Caching or Write-Back Cache) article that indicates Windows File Buffering and hardware Write Caching are separate and unrelated cache / buffering mechanism.

    Based on this finding, I would anticipate that, Windows flush commands Do Not flush the disk write-cache in addition to the Windows System File / Write-Back Cache. Only the Windows File Buffer (System File Buffer - Cache) is flushed. Any storage controller (IE RAID cache) or Disk / SSD cache flushing would occur independently.

    (Windows) File Buffering
    https://learn.microsoft.com/en-us/windows/win32/fileio/file-buffering

    "Discussion of caching does not consider any hardware caching on the physical disk itself, which is not guaranteed to be within the direct control of the system in any case. This has no effect on the requirements specified in this topic."

    Note: The above statement implies the above findings.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.