Skip to content

Segment heap opt-in/opt-out flags needed #39

Closed
@randomascii

Description

@randomascii
Item Value
OS, Version / Build 10.0.19041.0 Microsoft Windows NT 10.0.19041.0
Processor Architecture AMD64
Processor Type & Model Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, 3192 Mhz, 4 Core(s), 8 Logical Processor(s)
Memory 32GB
Storage Type, free / capacity (e.g. C: SSD 128GB / 512GB) SSD 2TB
Relevant apps installed Windows Performance Toolkit

Description

Flags to request or refuse the segment heap are needed in order to give applications control over when to use the NT versus segment heaps.

Steps to reproduce

crbug.com/1014701 describes how the NT heap leads to more than 100% memory overhead on some machines in Chrome's browser and network processes when running for a few weeks on many-core machines. Testing with opting-in to the segment heap using the IFEO registry keys showed that on those machines the segment heap dramatically reduced this overhead, saving hundreds of MB. Unfortunately, as shown in crbug.com/1102281 the segment heap increases the CPU cost in renderer processes, adding up to 13% CPU overhead in some scenarios. This means that the very-valuable segment heap is too expensive for us to enable.

Expected behavior

I would like to be able to enable the segment heap for some processes/heaps only.

Actual behavior

I currently have to enable the segment heap for all chrome.exe processes (using the application manifest), meaning that I have to take the good with the bad.
https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests

crrev.com/c/2337959 proves that it would be quite easy for Microsoft to add a function to Windows that would set or clear the "segment-heap-enabled" bit in RtlpHpHeapFeatures in ntdll.dll. Code inspection makes it clear that it would also be easy to add flags to HeapCreate and RtlCreateHeap to force-enable or force-disable the segment heap. These methods would work nicely in conjunction with the manifest, which by itself is too inflexible to be a complete solution.

That is, we really need these two HeapCreate flags:

HEAP_ENABLE_SEGMENT_HEAP - create a segment heap instead of an NT heap
HEAP_DISABLE_SEGMENT_HEAP - create an NT heap instead of a segment heap, even if the segment heap was requested in the application manifest

Alternately, if we had some way to get the address of RtlpHpHeapFeatures then we could clear that flag in our renderer processes after creating them but before starting. This would ensure that even the process heap would be of the desired type.

These flags would be useful for all Chromium-based browsers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions