On the interaction between the FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUG...
source link: https://devblogs.microsoft.com/oldnewthing/20210729-00/?p=105494
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
On the interaction between the FILE_FLAG_NO_BUFFERING
and FILE_FLAG_WRITE_THROUGH
flags
Raymond
July 29th, 2021
The CreateFile
function has two related flags: FILE_FLAG_NO_BUFFERING
and FILE_FLAG_WRITE_THROUGH
. These flags can be set independently, but they sort of work together.
First, let’s look at FILE_FLAG_NO_BUFFERING
. Setting this flag prevents operations on the handle from going through the disk cache. Reads come directly from the disk, and writes go directly to the disk.
The FILE_FLAG_WRITE_THROUGH
flag increases the urgency with which write requests are sent to the disk. Setting this flag forces writes to go to the disk immediately, and combining this flag with FILE_FLAG_NO_BUFFERING
adds the additional urgency of telling the disk controller to flush the data out of its internal cache.
So let’s fill out a table.
Lazily written to disk
No hardware flush Writes bypass cache
Immediately written to disk
No hardware flush Set Writes go into cache
Immediately written to disk
Hardware flush Writes bypass cache
Immediately written to disk
Hardware flush
Bonus reading: We’re currently using FILE_FLAG_NO_BUFFERING
and FILE_FLAG_WRITE_THROUGH
, but we would like our WriteFile to go even faster.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK