Wednesday, September 19, 2007

Desktop heap and GDI objects, usage and monitoring


When working with Lotus Notes and many IExplorer windows you might run into problems with random applications that will not open a new window or Windows will even throw an error:


Initialization of the dynamic library \system32\[kernel32user32.dll] failed. The
process is terminating abnormally.
On my normal laptop there is no problem yet, here is my current physical and free memory:

wmic MEMLOGICAL get TotalPhysicalMemory

TotalPhysicalMemory2087256

wmic OS get FreePhysicalMemoryFree

PhysicalMemory1437220

The taskmgr shows this:


So really, I am not in any problems yet! But if you do have the problem someone wrote about a fix for running out of GDI objects. He describes how it is actually a problem with the desktop heap settings and links to Windows Desktop Heap Tweak Guide and Microsofts own description of the problem.

To sum the solution it should be fixing this registry key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
Manager\SubSystems\Windows
My default setting is:
%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
Possible change:

Windows SharedSection=1024,3072,512

to:

Windows SharedSection=1024,8192,2048

I am not currently aware of the number of GDI objects where i will run into problems, but i hope to get an example from my collegue.

For the future I am interested in knowing how many GDI objects are created and where in these two cases, using a specific application from Citrix:
  • GDI object count on client, when application running on client

  • GDI object count on citrix server and client, when application is started from Citrix WI

I would like some util to monitor and alert on GDI object usage. Some ideas:
  • Task manager, add the column, this is easy.

  • Maybe Process Monitor, now maintained by Microsoft, can be used? MISSING.

  • WMI should be possible, but i have not found the path or alias to use in wmic:MISSING

  • Add counter in perfmon: MISSING INFO
My other notes during all this reading:

Overview of Performance Monitoring seems to show that GDI objects are not monitored in system monitor. I dont know if this is correct.

This article could be interesting to learn from: How to Use Remote Tools to Track Memory Leaks in Windows CE Applications.

EDIT 1:
I am still looking for tools for GDI object monitoring:
http://www.google.dk/search?hl=da&client=firefox-a&rls=org.mozilla%3Ada%3Aofficial&hs=m2Z&q=wmi+class+for+gdi+objects&btnG=S%C3%B8g&meta=

I am not the only one missing GDI count for a process:
http://www.ureader.com/message/33360788.aspx

There is a monitoring tool, Usage Monitor 1.8.0.3, I tried it, but you can only put a watch limit for one process, not a total limit. But watches can be placed on: Memory Usage, GDI Objects, and USER Objects.

679F88EA6D30D0035E26EC5B88E64063 umon-1.8.0.3.zip

Another monitor tool:
http://www.mmdfactory.com/logger.html

EDIT2:
Another fix was suggested by a collegue:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]"GDIProcessHandleQuota"=dword:00007530

To check it from batch file, which runs regedit /s file-with-above-content:
Set ExeError=%ErrorLevel%
If .%ExeError%==.0 Set RCValue=%ExeError%

Another way to check GDI object usage was suggested: process explorer.




2 comments:

Unknown said...

Google for "Microsoft Desktop Heap Monitor"

J said...

Patrick, thanks a lot for the hint! The dheapmon.exe -s is great for baselining and troubleshouting workstations and servers with GUI problems!

Now that I am here, I would recommend anyone the following articles with explanation of what desktop heap is, why it can give problems, some example usage, diagnosing, etc:

http://blogs.msdn.com/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx

http://blogs.msdn.com/ntdebugging/archive/2007/07/05/desktop-heap-part-2.aspx