Skip to content

Commit 97d956b

Browse files
authored
Improve windows mmap block performance (#264)
I noticed that the write performance was very poor on Windows when running bb_worker. Specifically during the initial fetch of all of the blobs from the CAS, bb_worker was spending a lot of time stuck in the WriteAt function. Writing via the memory map reduced this back down to almost nothing.
1 parent 89b9202 commit 97d956b

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

pkg/blockdevice/memory_mapped_block_device_windows.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,11 @@ func (bd *memoryMappedBlockDevice) ReadAt(p []byte, off int64) (n int, err error
8080
}
8181

8282
func (bd *memoryMappedBlockDevice) WriteAt(p []byte, off int64) (int, error) {
83-
// Like the unix implementation, we let write actions go through
84-
// the file handle.
85-
nTotal := 0
86-
for len(p) > 0 {
87-
var overlapped windows.Overlapped
88-
overlapped.Offset = uint32(off)
89-
overlapped.OffsetHigh = uint32(off >> 32)
90-
var bytesWritten uint32
91-
err := windows.WriteFile(bd.fileHandle, p, &bytesWritten, &overlapped)
92-
nTotal += int(bytesWritten)
93-
if err != nil {
94-
return nTotal, err
95-
}
96-
p = p[bytesWritten:]
97-
off += int64(bytesWritten)
98-
}
99-
return nTotal, nil
83+
// Unlike the unix implementation, we directly copy the data into the
84+
// memory-mapped region. Performance testing on Windows shows that this
85+
// is significantly faster than writing via the file handle,
86+
// particularly when there are multiple parallel writes.
87+
return copy(bd.data[off:], p), nil
10088
}
10189

10290
func (bd *memoryMappedBlockDevice) Sync() error {

0 commit comments

Comments
 (0)