I have a specific ram-intensive program I run which slows down my entire system for hours after each run - does the Windows NT 6.0/6.1 kernel have any tunables to encourage processes' working sets to be paged back into RAM quicker?
The program in question reads a 1.5GB file into a 1.5GB malloc'ed buffer, does a little processing for a minute, and then quits.
While it is running, all other programs are paged out to disk as expected. When the program ends, the programs are not paged back again. Even if I wait hours, they do not get brought back. That means when I show up and try to use my computer it's painfully slow for ages while it slowly pages each process back in as I use it.
It appears when the process has exited, the "Cached" memory number shown by task manager is very large, and "Free" is very low. Every running process only uses 1 or 2 MB of "Working set", whereas they have normal amounts of "Commit size", indicating most of their pages are on disk.
To me this appears that Windows is using RAM for disk cache to keep my large 1.5GB file just incase I want to re-read it (which I don't), rather than fetching back my normal processes. Is there any way to force this balance towards processes and away from disk cache?
Windows does not page memory back in for your other processes back in until those pages are actually used by them. There are no parameters (that I know of) that will cause pages to be paged back in until those pages are actually referenced.
If it did do that, it would frequently waste time and RAM paging in stuff you don't end up using. Supposed you have five processes mostly paged out. Which one should it bring back? Take a guess? A little bit of all of them? Or wait until you start using one and then make as much RAM available for that one as possible?
Windows, especially newer versions, does aggressively use excess RAM to cache "hot" files, but this never comes at the expense of programs that need RAM. These pages are quickly sacrificed to other processes that need memory. It's fast, because disk cache pages don't need to be paged out to the page file. They are just remapped into the address space of the process that needs it.
(And I sincerely doubt that a 1.5GB file that's opened once makes it to "hot" file status.)
It sounds to me like everything is working normally, but that you could stand to add more RAM or perhaps upgrade to a faster drive.
If you still think something is fishy, please post more specific information, like which version of Windows you're using, how much RAM the machine has, etc.
You can pass hints to
CreateFile
to suggest that Windows doesn't cache the file. This will discourage it from paging out the other processes in the first place.