How to flush drive on Windows

think2

Senior member
Dec 29, 2009
250
3
81
I've heard that hard drives use write caching and reordering to improve performance. How does a journaling filesystem like NTFS or a database engine force a drive to actually write all the data it's been given? Does FlushFileBuffers do it?
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
I've heard that hard drives use write caching and reordering to improve performance. How does a journaling filesystem like NTFS or a database engine force a drive to actually write all the data it's been given? Does FlushFileBuffers do it?
yes, that function will do it for the file that you have opened in your program. won't do it for the whole filesystem though
 

razel

Platinum Member
May 14, 2002
2,337
90
101
They don't force. NTFS or 'database engine' don't care what happens with the storage system. It's up to the OS or storage system (HDD, RAID, SSD, NAS, etc) to deal with the write cache or reordering.
 

Cerb

Elite Member
Aug 26, 2000
17,484
33
86
They don't force. NTFS or 'database engine' don't care what happens with the storage system. It's up to the OS or storage system (HDD, RAID, SSD, NAS, etc) to deal with the write cache or reordering.
You're write about ordering, simply because IDE/ATA has never had queued barriers, TMK. But they care about caching.

1. NTFS == the OS. It has barriers to implement, to maintain the state of the data and metadata, which will include the occasional buffer flushing.

2. Write caching might not be able to be turned off, or bypassed. This has long been a problem with HDDs, since write caching allows much higher performance. So, the HDD will be lying when it returns that it flushed its buffers.

3. What DBMS doesn't care about what happens with the storage system? I would not want to ever have to rely on such a product, that's for sure. Total apathy example. Even SQLite can be configured to ask for syncs all the time, to help ensure that data is where it expects it to be (Firefox does so, FI, and has had performance issues to deal with because of it, over the years). This is among the reasons why several SSD makers have advertised not using DRAM write caches, as that has long been an issue with HDDs (Crucial, Intel, and Samsung, right off): a successful write is one that actually happens, every time, rather than possibly being in a hidden queue to be written.
 

think2

Senior member
Dec 29, 2009
250
3
81
Finally found something authoritative
winntfs - dilip naik

<quote>
In any case, what is worth noting is that all NTFS versions up to and including Windows 7 and Windows 2008 R2 depend upon FUA to ensure that NTFS. NTFS in Windows 8 has switched to using the FlushFileBuffers API instead of depending upon the Forced Unit Access behavior.
</>


http://monolight.cc/2011/06/barriers-caches-filesystems/

<quote>
SATA does have the “FLUSH CACHE EXT” command, but whether the drive actually acts on it depends on the vendor. Get SCSI/SAS drives for mission critical data – nothing new here.
</>

So I'm guessing that FlushFileBuffers will work with some SATA drives and not others. Now I have to try and find which ones. And I still don't know what an IO barrier is in relation to a hard drive but I suspect it's a Linux thing.