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?

7
  • How are you measuring how much memory it is taking? And what do you mean by "memory"? Do you mean physical memory (RAM)? Jan 31, 2016 at 11:44
  • So, not physical memory then. Then the short answer is that nobody cares what this value is. Only physical memory is scarce and usually people do not bother to minimize the consumption of resources that are not scarce. Jan 31, 2016 at 23:25
  • @DavidSchwartz I measured total ram usage in Resource Monitor and the spikes and drops seem to be similar. Also when there's 10 such conhosts, my chrome halts for a while when accessed after some time. I've seen an improvement when avoiding starting the conhosts in the way described in my question (using start cmd sh.exe instead of start sh.exe). My question is why the difference at all? Why does conhost hog so much more memory (even just virtually) when doing start sh.exe compared to doing start cmd /c sh.exe Feb 1, 2016 at 8:24
  • The answer is what I said -- virtual memory is not scarce so people don't bother to minimize its consumption. It's quite common to allocate pretty large chunks just in case it's needed later. This is particularly true when launching a process because there are things you can do before you launch that you can't easily do after. Feb 1, 2016 at 8:26

1 Answer 1

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.

2
  • Ahh! I had Screen Buffer Size set to 9999 Don't know why it was only applying to start sh.exe but lowering it to sane values created conhost with not so much memory usage. Damn! lol. Thanks for the analysis! Feb 2, 2016 at 20:48
  • When I first looked at the trace I also thought about this, but forgot to add it. But nice to hear that it is fixed now :) Feb 3, 2016 at 5:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .