Sunday, 16 October 2011

Monitoring Desktop Heap Memory and troubleshooting issues (part I)

This article wants to put together a series of interesting articles to monitor the desktop heap memory and finally put forward a little in-house tool to monitor the output of Desktop Heap Information Monitor Tool v8.1 from AireSoft using the algorithm from "capturing output capture" from one of my previous posts.

Installing "Desktop Heap Information Monitor Tool v8.1:
To correctly install the tool (dheapdmp.zip), go to AireSoft web page and follow the installation steps from the web. If an error pops up, follow the guidelines from the following links:
- dheapInst - driver installation error occurred (2).
dheapinst - Driver Installation error occured (124).

If it helps, I got the error "Driver Installation error occured (124)" and I fixed it by changing the compatibility of dheapinst to Windows Server 2003 SP1.

Once installed, if we run dheapmon -l to install the monitor and then again dheapmon, we will see the heap memory information:


More about "Desktop heap memory":
The Desktop Heap Monitor is a tool that examines usage of desktop heap. 

WIN32 subsystem has internal heap area known as "desktop heap." When you run a large number of Windows-based programs, "Out Of Memory" error messages appear when you attempt to start new programs or try to use programs that are already running, even though you still have plenty of physical and pagefile memory available

This behavior can occur if the desktop heap in the WIN32 subsystem is depleted. To fix this problem follow the next workaround :
http://support.microsoft.com/kb/126962/
sourceMicrosoft.


Increasing "Desktop heap memory":

To increase desktop heap memory, we can use the tool "Microsoft Fix It 50496" that will increase the parameters automatically. If you want to fix it manually, you just need to go to the following registry path and tweak it:
- HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems

Where the default values for my windows vista are:

%SystemRoot%\system32\csrss.exe 
ObjectDirectory=\Windows 
SharedSection=1024,12288,512 
Windows=On 
SubSystemType=Windows 
ServerDll=basesrv,1 
ServerDll=winsrv:UserServerDllInitialization,3 
ServerDll=winsrv:ConServerDllInitialization,2 
ProfileControl=Off 
MaxRequestThreads=16



The first SharedSection value (1024) defines the heap size common to all desktops. This includes the global handle table.


The second SharedSection value (12288) controls the size of the desktop heap that is associated with an interactive window station (used for Windows objects). This static value is used to prevent ill- behaved applications from consuming too many resources. Because the desktop heap is mapped into each process' address space, this value should not be set to an arbitrarily high value (as it would decrease performance), but should only be increased sufficiently to allow all the desired applications to run.


The third SharedSection value (512) controls the size of the desktop heap for each desktop that is associated with a "non-interactive" window station.
source : microsoft.

Monitoring Desktop Heap Memory:
As it is quite difficult to monitor, I have developed a little tool that you can download from here, to log every change on the table result.

Just point the tool to the dheapmon executable and press start. Every 10s the output will be scanned and displayed into the component, taking into account the previous value, and if a change occurs it will be displayed in another colour.

Final notes:
Desktop Heap memory is related to "Out of Memory" issues and this article will help you to work with this parameter and how to deal with it and monitor it.

Stay tuned for Part 2, where I will go further with Desktop heap memory using Delphi.
Jordi Corbilla.

Related links:

8 comments:

  1. thanks for recommendation to change compatibility.

    I was getting error: dheapinst - Driver Installation error occured (124)

    Now:
    dheapinst - Desktop Heap Monitor installed successfully

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Well I have the same problem. But how do you change compatibility?

      Delete
  2. Can this tool work on 32-bit Windows XP? It seems to operate but then freezes up the UI window of the tool.

    ReplyDelete
    Replies
    1. Hi Syclone0044,

      The tool was tested under win7, I don't know if the behavior you're experiencing is normal, but it could be. It's using an old version of this algorithm console output. So probably I will update the tool and publish the code somewhere under my repository.

      Jordi

      Delete
  3. The blog post seems very useful and the content posted about desktop memory is great. The post is very helpful for me.
    Thanks for sharing the post.

    ReplyDelete