John Lam 1997 — 2026

Sequential I/O performance

This morning, I was doing some research on sequential I/O performance, and re-read this excellent research paper published by Leonard Chung and Jim Gray at MSR. One of the interesting security-related performance issue raised in this paper can be found in Section 4.4, concerning file pre-allocation:

“When growing a file, it is important to write it in sequential order. Otherwise Windows writes each block twice: once to zero the “gap” and once to write the actual data when the need write finally is issued”.

It is necessary to “zero the gap” to prevent reading data that has not been previously written. Otherwise an attacker would be able to extend a file, and attempt to read the data that was there before. Windows prevents this by zeroing out the bytes in the file to guarantee that 0 is returned when reading data that has not been previously written.

The performance gap is quite severe - write throughput drops by 50% due to the need to write the data twice to disk. Writing to the end of a file does not incur this penalty.

4 archived reader comments

runtime (2003-02-13)

Didn’t Microsoft finally add support for file “holes” in Windows 2000? If you write byte 1 and seek ahead 10 GB and write another byte, there is no need to write 10 GBs of zeroes.

John Lam (2003-02-13)

I suspect the scenario that you describe would work. But consider the case where you pre-allocated a 10GB file, and then did a seek back to offset 0 to begin writing. In that case it would have to fill with 0’s, right? Perhaps it is a fill-on-read scheme? The tests described by the paper were done using Win2K as well as NT4.

Jason Kaczor (2003-02-13)

Uh yeah they did. Actually it is an NTFS feature, here it is: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/sparse_files.asp

Celexa (2004-10-25)

Check Celexa info.