개발/프로그래밍(일반)

[스크랩] GDI 개체 누수로 인한 문제를 지연할 수 있는 Registry key

kyu76 2012. 6. 13. 17:35

GDI 개체의 누수는 Desktop Heap Memory의 고갈로 인하여 Virtual Memory Pressure 와는 다르게 "Not enough resource" 와 같은 오류를 얻을 수 있다. User mode에서는 좀처럼 확인하기 어렵지만, Task Manager GDI 개체 수나 화면이 깨지거나 하얗게 되는 현상, 또는 Window menu가 정상적으로 보이지 않거나 겹쳐서 그려지는 현상이 발생한다면, 의심해 볼만 하다. 보통 시스템에 GDI 개체 수가 어느 정도 커지면 문제가 발생한다는 특별한 임계값이 있는 것이 아니기 때문에 그때 그때마다 measure 하는 것이 중요하다.

 

GDI Objects (Windows)

 

There is a theoretical limit of 65,536 GDI handles per session. However, the maximum number of GDI handles that can be opened per session is usually lower, since it is affected by available memory.

Windows 2000:  There is a limit of 16,384 GDI handles per session.

There is also a default per-process limit of GDI handles. To change this limit, set the following registry value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\
     CurrentVersion\Windows\GDIProcessHandleQuota

This value can be set to a number between 256 and 65,536.

 

Msdn의 문서를 참조하면, Windows XP환경에서는 65,000여개의 GDI 개체를 생성할 수 있다. 기본적으로는 10,000여개를 사용하는 데, GDIProcessHandleQuota 값의 조정에 의해서 해당 값을 조정할 수 있다. 하지만, 이 값을 max 값으로 늘린다고 해서, 그 개수 만큼 만들어질지는 알 수 없다. 이는 Desktop Heap Memory에 종속적이기 때문에 현재, 시스템의 Desktop heap이 어떻게 사용되고 있느냐에 따라서 특정 ProcessGDI개체 수의 limitation은 달라질 수 있다. (여기서의 limitation은 언급한 Not enough resource 오류가 발생하지 않는 수준을 의미한다.)

 

Desktop Heap Overview

 

Configuring the size of individual desktop heaps

Configuring the size of the individual desktop heaps is bit more complex.  Speaking in terms of desktop heap size, there are three possibilities:

·         The desktop belongs to an interactive window station and is a “Disconnect” or “Winlogon” desktop, so its heap size is fixed at 64KB or 128 KB, respectively (for 32-bit x86)

·         The desktop heap belongs to an interactive window station, and is not one of the above desktops.  This desktop’s heap size is configurable.

·         The desktop heap belongs to a non-interactive window station.  This desktop’s heap size is also configurable.

 

The size of each desktop heap allocation is controlled by the following registry value:

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

 

 The default data for this registry value will look something like the following (all on one line):

                %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

                                                                 

 

Desktop Heap의 전체 Size는 한계가 존재한다. (terminal service를 사용하지 않았을 경우에 48M 정도이다.) 상위의 sharedSection은 전체 Desktop Heap memory를 각 desktop에 어떻게 나눠줄지에 대한 규정으로 보면 된다. 특히, 이중 SharedSection의 두 번째 값인 3072(kb) GDI와 관련이 있는 Interactive window station Desktop Heap Size 를 규정하고 있는 데, 해당 값을 늘린다면, 하나의 desktop에서 사용하는 Memory size가 증가하게 된다. 그러므로, desktop에 존재하는 process 도 더 많은 desktop heap memory를 사용할 수 있게 된다. 하지만, 하나의 window station에서 생성되는 desktop의 수는 줄어들 수밖에 없다. 그러므로, 이러한 것을 고려하여 해당 값들을 조정해야만 한다.

 

그렇다면, 전체 Desktop Heap size를 좀 더 늘릴 수는 없을 까? 이것도 가능하다. 이는 SessionViewSize라는 registry key와 연관이 있다.

 

" The SessionViewSize registry entry specifies the amount of memory that is reserved for desktop heaps. The default value of this entry is 20 megabytes (MB). This memory is allocated for applications to use GUI objects such as fonts, menus, and windows."

 

참조:

Applications may not run correctly in a Terminal Services environment

 

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory ManagementSessionViewSize 를 증가해서 늘릴 수 있다. (해당 문서는 Windows 2003 기준으로 나와있지만, Test한 결과 Windows XP에서 역시 증가되는 것으로 확인할 수 있다.)

출처 : 늦었지만 경제를 공부해야할 때
글쓴이 : 생각좀해보구서 원글보기
메모 :