How can I prevent Windows Server 2003 from trimming a process's working set?

There are two different, though I believe related, issues I have with how Windows Server 2003 handles processes's working sets.

First, there are GUI applications running on the console session whose working set is trimmed, when their top-level window is minimized. I know it's rather unusual to have server processes running with a GUI, but these are legacy applications doing important things that I cannot do anything about.

Second, there is a long running database server that allocates a lot of memory when a client connects, but doesn't touch that memory until another client connects. In the mean time, several days may pass and the operating system seems to think that is reason enough to trim that process's working set.

In both cases, there is plenty of physical RAM available (several GB more than the applications would need), so I would like Windows to not trim their working sets. Is there a setting to configure this? These are all third-party applications, so changing memory allocation or locking pages in memory aren't viable options.


Solution 1:

The article that you posted has all the information you're asking for, though I understand it isn't what you want to hear.

First off, I don't know what your applications are or what they do or why their working sets not being trimmed is so important, or any of that other tangential information that might help you on your path to solving the problem that the behavior of the working set of the process is contributing to. It sounds to me like you have a poorly designed application that you have to support, and you're trying to alter the behavior of Windows to compensate for a poorly designed application. That's a crappy situation to be in, and I'm sorry.

That said, I'll try to answer your question:

You're describing a basic, fundamental mechanism in how Windows was designed. The default behavior of the Minimize button on a GUI's window is going to call ShowWindow(hWnd, SW_MINIMIZE) which trims the process' working set - end of story.

The writers of this poorly designed application that you're tending to could have chosen to intercept the WM_SYSCOMMAND message that occurs when a user clicks the Minimize window button and call ShowWindow(hWnd, SW_SHOWMINIMIZED) (which does not trim the WS) instead of ShowWindow(hWnd, SW_MINIMIZE), but they didn't. If you cannot contact the developers of this application and tell them to try again, this time with an actual server application, then you are stuck with this behavior.