diff options
| author | j.laycock <joseph.laycock@4sightimaging.com> | 2019-10-01 12:21:44 +0100 |
|---|---|---|
| committer | j.laycock <joseph.laycock@4sightimaging.com> | 2019-10-01 12:21:44 +0100 |
| commit | eb27c2b03762b2ff214824fad504aa348f397afd (patch) | |
| tree | 09242f2b7047544720bd9ccca3cb6929666875cb /weed/storage/memory_map | |
| parent | d5f5acb734738e89326ca49aee241b1f6a6c270c (diff) | |
| download | seaweedfs-eb27c2b03762b2ff214824fad504aa348f397afd.tar.xz seaweedfs-eb27c2b03762b2ff214824fad504aa348f397afd.zip | |
Make releaseMemory private and return byte array instead, fix other platform compilation issues, reduce in-memory chunk size.
Diffstat (limited to 'weed/storage/memory_map')
| -rw-r--r-- | weed/storage/memory_map/memory_map.go | 12 | ||||
| -rw-r--r-- | weed/storage/memory_map/memory_map_windows.go | 22 |
2 files changed, 19 insertions, 15 deletions
diff --git a/weed/storage/memory_map/memory_map.go b/weed/storage/memory_map/memory_map.go index 4baf6fc1f..5f0327ea7 100644 --- a/weed/storage/memory_map/memory_map.go +++ b/weed/storage/memory_map/memory_map.go @@ -25,16 +25,16 @@ type MemoryMap struct { var FileMemoryMap = make(map[string]*MemoryMap) -func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) { - +func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxLength uint64) { } -func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (MemoryBuffer, error) { - return MemoryBuffer{}, fmt.Errorf("Memory Map not implemented for this platform") -} +func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) { -func (mBuffer *MemoryBuffer) ReleaseMemory() { +} +func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) ([]byte, error) { + dataSlice := []byte{} + return dataSlice, fmt.Errorf("Memory Map not implemented for this platform") } func (mBuffer *MemoryMap) DeleteFileAndMemoryMap() { diff --git a/weed/storage/memory_map/memory_map_windows.go b/weed/storage/memory_map/memory_map_windows.go index a06b7947c..ac4493188 100644 --- a/weed/storage/memory_map/memory_map_windows.go +++ b/weed/storage/memory_map/memory_map_windows.go @@ -48,7 +48,7 @@ var currentMaxWorkingSet uint64 = 0 var _ = getProcessWorkingSetSize(uintptr(currentProcess), ¤tMinWorkingSet, ¤tMaxWorkingSet) var systemInfo, _ = getSystemInfo() -var chunkSize = uint64(systemInfo.dwAllocationGranularity) * 256 +var chunkSize = uint64(systemInfo.dwAllocationGranularity) * 128 var memoryStatusEx, _ = globalMemoryStatusEx() var maxMemoryLimitBytes = uint64(float64(memoryStatusEx.ullTotalPhys) * 0.8) @@ -82,7 +82,7 @@ func (mMap *MemoryMap) DeleteFileAndMemoryMap() { windows.CloseHandle(windows.Handle(mMap.File.Fd())) for _, view := range mMap.write_map_views { - view.ReleaseMemory() + view.releaseMemory() } mMap.write_map_views = nil @@ -130,17 +130,21 @@ func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) { } } -func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (MemoryBuffer, error) { - return allocate(windows.Handle(mMap.file_memory_map_handle), offset, length, false) +func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (dataSlice []byte, err error) { + dataSlice = make([]byte, length) + mBuffer, err := allocate(windows.Handle(mMap.file_memory_map_handle), offset, length, false) + copy(dataSlice, mBuffer.Buffer) + mBuffer.releaseMemory() + return dataSlice, err } -func (mBuffer *MemoryBuffer) ReleaseMemory() { +func (mBuffer *MemoryBuffer) releaseMemory() { windows.VirtualUnlock(mBuffer.aligned_ptr, uintptr(mBuffer.aligned_length)) windows.UnmapViewOfFile(mBuffer.aligned_ptr) - currentMinWorkingSet = currentMinWorkingSet - mBuffer.aligned_length - currentMaxWorkingSet = currentMaxWorkingSet - mBuffer.aligned_length + currentMinWorkingSet -= mBuffer.aligned_length + currentMaxWorkingSet -= mBuffer.aligned_length if currentMinWorkingSet < maxMemoryLimitBytes { var _ = setProcessWorkingSetSize(uintptr(currentProcess), currentMinWorkingSet, currentMaxWorkingSet) @@ -182,8 +186,8 @@ func allocate(hMapFile windows.Handle, offset uint64, length uint64, write bool) access = windows.FILE_MAP_WRITE } - currentMinWorkingSet = currentMinWorkingSet + aligned_length - currentMaxWorkingSet = currentMaxWorkingSet + aligned_length + currentMinWorkingSet += aligned_length + currentMaxWorkingSet += aligned_length if currentMinWorkingSet < maxMemoryLimitBytes { // increase the process working set size to hint to windows memory manager to |
