Memory mapped files remain in physical memory?

I have a process that uses a lot of memory mapped files.
The problem is that these files are stored in physical memory, even if the machine is inactive in memory, and other processes require this memory.

I tried to use SetProcessWorkingSetSize to limit the working set of processes, but this does not help, the working set of the process continues to grow above the maximum value.

Is there a better way to limit the working set of a process?
Can I change the Windows heuristics for displayed page files?

+4
source share
4 answers

Finished using brute force VirtualUnlock.

PROCESS_MEMORY_COUNTERS pmc; if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { if (pmc.WorkingSetSize > MaxWorkingSetSize) { VirtualUnlock(FilePtr.pData, MaxWorkingSetSize); UnmapViewOfFile(FilePtr.pData); CloseHandle(FilePtr.hFileMap); CloseHandle(FilePtr.hFile); } } 
+2
source

If you find that your process with memory-bound files is held on many of these pages, then this means that the OS did not need to drop any of your memory-mapped areas for transfer to other processes. So, how do you know that other processes actually need the memory currently used for mapped files? Just because the OS on physical RAM is small, doesn’t mean anything. Other processes require memory to force the OS to abandon the displayed pages and provide them with RAM.

So, it looks like your mmap-I / O process is starving for your other process, which uses RAM less often. One approach is to intelligently block memory during fasting. Take a look at VirtualLock for win32.

+2
source

I think this behavior is related to how the MMF (Memory Mapped Files) work. Check out this blog article. It explains that MMF files skip the Windows swap process and are thus not supported by the page file. Instead, the MMF becomes a backup of the data on its own, which means that it ultimately takes up more memory because it is not pages (Er, I'm not sure I get it myself), it’s best to read the blog!)

Here is the MSDN documentation for memory mapped files and here is another SO question related to MMF.

0
source

Check out my answer here ; with VirtualUnlock () you can manually disable parts of the MMF; for example, sections that you don’t think will be accessed soon.

0
source

All Articles