{"id":105494,"date":"2021-07-29T07:00:00","date_gmt":"2021-07-29T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105494"},"modified":"2021-07-29T07:21:19","modified_gmt":"2021-07-29T14:21:19","slug":"20210729-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210729-00\/?p=105494","title":{"rendered":"On the interaction between the <CODE>FILE_<WBR>FLAG_<WBR>NO_<WBR>BUFFERING<\/CODE> and <CODE>FILE_<WBR>FLAG_<WBR>WRITE_<WBR>THROUGH<\/CODE> flags"},"content":{"rendered":"<p>The <code>Create\u00adFile<\/code> function has two related flags: <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code> and <code>FILE_<wbr \/>FLAG_<wbr \/>WRITE_<wbr \/>THROUGH<\/code>. These flags can be set independently, but they sort of work together.<\/p>\n<p>First, let&#8217;s look at <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code>. 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.<\/p>\n<p>The <code>FILE_<wbr \/>FLAG_<wbr \/>WRITE_<wbr \/>THROUGH<\/code> 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 <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code> adds the additional urgency of telling the disk controller to flush the data out of its internal cache.<\/p>\n<p>So let&#8217;s fill out a table.<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th colspan=\"2\" rowspan=\"2\">\u00a0<\/th>\n<th style=\"text-align: center;\" colspan=\"2\">NO_<wbr \/>BUFFERING<\/th>\n<\/tr>\n<tr>\n<th style=\"text-align: center;\">Clear<\/th>\n<th style=\"text-align: center;\">Set<\/th>\n<\/tr>\n<tr>\n<th rowspan=\"2\"><span style=\"writing-mode: vertical-lr; -ms-writing-mode: tb-rl; transform: rotate(180deg);\"> WRITE_<wbr \/>THROUGH<\/span><\/th>\n<th style=\"text-align: center;\">Clear<\/th>\n<td nowrap=\"nowrap\">Writes go into cache<br \/>\nLazily written to disk<br \/>\nNo hardware flush<\/td>\n<td nowrap=\"nowrap\">Writes bypass cache<br \/>\nImmediately written to disk<br \/>\nNo hardware flush<\/td>\n<\/tr>\n<tr>\n<th style=\"text-align: center;\">Set<\/th>\n<td nowrap=\"nowrap\">Writes go into cache<br \/>\nImmediately written to disk<br \/>\nHardware flush<\/td>\n<td nowrap=\"nowrap\">Writes bypass cache<br \/>\nImmediately written to disk<br \/>\nHardware flush<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Bonus reading<\/b>: <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140306-00\/?p=1583\"> We&#8217;re currently using <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code> and <code>FILE_<wbr \/>FLAG_<wbr \/>WRITE_<wbr \/>THROUGH<\/code>, but we would like our WriteFile to go even faster<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s fill in another table.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-105494","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Let&#8217;s fill in another table.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=105494"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105494\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=105494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}