More control over memory mapped files and working set size

Martin Sedlmair 31 Reputation points
2021-11-06T14:26:46.21+00:00

I'm having a lot of question regarding memory mapped files, but currently no one was able to answer specific question. Reading Mark Russinovichs' book didn't help to clarify the details.

My problem is that I'm completely relying on memory mapped files since my data is very large. Originally I did my own - lets call if file-based GC and paging - to offload currently unused memory regions into individual user-defined files. But I had to write my own mechanism to manage modified and unmodified regions and map them back and forth manually. This approach worked well, since it started to page in good memory conditions and became more aggressive when the physical RAM was decreasing more and more, also this mechanism had ther ability to stop other threads so that the paging manager was able to do his work and no one else was producing additional memory.

Since this is what memory mapped files also do I wanted to switch to those. The only problem is that it all works well until the commited memory and the working set reach the size of the physical RAM. Then the memory manager starts to page so heavily that the system freezes and sometimes freezes so much that windows had to be restarted. The problem is that I'm obviously producing so much memory in a very short period of time that the timing conditions in the KeBalanceSetManager and the ModifiedPageWriters are not meet. What happens is that pages are written, but I'm still allocating a lot of memory. This leads to the point where Windows is trying to page but doesn't get out of this condition because I'm allocating too much.

The situation would be much easier if I could throttle allocating memory or even stop my application from allocating until good physical memory conditions are met again, but I have no clue if there are methods how to handle this. I cannot ask the current comitted memory size, because event if everything is pages the working set keeps its size. The only remedy is to call EmptyWorkingSet which really trims the working set. Using QueryMemoryResourceNotification didn't help as well since it is obviously bound to the workingset which is only trimmed when calling EmptyWorkingSet.

The question is if I can have either more control of memory mapped files or at least if there is a method of how ask the system about its memory conditions?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
1,891 questions
No comments
{count} votes

Accepted answer
  1. Alon Fliess 251 Reputation points Microsoft MVP
    2021-12-10T01:06:58.7+00:00

    Hi,
    Maybe this (Memory Performance Information) is what you are looking for.

    Alon.


0 additional answers

Sort by: Most helpful