Fix a windows performance issue when shutting down block devices #288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Whilst writing the integration test for buildbarn in bb-deployments, I noticed that bb_storage took a long time to shutdown on Windows. When looking at the system monitor, bb_storage was saturating the disk writing out data on shutdown. This was unexpected, since the test only wrote a small amount of data to the cache, so only a small amount of the block device should have been used (hundreds of MBs out of the GBs in the block device).
It seems that when using SetEndOfFile, Windows will write out the entire file's contents when the process gets shutdown. This is a problem if buildbarn is started with a large block device but only uses a small part of it, like in the deployment tests.
Following the suggestions at https://devblogs.microsoft.com/oldnewthing/20110922-00/?p=9573 we now create a sparse file and instantly zero the entire file's contents (if it's new or is resized). This completely fixes the performance issues.