Microsoft MVP성태의 닷넷 이야기
Windows: 116. 프로세스 풀 덤프 시간을 줄여 주는 Process Reflection [링크 복사], [링크+제목 복사]
조회: 15179
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

프로세스 풀 덤프 시간을 줄여 주는 Process Reflection

Windows Internals 책을 통해 Windows 7 이후 지원된다는 "Process Reflection"에 대해 처음 알게 되었습니다. ^^ (470 페이지에 자세하게 설명되어 있습니다.)

Windows Internals 제6판 Vol. 1: 마이크로소프트 윈도우 커널 공식 가이드 6판 
; http://www.yes24.com/24/goods/7877539

간단하게 설명해 보면!

프로세스 Full Dump 등을 남기려면 해당 EXE 프로세스의 동작을 중지시켜 사용 중인 메모리를 모두 디스크에 써야 하는데 이 소비 시간은 프로세스가 사용 중인 메모리의 크기에 영향을 받게 됩니다. 64비트 프로세스의 경우 대용량을 쓸 수 있다는 점을 감안하면 향후 미래를 생각해 봤을 때 분명히 문제가 아닐 수 없습니다.

마이크로소프트는 이에 대한 해법으로 "Process Reflection"을 구현했는데, 대상 프로세스의 현재 상태를 반영하는 임시 자식 프로세스를 생성하는 것입니다. 따라서, 덤프를 떠야 할 프로세스는 "미니 덤프를 생성할 시간"과 해당 프로세스에 대한 정지된 "클론"을 만드는 데 드는 시간 만큼만 중지하게 되어 실 서비스 운영 중에도 큰 부담없이 사용할 수 있다는 장점이 있습니다.

현재 이 정책을 반영한 프로그램이 sysinternals 도구에 포함된 procdump.exe입니다. procdump.exe로 full dump를 받는 방법은 다음과 같이 실행하게 되는데요.

C:\Windows\system32>procdump -ma reportingservicesservice.exe D:\temp\procdump.dmp

ProcDump v4.0 - Writes process dump files
Copyright (C) 2009-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

Writing dump file D:\temp\procdump.dmp ...
Dump written.

대상 exe가 사용하는 모든 메모리를 디스크에 복사하기 때문에 이때 Process Explorer 등을 통해 살펴보면 reportingservicesservice.exe가 SUSPEND 상태로 머물러 있음을 확인할 수 있습니다.

하지만 윈도우 7부터 지원되는 '-r' 옵션을 이용해,

   -r      Dump using a clone. Concurrent limit is optional (default 1, max 5).
           CAUTION: a high concurrency value may impact system performance.
           - Windows 7   : Uses Reflection. OS doesn't support -e.
           - Windows 8.0 : Uses Reflection. OS doesn't support -e.
           - Windows 8.1+: Uses PSS. All trigger types are supported.

덤프를 남겨보면,

C:\Windows\system32>procdump -r -ma reportingservicesservice.exe D:\temp\procdump.dmp

ProcDump v4.0 - Writes process dump files
Copyright (C) 2009-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

Writing dump file D:\temp\procdump-1.dmp ...
Dump written.

Writing dump file D:\temp\procdump-reflected.dmp ...
Dump written.

Finished writing reflected dump.
Open D:\temp\procdump.ini in the debugger to view the combined reflected dump.

보는 바와 같이 단계별로 2개의 .dmp 파일을 생성하고 그 파일들을 엮어주는 ini 파일이 다음의 내용으로 함께 생성됩니다.

[UserModeDump]
default=procdump-1.dmp
memory=procdump-reflected.dmp
module=procdump-1.dmp

여기서 procdump-1.dmp 파일은 minidump 유형의 덤프 파일로 이것을 남길 때만 대상 프로세스(본문에서는 reportingservicesservice.exe)가 SUSPEND 상태로 머물고 그 이후 메모리 덤프가 남겨지는 procdump-reflected.dmp 파일을 생성하는 동안에는 다시 정상적으로 서비스를 하게 됩니다.

실제로 windbg에서 procdump-1.dmp파일만 로드해서 .NET sos 확장 DLL을 로드하려고 하면 다음과 같이 경고 문구가 나옵니다.

0:000> .load C:\Windows\Microsoft.NET\Framework64\v2.0.50727\sos.dll
------------------------------------------------------------
sos.dll needs a full memory dump for complete functionality.
You can create one with .dump /ma <filename>
------------------------------------------------------------

당연하지만, 미니 덤프이기때문에 그에 포함되지 않은 영역의 메모리에 대한 내용은 보여지지 않는 경우가 많습니다.

0:041> !printexception
Exception object: 000000008067dec0
Exception type: System.ArgumentException
Message: The source '...' is not registered in log '...'. (It is registered in log '...'.) " The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property.
InnerException: <none>
StackTrace (generated):
    SP               IP               Function
    00000000152BCEC0 00007FFADD466353 System!System.Diagnostics.EventLog.VerifyAndCreateSource(System.String, System.String)+0x313
    00000000152BCF30 00007FFADD465BC1 System!System.Diagnostics.EventLog.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32, Int16, Byte[])+0x191
    00000000152BCFD0 00007FFADDA75D3C System!System.Diagnostics.EventLog.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32)+0x1c
    00000000152BD010 00007FFADDA75C42 TestLib!TestLib.Logger.LogEvent(System.Diagnostics.EventLogEntryType, TestLib.WindowEventLogId, System.String)+0x322

StackTraceString: <none>
HResult: 80070057

0:041> dd 00000000152BCEC0 
00000000`152bcec0  ???????? ???????? ???????? ????????
00000000`152bced0  ???????? ???????? ???????? ????????
00000000`152bcee0  ???????? ???????? ???????? ????????
00000000`152bcef0  ???????? ???????? ???????? ????????
00000000`152bcf00  ???????? ???????? ???????? ????????
00000000`152bcf10  ???????? ???????? ???????? ????????
00000000`152bcf20  ???????? ???????? ???????? ????????
00000000`152bcf30  ???????? ???????? ???????? ????????

반면, INI 파일을 windbg에서 열면 ini 내부에 지정된 덤프를 자동으로 모두 열고,

Loading Dump File [D:\temp\procdump.ini]

Loading User-mode Dump Configuration File [D:\temp\procdump.ini,D:,\temp\]
    default dump: [procdump-1.dmp]
    memory dump: [procdump-reflected.dmp]
    module list dump: [procdump-1.dmp]

Loading Dump File [D:\temp\procdump-1.dmp]
Comment: '
*** procdump  -r -ma reportingservicesservice.exe D:\temp\procdump.dmp
*** Timed dump'
User Mini Dump File: Only registers, stack and portions of memory are available


Loading Dump File [D:\temp\procdump-reflected.dmp]
User Mini Dump File with Full Memory: Only application data is available

Comment: '
*** procdump  -r -ma reportingservicesservice.exe D:\temp\procdump.dmp
*** Timed dump'

.NET SOS 확장 dll 로드 및 여타 메모리 조사도 정상적으로 잘 동작합니다.

0:000> .load C:\Windows\Microsoft.NET\Framework64\v2.0.50727\sos.dll

0:041> !printexception
Exception object: 000000008067dec0
Exception type: System.ArgumentException
Message: The source '...' is not registered in log '...'. (It is registered in log '...'.) " The Source and Log properties must be matched, or you may set Log to the empty string, and it will automatically be matched to the Source property.
InnerException: <none>
StackTrace (generated):
    SP               IP               Function
    00000000152BCEC0 00007FFADD466353 System!System.Diagnostics.EventLog.VerifyAndCreateSource(System.String, System.String)+0x313
    00000000152BCF30 00007FFADD465BC1 System!System.Diagnostics.EventLog.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32, Int16, Byte[])+0x191
    00000000152BCFD0 00007FFADDA75D3C System!System.Diagnostics.EventLog.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32)+0x1c
    00000000152BD010 00007FFADDA75C42 TestLib!TestLib.Logger.LogEvent(System.Diagnostics.EventLogEntryType, TestLib.WindowEventLogId, System.String)+0x322

StackTraceString: <none>
HResult: 80070057

0:041> dd 00000000152BCEC0 
00000000`152bcec0  1a5b61a0 00000000 007f0628 00000000
00000000`152bced0  fffffffe ffffffff 757fe648 00001871
00000000`152bcee0  00989680 00000000 000000c6 00000000
00000000`152bcef0  757fe648 00001871 152bcf48 00000000
00000000`152bcf00  80c90c30 00000000 dcc46a99 00007ffa
00000000`152bcf10  80c90b78 00000000 3c186d89 00007ffb
00000000`152bcf20  00000001 00000000 00000001 00000000"
00000000`152bcf30  00000000 00000000 3c18a092 00007ffb

이로써, 운영 서버에도 풀 덤프를 남겨달라고 부탁해도 크게 부담이 없게 되었습니다. (그래도, 부담스러워하는 고객이 있겠지만. ^^)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2017-08-04 04시23분
@taehwalee 님이 알려주신 정보... ^^

Windows 8, 2012 R2 부터는 OS에서 기능이 더 좋아져서 -r 옵션을 사용하면 덤프 파일이 1개만 생성된다고 하네요 (기존은 3개죠, 블로그에 쓰신것 처럼요)
; https://twitter.com/taehwalee/status/893310350925455360
정성태
2018-10-23 04시11분
zodiacon/AllTools - All reasonably stable tools
; https://github.com/zodiacon/AllTools

Windows Internals Book 7th edition Tools
; https://github.com/zodiacon/WindowsInternals
정성태

... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12301정성태8/30/202010345오류 유형: 641. error MSB4044: The "Fody.WeavingTask" task was not given a value for the required parameter "IntermediateDir".
12300정성태8/29/20209794.NET Framework: 935. C# - ETW 관련 Win32 API 사용 예제 코드 (4) CLR ETW Consumer파일 다운로드1
12299정성태8/27/202010717.NET Framework: 934. C# - ETW 관련 Win32 API 사용 예제 코드 (3) ETW Consumer 구현파일 다운로드1
12298정성태8/27/202010428오류 유형: 640. livekd - Could not resolve symbols for ntoskrnl.exe: MmPfnDatabase
12297정성태8/25/20209624개발 환경 구성: 503. SHA256 테스트 인증서 생성 방법
12296정성태8/24/202010084.NET Framework: 933. C# - ETW 관련 Win32 API 사용 예제 코드 (2) NT Kernel Logger파일 다운로드1
12295정성태8/24/20209472오류 유형: 639. Bitvise - Address is already in use; bind() in ListeningSocket::StartListening() failed: Windows error 10013: An attempt was made to access a socket ,,,
12293정성태8/24/202010794Windows: 171. "Administered port exclusions" 설명
12292정성태8/20/202012063.NET Framework: 932. C# - ETW 관련 Win32 API 사용 예제 코드 (1)파일 다운로드2
12291정성태8/15/202010988오류 유형: 638. error 1297: Device driver does not install on any devices, use primitive driver if this is intended.
12290정성태8/11/202011709.NET Framework: 931. C# - IP 주소에 따른 국가별 위치 확인 [8]파일 다운로드1
12289정성태8/6/20209196개발 환경 구성: 502. Portainer에 윈도우 컨테이너를 등록하는 방법
12288정성태8/5/20209166오류 유형: 637. WCF - The protocol 'net.tcp' does not have an implementation of HostedTransportConfiguration type registered.
12287정성태8/5/20209661오류 유형: 636. C# - libdl.so를 DllImport로 연결 시 docker container 내에서 System.DllNotFoundException 예외 발생
12286정성태8/5/202010526개발 환경 구성: 501. .NET Core 용 container 이미지 만들 때 unzip이 필요한 경우
12285정성태8/4/202010891오류 유형: 635. 윈도우 10 업데이트 - 0xc1900209 [2]
12284정성태8/4/202010257디버깅 기술: 169. Hyper-V의 VM에 대한 메모리 덤프를 뜨는 방법
12283정성태8/3/202010746디버깅 기술: 168. windbg - 필터 드라이버 확인하는 확장 명령어(!fltkd) [2]
12282정성태8/2/20209514디버깅 기술: 167. windbg 디버깅 사례: AppDomain 간의 static 변수 사용으로 인한 crash (2)
12281정성태8/2/202012011개발 환경 구성: 500. (PDB 연결이 없는) DLL의 소스 코드 디버깅을 dotPeek 도구로 해결하는 방법
12280정성태8/2/202011166오류 유형: 634. 오라클 (평생) 무료 클라우드 VM 생성 후 SSH 접속 시 키 오류 발생 [2]
12279정성태7/29/202012004개발 환경 구성: 499. 닷넷에서 접근해보는 InterSystems의 Cache 데이터베이스파일 다운로드1
12278정성태7/23/20209371VS.NET IDE: 149. ("Binary was not built with debug information" 상태로) 소스 코드 디버깅이 안되는 경우
12277정성태7/23/202010799개발 환경 구성: 498. DEVPATH 환경 변수의 사용 예 - .NET Reflector의 (PDB 연결이 없는) DLL의 소스 코드 디버깅
12276정성태7/23/202010007.NET Framework: 930. 개발자를 위한 닷넷 어셈블리 바인딩 - DEVPATH 환경 변수
12275정성태7/22/202012575개발 환경 구성: 497. 닷넷에서 접근해보는 InterSystems의 IRIS Data Platform 데이터베이스파일 다운로드1
... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...