Skip to content

Conversation

@cshung
Copy link
Contributor

@cshung cshung commented Aug 12, 2021

This PR fixes #936.

Here are a few key changes in the heap data structure:

To get our terminologies straight, while we still have the heap_segment objects, we call them region objects under the context of USE_REGIONS.

Under USE_REGIONS, the heap_segment object itself is stored somewhere other than the address it manages (it is part of the seg_mapping_table to be precise), therefore we cannot use the address of the heap_segment object itself to determine the base address of the region.

With USE_REGIONS, gen0 and gen1 are no longer restricted on ephemeral_heap_segment, we could have a linked list of regions for gen0 and gen1. This explains the extra calls to AddSegments on ProcessHeap.

The field allocation_start is no longer defined in generation. For backward compatibility reasons, the field is still defined on the DacpGenerationData structure, but it will always be 0 in .NET 6 when USE_REGIONS is turned on. There isn't a single start and end pointer for gen0 and gen1 anymore. Instead, each region belongs to a generation, therefore the Gen0Start and Gen0Length are simply set to the Start and End-Start of the region if it is indeed a gen0 region, otherwise it is set to End and 0 respectively.

Beyond the obvious changes, here are some not so obvious changes that might break things:

  1. The regions are no longer sorted, so I have to remove the check in the unit tests.
  2. There could be empty regions, so I have to avoid walking them in heap enumeration.
  3. By default, each region is just 4MB (LOH regions has a default size of 32MB), so one might have a lot more regions.

Status of the PR:

Right now this fix is sufficient to get the DumpGen command in SOS to work with dotnet/diagnostics#2501. With some hacks, all the unit tests passed. I might have missed other scenarios that are not covered by the tests.

Future work:

As the change on SOS side and unit test changes indicate, even when the fix is in, it is still possible for callers to be broken by USE_REGIONS. While there is nothing we can do in the code to prevent that, we might be able to communicate upfront to get it fixed earlier.

Eventually, we need to publish a new version with region support enabled so that SOS (and other tools) can consume the new functionalities.

@cshung cshung changed the title [WIP] Support regions Support regions Aug 18, 2021
@leculver leculver merged commit 6b23a36 into microsoft:master Aug 23, 2021
@cshung cshung deleted the public/regions branch July 30, 2022 18:13
@cshung cshung restored the public/regions branch July 30, 2022 18:42
@cshung cshung deleted the public/regions branch July 30, 2022 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support regions

2 participants