[Donglcee 동료인 하정훈님의 정말 심도있는 주제에 대한 포스팅] Debug 101: Examining Memory Use

이동철입니다. 제 직장 동료 중에 아주 능력있는 친구(하정훈)가 있는데,, 아 이 친구가 자신이 소유한 자료 중에서 영양가있는 자료를 하나 공유해 준다고 해서... 제가 이렇게 포스팅하게 되었습니다.

이 친구 자료는 저보다는 아주 level의 depth가 깊습니다. 제가 쓴글이 아니라는 점을 다시 한 번 강조합니다 ^-^

"Debugging" 에 관한 아주 영양가 만점의 자료네요,,, 여러분들 참조하세요

-------------------------------------

WinDBG 를 사용하여 Memory 사용량을 알아보는 시간을 가지도록 하겠습니다. 아래에서 우리는 2가지 debugger command 를 확인할 수 있습니다.

!VM 그리고 !memusage 입니다.

왜 2개의 command 인가? 왜냐하면 하나는 Virtual Memory Usage 를 보여주고 다른 하나는 Physical Memory Usage 에 대한 내용을 확인할 수 있습니다. 즉 쓰임새가 틀린 Debugger command 여서 2개를 소개해드리는 것 입니다.

!VM command 는 option 에 따라 보여주는 data 가 틀려집니다. Default Option은 “ 0 “ 이며 System-wide virtual memory information 그리고 각 process의 memory information을 보여줍니다.

 

Windows Debugger Download 경로 :

X64, IA64, X86 Platform 별로 Version이 상이하므로 각 Platform 에 맞는 Version 설치

https://www.microsoft.com/whdc/DevTools/Debugging/default.mspx

Web Symbol 경로 :

https://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx#a

SRV*c:\websymbols*https://msdl.microsoft.com/download/symbols

 

Flag

Function

Bit 0 (0x1)

Process 정보가 생략된 결과 출력

Bit 1 (0x2)

Memory Management 의Thread stack정보를 포함하는 결과 출력

Bit 2 (0x4)

Terminal Server의 Memory Usage를 포함 (Win XP 이상)

Bit 3 (0x8)

Page File Write Log 를 포함 (Win XP 이상)

Bit 4 (0x10)

Working set owner의 thread stack 포함 (Win XP 이상)

Bit 5 (0x20)

Kernel 의 Virtual Address 사용량을 포함 (Win XP 이상)

 

이번 Post 에서는 32 bit Windows XP or Windows 2003 에서 CrashOnCtrlScroll 방법으로 수집된 덤프 또는 Bang.exe 와 같은 도구를 사용하여 인위적으로 수집된 덤프를 기반으로 설명 드립니다.

이와 같이 인위적으로 메모리 덤프를 수집하시려면 sysinternals의 NotMyFault와 같은 도구를 사용하실 수도 있습니다.

참고 :

How to generate a kernel or a complete memory dump file in Windows Server 2008

https://support.microsoft.com/kb/969028

그리고 시작에 앞서 간단히 !VM command 의 결과를 짚어보도록 하겠습니다.

 

!vm

1: kd> !vm

*** Virtual Memory Usage ***
Physical Memory: 523793 ( 2095172 Kb)
Page File: \??\C:\pagefile.sys
Current: 2095104 Kb Free Space: 2031992 Kb
Minimum: 2095104 Kb Maximum: 4190208 Kb
Available Pages: 389780 ( 1559120 Kb)
ResAvail Pages: 436684 ( 1746736 Kb)
Locked IO Pages: 54 ( 216 Kb)
Free System PTEs: 149380 ( 597520 Kb)
Free NP PTEs: 32766 ( 131064 Kb)
Free Special NP: 0 ( 0 Kb)
Modified Pages: 754 ( 3016 Kb)
Modified PF Pages: 753 ( 3012 Kb)
NonPagedPool Usage: 3230 ( 12920 Kb)
NonPagedPool Max: 65536 ( 262144 Kb)
PagedPool 0 Usage: 3862 ( 15448 Kb)
PagedPool 1 Usage: 458 ( 1832 Kb)
PagedPool 2 Usage: 445 ( 1780 Kb)
PagedPool 3 Usage: 471 ( 1884 Kb)
PagedPool 4 Usage: 460 ( 1840 Kb)
PagedPool Usage: 5696 ( 22784 Kb)
PagedPool Maximum: 92160 ( 368640 Kb)
Session Commit: 1603 ( 6412 Kb)
Shared Commit: 6500 ( 26000 Kb)
Special Pool: 0 ( 0 Kb)
Shared Process: 2908 ( 11632 Kb)
PagedPool Commit: 5696 ( 22784 Kb)
Driver Commit: 2235 ( 8940 Kb)
Committed pages: 104454 ( 417816 Kb)
Commit limit: 1008403 ( 4033612 Kb)

  Total Private: 76464 ( 305856 Kb)

         0358 MsMpEng.exe 26290 ( 105160 Kb)
0380 svchost.exe 4818 ( 19272 Kb)
0438 CcmExec.exe 4088 ( 16352 Kb)
0344 wlcrasvc.exe 2291 ( 9164 Kb)
0a08 wuauclt.exe 2171 ( 8684 Kb)
0070 WakeUpAgt.exe 1870 ( 7480 Kb)
01d0 winlogon.exe 1825 ( 7300 Kb)
0208 lsass.exe 1660 ( 6640 Kb)
066c FSysAgent.exe 1605 ( 6420 Kb)
0730 InoRpc.exe 1210 ( 4840 Kb)
06b8 HealthService.e 1210 ( 4840 Kb)
0d54 wmiprvse.exe 951 ( 3804 Kb)
04f4 spoolsv.exe 912 ( 3648 Kb)
02c8 svchost.exe 748 ( 2992 Kb)
0308 svchost.exe 543 ( 2172 Kb)
04a4 ati2evxx.exe 542 ( 2168 Kb)
02b8 ati2evxx.exe 506 ( 2024 Kb)
0fd0 wmiprvse.exe 501 ( 2004 Kb)
01fc services.exe 472 ( 1888 Kb)
01b0 csrss.exe 431 ( 1724 Kb)
042c svchost.exe 412 ( 1648 Kb)
03d8 svchost.exe 390 ( 1560 Kb)
014c wdfmgr.exe 384 ( 1536 Kb)
05d0 svchost.exe 309 ( 1236 Kb)
067c FwcAgent.exe 294 ( 1176 Kb)
0cc8 alg.exe 277 ( 1108 Kb)
0614 mscorsvw.exe 254 ( 1016 Kb)
0180 smss.exe 49 ( 196 Kb)
0004 System 7 ( 28 Kb)
062c wlcrdpsystem.ex 0 ( 0 Kb)

아래에서 보다시피, 다양한 정보와 Memory Usage를 출력하여 줍니다. 단 정확한 Command 를 실행하여야 합니다.

Windows XP

1: kd> !vm 5

*** Virtual Memory Usage ***
Physical Memory: 523793 ( 2095172 Kb)
Page File: \??\C:\pagefile.sys
Current: 2095104 Kb Free Space: 2031992 Kb
Minimum: 2095104 Kb Maximum: 4190208 Kb
Available Pages: 389780 ( 1559120 Kb)
ResAvail Pages: 436684 ( 1746736 Kb)
Locked IO Pages: 54 ( 216 Kb)
Free System PTEs: 149380 ( 597520 Kb)
Free NP PTEs: 32766 ( 131064 Kb)
Free Special NP: 0 ( 0 Kb)
Modified Pages: 754 ( 3016 Kb)
Modified PF Pages: 753 ( 3012 Kb)
NonPagedPool Usage: 3230 ( 12920 Kb)
NonPagedPool Max: 65536 ( 262144 Kb)
PagedPool 0 Usage: 3862 ( 15448 Kb)
PagedPool 1 Usage: 458 ( 1832 Kb)
PagedPool 2 Usage: 445 ( 1780 Kb)
PagedPool 3 Usage: 471 ( 1884 Kb)
PagedPool 4 Usage: 460 ( 1840 Kb)
PagedPool Usage: 5696 ( 22784 Kb)
PagedPool Maximum: 92160 ( 368640 Kb)
Shared Commit: 6500 ( 26000 Kb)
Special Pool: 0 ( 0 Kb)
Shared Process: 2908 ( 11632 Kb)
PagedPool Commit: 5696 ( 22784 Kb)
Driver Commit: 2235 ( 8940 Kb)
Committed pages: 104454 ( 417816 Kb)
Commit limit: 1008403 ( 4033612 Kb)

Terminal Server Memory Usage By Session:

Session Paged Pool Maximum is 4096K
Session View Space Maximum is 49152K

Session ID 0 @ ba620000:
Paged Pool Usage: 0K
Commit Usage: 6412K

!vm5 실행 시, 터미널 서버의 메모리 사용량도 포함하여 화면에 출력하게 됩니다. 하지만 XP에서는 0x5 가 보여주는 결과는 오직 하나의 Active Terminal Session (Session 0)만을 보여주게 됩니다. 즉 Local Console Session의 Terminal Memory Usage 를 확인할 수 있습니다. 그러나 Local Console Session을 포함하여 3개의 Remote Desktop Connection을 제공하는 Windows Server 2003 의 경우 3개의 Terminal Session의 Memory Usage 도 출력하여 줍니다.

Windows Server 2003

3: kd> !vm 5

 

*** Virtual Memory Usage ***

               Physical Memory: 982898 ( 3931592 Kb)

               Page File: \??\C:\pagefile.sys

                 Current: 2095104 Kb Free Space: 1691088 Kb

                 Minimum: 2095104 Kb Maximum: 2936368 Kb

               Available Pages: 492424 ( 1969696 Kb)

               ResAvail Pages: 895348 ( 3581392 Kb)

               Locked IO Pages: 444 ( 1776 Kb)

               Free System PTEs: 184946 ( 739784 Kb)

               Free NP PTEs: 32766 ( 131064 Kb)

               Free Special NP: 0 ( 0 Kb)

               Modified Pages: 443 ( 1772 Kb)

               Modified PF Pages: 358 ( 1432 Kb)

               NonPagedPool Usage: 12977 ( 51908 Kb)

               NonPagedPool Max: 65471 ( 261884 Kb)

               PagedPool 0 Usage: 29752 ( 119008 Kb)

               PagedPool 1 Usage: 3019 ( 12076 Kb)

               PagedPool 2 Usage: 3051 ( 12204 Kb)

               PagedPool 3 Usage: 3055 ( 12220 Kb)

               PagedPool 4 Usage: 3071 ( 12284 Kb)

               PagedPool Usage: 41948 ( 167792 Kb)

               PagedPool Maximum: 90624 ( 362496 Kb)

               Shared Commit: 3536 ( 14144 Kb)

               Special Pool: 0 ( 0 Kb)

               Shared Process: 7948 ( 31792 Kb)

               PagedPool Commit: 42012 ( 168048 Kb)

               Driver Commit: 9212 ( 36848 Kb)

               Committed pages: 506582 ( 2026328 Kb)

               Commit limit: 1465379 ( 5861516 Kb)

 

 

               Terminal Server Memory Usage By Session:

 

               Session Paged Pool Maximum is 4096K

               Session View Space Maximum is 49152K

 

               Session ID 0 @ f7995000:

               Paged Pool Usage: 0K

               Commit Usage: 288K

 

               Session ID 2 @ f79a1000:

               Paged Pool Usage: 0K

               Commit Usage: 340K

 

               Session ID 3 @ b583d000:

               Paged Pool Usage: 0K

                Commit Usage: 276K

 

더 자세한 즉, !VM 명령으로 확인하기 어려운 더 자세한 Memory Usage를 확인하시려면 다음의 !memusage 명령을 사용할 수 있습니다. !memusage 를 사용하여 Physical Memory Usage를 Review 하실 수 있습니다. 아래 flag들을 사용하여 자세한 Memory Usage를 확인할 수 있으며 Windows XP 이상의 OS에서 사용할 수 있습니다. 하지만 만약 수집된 덤프가 Windows2000 에서 수집된 덤프라면 추가적인 Parameter를 사용하실 수는 없습니다.

Flag

Function

0x0

일반적인 요약 정보 및 PFN Database의 자세한 설명

0x1

PFN Database 내부의 no-write page에 대한 요약 정보

0x2

PFN Database 내부의 no-write page에 대한 자세한 정보

0x8

Memory 사용에 대한 일반적인 정보만 출력

Falg 없는 !memusage 의 예:

1: kd> !memusage
loading PFN database
loading (100% complete)
Compiling memory usage data (99% Complete).
Zeroed: 281150 (1124600 kb)
Free: 0 ( 0 kb)
Standby: 108630 (434520 kb)
Modified: 754 ( 3016 kb)
ModifiedNoWrite: 0 ( 0 kb)
Active/Valid: 133277 (533108 kb)
Transition: 0 ( 0 kb)
Bad: 0 ( 0 kb)
Unknown: 0 ( 0 kb)
TOTAL: 523811 (2095244 kb)
Building kernel map
Finished building kernel map
Scanning PFN database - (100% complete)

Usage Summary (in Kb):
Control Valid Standby Dirty Shared Locked PageTables name
89e4a8b8 364 28868 0 0 0 0 mapped_file( $LogFile )
89c91168 0 1880 0 0 0 0 mapped_file( mscorlib.ni.dll )
899a31d8 0 636 0 0 0 0 mapped_file( mshtml.dll )
893933d0 0 52 0 0 0 0 mapped_file( ccmident.dll )
892bd2f0 0 68 0 0 0 0 mapped_file( wbemess.lo_ )
89c85220 0 2872 0 0 0 0 mapped_file( mscorwks.dll )

0x8 flag 를 사용한 예:

1: kd> !memusage 8
loading PFN database
loading (100% complete)
Compiling memory usage data (99% Complete).
Zeroed: 281150 (1124600 kb)
Free: 0 ( 0 kb)
Standby: 108630 (434520 kb)
Modified: 754 ( 3016 kb)
ModifiedNoWrite: 0 ( 0 kb)
Active/Valid: 133277 (533108 kb)
Transition: 0 ( 0 kb)
Bad: 0 ( 0 kb)
Unknown: 0 ( 0 kb)
TOTAL: 523811 (2095244 kb)

 

간략히 WinDBG 에서 사용하실 수 있는 !vm 그리고 !memusage 명령을 알아보았습니다. 더 자세한 내용은 WinDBG Help에서 확인하실 수 있습니다. 다음 번에 기회가 된다면 더 자세한 내용을 다루도록 하겠습니다.

With that, we’ve reached the end of this post. The resources below as well as the debugging help file can provide you with more information. Until next time …

관련 추가 기술자료 :

- CC Hameed