Windows is leaking memory when reading random chunks of a large file

Nazar Mokrynskyi 0 Reputation points
2024-02-28T10:45:31.14+00:00

I'd like Windows developers to look at the issue reported here: https://internals.rust-lang.org/t/high-memory-usage-on-random-file-reads-using-seek-read-windows/20396 Tl;DR: A small Windows app (in the thread linked above) reads tiny chunks of a large 500G file at random and uses 0.5M of RAM, while total memory used by Windows increases by ~1G instead and I have no idea where it goes. This is MUCH worse when even larger files are involved, similar app easily makes Windows use over 100G of RAM for no good reason. Reproducible on Windows 10 and 11. Originally asked at https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/windows-is-leaking-memory-when-reading-random/965c422c-cb71-4dbb-9d3e-49dfa7b9df76, but was recommended to ask here instead.

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2024-02-28T14:46:10.92+00:00

    I have no idea where it goes.

    Use the Vmmap and Rammap tools to analyze memory.

    https://learn.microsoft.com/en-us/sysinternals/downloads/vmmap

    https://learn.microsoft.com/en-us/sysinternals/downloads/rammap

    Start by running your program against a small file. If there is a memory leak bug in your code, or as a result of some Windows API call, you should see memory gradually increase the longer your program runs. And if you let it run long enough it should eventually consume all available memory.

    In the process explorer and task manager images that you posted the private bytes graph shows a consistent value. To me that does not indicate a leak. If your memory usage increases only when size of the file it reads increases, then I would suspect that Windows or Rust is just caching the file contents.

    Look at the File Summary and File Details tabs in Rammap. Vmmap will also show Mapped File details.

    FYI, I am not familiar with the Rust programming language.


  2. Nazar Mokrynskyi 0 Reputation points
    2024-03-03T00:24:21.3733333+00:00

    Live chat support representative suggested to post in yet another place, mentioning here for continuity: https://techcommunity.microsoft.com/t5/microsoft-learn/windows-is-leaking-memory-when-reading-random-chunks-of-a-large/m-p/4074012

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.