2

Git bash (sh.exe) otherwise takes little memory, but when started with CMD's start sh.exe command, it creates a conhost.exe process that takes 3-700 MB memory.

Interestingly start cmd /k sh.exe does the same thing but it creates conhost process that only takes 8 MB.

Why does starting sh.exe with "start" command create a conhost process that takes so much more memory?

1 Answers1

1

ok, I looked at both traces with WPA.exe. In the trace which shows the high memory usage, the memory usage comes from creating the screen buffer DoCreateScreenBuffer:

Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
1, conhost.exe (10848), [Root], , 46, 800784384, 800833536
2, ,    |- ntdll.dll!RtlUserThreadStart, , 31, 800669696, 800673792
3, ,    |    kernel32.dll!BaseThreadInitThunk, , 31, 800669696, 800673792
4, ,    |    |- ConhostV2.dll!ConsoleIoThread, , 13, 800509952, 800509952
5, ,    |    |    ConhostV2.dll!ConsoleHandleConnectionRequest, , 13, 800509952, 800509952
6, ,    |    |    ConhostV2.dll!ConsoleAllocateConsole, , 13, 800509952, 800509952
7, ,    |    |    |- ConhostV2.dll!SetUpConsole, , 10, 800460800, 800460800
8, ,    |    |    |    |- ConhostV2.dll!AllocateConsole, , 7, 800432128, 800432128
9, ,    |    |    |    |    ConhostV2.dll!DoCreateScreenBuffer, , 7, 800432128, 800432128
10, ,   |    |    |    |    |- ConhostV2.dll!SCREEN_INFORMATION::CreateInstance, , 6, 800415744, 800415744
11, ,   |    |    |    |    |    ConhostV2.dll!TEXT_BUFFER_INFO::CreateInstance, , 6, 800415744, 800415744
12, ,   |    |    |    |    |    |- ConhostV2.dll!DBCS_SCREEN_BUFFER::CreateInstance, , 4, 599891968, 599891968
13, ,   |    |    |    |    |    |    ntdll.dll!RtlpAllocateHeapInternal, , 4, 599891968, 599891968
14, ,   |    |    |    |    |    |    ntdll.dll!RtlpAllocateHeap, , 4, 599891968, 599891968
15, ,   |    |    |    |    |    |    ntdll.dll!NtAllocateVirtualMemory, , 4, 599891968, 599891968
16, ,   |    |    |    |    |    |    ntoskrnl.exe!KiSystemServiceCopyEnd, , 4, 599891968, 599891968
17, ,   |    |    |    |    |    |    ntoskrnl.exe!NtAllocateVirtualMemory, , 4, 599891968, 599891968
18, ,   |    |    |    |    |    |    ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 4, 599891968, 599891968

The start cmd /k sh.exe one, doesn't do this memory allocations. Here only some chars are printed, which uses only 69kB.

Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
7, conhost.exe (10072), [Root], , 2, 81920, 81920
8, ,   ntdll.dll!RtlUserThreadStart, , 2, 81920, 81920
9, ,   kernel32.dll!BaseThreadInitThunk, , 2, 81920, 81920
10, ,   |- ConhostV2.dll!ConsoleIoThread, , 1, 69632, 69632
11, ,   |    ConhostV2.dll!SrvWriteConsole, , 1, 69632, 69632
12, ,   |    ConhostV2.dll!DoSrvWriteConsole, , 1, 69632, 69632
13, ,   |    ConhostV2.dll!DoWriteConsole, , 1, 69632, 69632
14, ,   |    ConhostV2.dll!WriteChars, , 1, 69632, 69632
15, ,   |    ConhostV2.dll!WriteCharsLegacy, , 1, 69632, 69632
16, ,   |    ConhostV2.dll!WriteRegionToScreen, , 1, 69632, 69632
17, ,   |    ConhostV2.dll!ConsolePolyTextOut, , 1, 69632, 69632
18, ,   |    ntdll.dll!RtlpAllocateHeapInternal, , 1, 69632, 69632
19, ,   |    ntdll.dll!RtlpAllocateHeap, , 1, 69632, 69632
20, ,   |    ntdll.dll!RtlpCommitBlock, , 1, 69632, 69632
21, ,   |    ntdll.dll!NtAllocateVirtualMemory, , 1, 69632, 69632
22, ,   |    ntoskrnl.exe!KiSystemServiceCopyEnd, , 1, 69632, 69632
23, ,   |    ntoskrnl.exe!NtAllocateVirtualMemory, , 1, 69632, 69632
24, ,   |    ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 1, 69632, 69632
25, ,   |  , 0x2a657431000, 1, 69632, 69632

But I have no clue, why this happens. Run it always with start cmd /k.