aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorj.laycock <joseph.laycock@4sightimaging.com>2019-09-11 10:41:59 +0100
committerj.laycock <joseph.laycock@4sightimaging.com>2019-09-11 10:42:37 +0100
commitc1a928887a0da5825b7ba36ddb0530951eb6ee9a (patch)
treee0e0ba9a1eab8d5fe2171868a066ff91c882f684
parent9ea9a5e97a513ed3cbcf04a4f14f05a344aae65c (diff)
downloadseaweedfs-c1a928887a0da5825b7ba36ddb0530951eb6ee9a.tar.xz
seaweedfs-c1a928887a0da5825b7ba36ddb0530951eb6ee9a.zip
Add some comments/documentation
-rw-r--r--weed/storage/memory_map/memory_map_windows.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/weed/storage/memory_map/memory_map_windows.go b/weed/storage/memory_map/memory_map_windows.go
index 5ce750cf4..82d7696f1 100644
--- a/weed/storage/memory_map/memory_map_windows.go
+++ b/weed/storage/memory_map/memory_map_windows.go
@@ -71,6 +71,8 @@ func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxLength uint64) {
}
func (mMap *MemoryMap) DeleteFileAndMemoryMap() {
+ //First we close the file handles first to delete the file,
+ //Then we unmap the memory to ensure the unmapping process doesn't write the data to disk
windows.CloseHandle(windows.Handle(mMap.file_memory_map_handle))
windows.CloseHandle(windows.Handle(mMap.File.Fd()))
@@ -145,7 +147,6 @@ func (mBuffer *MemoryBuffer) ReleaseMemory() {
}
func allocateChunk(mMap *MemoryMap) {
-
start := uint64(len(mMap.write_map_views)) * chunkSize
mBuffer, err := allocate(windows.Handle(mMap.file_memory_map_handle), start, chunkSize, true)
@@ -159,6 +160,7 @@ func allocate(hMapFile windows.Handle, offset uint64, length uint64, write bool)
mBuffer := MemoryBuffer{}
+ //align memory allocations to the minium virtal memory allocation size
dwSysGran := systemInfo.dwAllocationGranularity
start := (offset / uint64(dwSysGran)) * uint64(dwSysGran)
@@ -177,6 +179,8 @@ func allocate(hMapFile windows.Handle, offset uint64, length uint64, write bool)
currentMinWorkingSet = currentMinWorkingSet + aligned_length
currentMaxWorkingSet = currentMaxWorkingSet + aligned_length
+ // increase the process working set size to hint to windows memory manager to
+ // prioritise keeping this memory mapped in physical memory over other standby memory
var _ = setProcessWorkingSetSize(uintptr(currentProcess), uintptr(currentMinWorkingSet), uintptr(currentMaxWorkingSet))
addr_ptr, errno := windows.MapViewOfFile(hMapFile,
@@ -254,6 +258,7 @@ func getSystemInfo() (_SYSTEM_INFO, error) {
// PSIZE_T lpMinimumWorkingSetSize,
// PSIZE_T lpMaximumWorkingSetSize
// );
+// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprocessworkingsetsize
func getProcessWorkingSetSize(process uintptr, dwMinWorkingSet *uint64, dwMaxWorkingSet *uint64) error {
r1, _, err := syscall.Syscall(procGetProcessWorkingSetSize.Addr(), 3, process, uintptr(unsafe.Pointer(dwMinWorkingSet)), uintptr(unsafe.Pointer(dwMaxWorkingSet)))
@@ -270,6 +275,7 @@ func getProcessWorkingSetSize(process uintptr, dwMinWorkingSet *uint64, dwMaxWor
// SIZE_T dwMinimumWorkingSetSize,
// SIZE_T dwMaximumWorkingSetSize
// );
+// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setprocessworkingsetsize
func setProcessWorkingSetSize(process uintptr, dwMinWorkingSet uintptr, dwMaxWorkingSet uintptr) error {
r1, _, err := syscall.Syscall(procSetProcessWorkingSetSize.Addr(), 3, process, (dwMinWorkingSet), (dwMaxWorkingSet))