Posted by: kurtsh | February 20, 2007

TOOL: How to flush out the disk write cache to a drive

While I was writing my post on Process Explorer, I stumbled on an updated tool that I’ve been using since 1997 when Mark Russinovich first created it for his original web site, http://www.ntinternals.com.  (I believe our lawyers might have forced him to change the name to Winternals.com because a decade ago our legal department went gonzo about hunting down people that used the term NT in their domain names, claiming copyright.  Whatever.)

In any case, the tool used to be called NTFLUSH.EXE, which I still have.  It’s apparently now called "Sync 2.0", which is as the file name describes, a way to either "flush" the NT write cache ro "sync" the NT write cache such that changes made to the file cache in memory are "synced" with what’s actually on disk.

See, when you write changes to the disk, those changes aren’t necessarily immediately written.  Instead they’re written to the file cache in memory for writing back to disk at a later time when there’s less activity and more CPU available.  And usually this isn’t a problem:  After all, the only way that you’d suffer data loss from NOT writing these changes to disk would be if the power went out, the user suddenly and unexpectedly turned off the computer, or if the disk got yanked out unexpectedly from the PC.

Scenarios 1 & 2 aren’t likely.  Most people are smart enough to know that hard reseting a computer results in potential data loss, and the resulting performance benefit to the end user of having a write cache is so huge that it’d be terrible not to have it available.

Scenario 3 however is very common:  If you have a SDFlash card, a USB thumb stick, a USB connected hard drive, a PC Card based microdrive, or any one of these scenarios, you can see how easy it would be to simply YANK the storage off the PC… the same PC that might have content in the write cache waiting to write it to the disk.  This is the reason why you’re supposed to "safely remove" the device before unplugging it.

But the problem is that using the "safely remove hardware" feature in the Systray is a pain in the ass.  It takes 4 or 5 clicks of the mouse just to do what you used to do by just yanking the drive out from the USB port.  That’s why NTFLUSH/SYNC is interesting.  If you put it in your Start Menu or your Quick Link bar and run it right before you pull a USB drive or Flash card out, you can be sure that you aren’t going to suffer an data loss from latent writes.

Anyway, the tools still on the Sysinternals site, and it’s certainly worth picking up.

DOWNLOAD:
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Sync.mspx


Categories