Optimizing Desktop Heap

On a heavily-loaded server, you may experience issues running a large number of jobs on an Argent Queue Engine, or simulating virtual concurrent users using Argent Defender.

All of these tasks involve a large number of processes that run in the background, with each process consuming its share of resources.

When issues arise, you may notice error messages in your Event Logs that look like something like this:

  • “Out Of Memory”
  • “Initialization of the dynamic library \system32\user32.dll failed”
  • “Initialization of the dynamic library \system32\kernel32.dll failed”
  • “A desktop heap allocation failed”

Strangely enough, the server shows a huge amount of free memory and available CPU resources — so what’s the deal here?

What you are actually facing is a Microsoft limitation known as desktop heap.

Desktop Heap — What Is It?

First off, desktop heap is NOT the same as virtual storage, or “core” — desktop heap is used as a general-purpose Operating System work area, reserved for storing user interfaces, menus, strings and hooks.

The heap resources are further divided across three types of heap:

Common Heap (1,024 KB)
  • Shared, common, and global handles
  • Interactive Heap (3,072 KB)
  • Windows, hooks, menus for processes that can be seen and interactively operated by the user
  • Non-Interactive Heap (512 KB)
  • Windows, hooks, menus for non-interactive processes that run in the background
  • On Windows 2000 machines, there may also be a fourth value designated for terminal services.

    Note: Each value is the maximum amount of memory allowed per process.

    As you can clearly see, Microsoft did NOT intend for any background, non-interactive process to consume more than 512 KB of resources.

    Luckily, Microsoft provides a registry setting that allows you to control the amount of heap available to each type of resource.


    HKLM\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

       %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows

       SharedSection=1024,3072,512 Windows=On SubSystemType=Windows

       ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3

       ServerDll=winsrv:ConServerDllInitialization,2 ProfileControl=Off

       MaxRequestThreads=16

    The first value (blue) is the Common Heap — don’t change this.

    The second value (red) is the Interactive Heap.

    The third value (green) is the Non-Interactive Heap.

    Resolving ‘Out Of Memory’ and ‘Desktop Heap Allocation’ Errors

    Change the third value (green) to 3072 — this gives the non-interactive heap as many resources as the interactive heap:


    HKLM\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

       %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows

       SharedSection=1024,3072,3072 Windows=On SubSystemType=Windows

       ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3

       ServerDll=winsrv:ConServerDllInitialization,2 ProfileControl=Off

       MaxRequestThreads=16

    IMPORTANT NOTE

    MICROSOFT REQUIRES A REBOOT AFTER CHANGING THIS REGISTRY VALUE.

    After the reboot, double-check the registry key to ensure the changes have been made.

    Typically, these changes will greatly enhance the stability of your Windows operating system.

    However, as these are Microsoft issues, Argent’s suggestions for Microsoft design and implementation problems are simply suggestions – please contact Microsoft support in your region for more details.