From 4257582db5e70ea628ef7f7d45cf2b5bcc6a3eda Mon Sep 17 00:00:00 2001 From: "j.laycock" Date: Thu, 5 Sep 2019 11:15:01 +0100 Subject: [PATCH] Allocate in 16MB chunks, make creation of memory maps always aligned to 16MB chunks --- weed/storage/memory_map/memory_map_windows.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/weed/storage/memory_map/memory_map_windows.go b/weed/storage/memory_map/memory_map_windows.go index 055aeacc5..c5deef84a 100644 --- a/weed/storage/memory_map/memory_map_windows.go +++ b/weed/storage/memory_map/memory_map_windows.go @@ -38,19 +38,26 @@ var ( var system_info, err = getSystemInfo() -var chunk_size = uint64(system_info.dwAllocationGranularity) * 512 +var chunk_size = uint64(system_info.dwAllocationGranularity) * 256 func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxlength uint64) { - maxlength_high := uint32(maxlength >> 32) - maxlength_low := uint32(maxlength & 0xFFFFFFFF) + chunks := (maxlength / chunk_size) + if chunks*chunk_size < maxlength { + chunks = chunks + 1 + } + + alignedMaxLength := chunks * chunk_size + + maxlength_high := uint32(alignedMaxLength >> 32) + maxlength_low := uint32(alignedMaxLength & 0xFFFFFFFF) file_memory_map_handle, err := windows.CreateFileMapping(windows.Handle(file.Fd()), nil, windows.PAGE_READWRITE, maxlength_high, maxlength_low, nil) if err == nil { mMap.File = file mMap.file_memory_map_handle = uintptr(file_memory_map_handle) - mMap.write_map_views = make([]MemoryBuffer, 0, maxlength/chunk_size) - mMap.max_length = maxlength + mMap.write_map_views = make([]MemoryBuffer, 0, alignedMaxLength/chunk_size) + mMap.max_length = alignedMaxLength mMap.End_of_file = -1 } }