Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory-mapped files remain in physical memory?

Tags:

I have a process that uses a lot of memory mapped files.
Problem is that those files are kept in physical memory, even when the machine is low on memory, and other processes require this memory.

I've tried using SetProcessWorkingSetSize to limit the process working set, but it doesn't help, the process' working set keeps growing over the max value.

Is there a better way to limit the process' working set?
Can I change Windows' heuristcs for paging memory mapped files?

like image 211
Meidan Alon Avatar asked Oct 25 '09 10:10

Meidan Alon


People also ask

Where are memory map files stored?

Memory-mapped files are accessed through the operating system's memory manager, so the file is automatically partitioned into a number of pages and accessed as needed. You do not have to handle the memory management yourself.

What is physical memory map?

In computer science, a memory map is a structure of data (which usually resides in memory itself) that indicates how memory is laid out. The term "memory map" can have different meanings in different contexts. It is the fastest and most flexible cache organization that uses an associative memory.

What is memory mapping in virtual memory?

Memory-mapping is a mechanism that maps a portion of a file, or an entire file, on disk to a range of addresses within an application's address space. The application can then access files on disk in the same way it accesses dynamic memory.

What do you mean by mapping files into memory?

File mapping is the process of mapping the disk sectors of a file into the virtual memory space of a process. Once mapped, your app accesses the file as if it were entirely resident in memory.


1 Answers

Ended up 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);
        }
}
like image 197
Meidan Alon Avatar answered Oct 04 '22 16:10

Meidan Alon