Align VHD disk data blocks for optimal performance when a VHD resides on storage with 4K sector size.

This commit is contained in:
Mark Pizzolato 2012-02-25 08:45:52 -08:00
parent 98e343f43f
commit 4838d1f7dd

View file

@ -2132,6 +2132,7 @@ typedef struct _VHD_DynamicDiskHeader {
} VHD_DynamicDiskHeader; } VHD_DynamicDiskHeader;
#define VHD_BAT_FREE_ENTRY (0xFFFFFFFF) #define VHD_BAT_FREE_ENTRY (0xFFFFFFFF)
#define VHD_DATA_BLOCK_ALIGNMENT ((uint64)4096) /* Optimum when underlying storage has 4k sectors */
static char *VHD_DiskTypes[] = static char *VHD_DiskTypes[] =
{ {
@ -3214,6 +3215,14 @@ while (sects) {
BitMap = malloc(BitMapSectors*SectorSize); BitMap = malloc(BitMapSectors*SectorSize);
memset(BitMap, 0xFF, BitMapBytes); memset(BitMap, 0xFF, BitMapBytes);
BlockOffset -= sizeof(hVHD->Footer); BlockOffset -= sizeof(hVHD->Footer);
/* align the data portion of the block to the desired alignment */
/* compute the address of the data portion of the block */
BlockOffset += BitMapSectors*SectorSize;
/* round up this address to the desired alignment */
BlockOffset += VHD_DATA_BLOCK_ALIGNMENT-1;
BlockOffset &= ~(VHD_DATA_BLOCK_ALIGNMENT-1);
/* the actual block address is the beginning of the block bitmap */
BlockOffset -= BitMapSectors*SectorSize;
hVHD->BAT[BlockNumber] = NtoHl((uint32)(BlockOffset/SectorSize)); hVHD->BAT[BlockNumber] = NtoHl((uint32)(BlockOffset/SectorSize));
if (WriteFilePosition(hVHD->File, if (WriteFilePosition(hVHD->File,
BitMap, BitMap,