Skip to content

[cDAC] Cache small target-memory reads in bounded pages - #136661

Open
max-charlamb wants to merge 3 commits into
dotnet:mainfrom
max-charlamb:cdac-cache-target-pages
Open

max-charlamb wants to merge 3 commits into
dotnet:mainfrom
max-charlamb:cdac-cache-target-pages

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Cache small target-memory reads in ContractDescriptorTarget using 32 preallocated 4 KiB pages by default. A pre-sized dictionary maps aligned addresses to cache slots, and misses replace slots in FIFO order.

The cache targets workloads such as dump enumeration and stack walking that issue many small reads from nearby addresses. Cache hits avoid repeated physical ReadVirtual callbacks while preserving logical-read notifications, so dump-region reporting is unchanged. Failed full-page fills fall back to the exact requested read, and unavailable pages are retried after eviction or invalidation. The cache is cleared on every flush scope and before writes.

Configuration

Managed consumers can configure the cache with standard runtime-host configuration options:

<ItemGroup>
  <RuntimeHostConfigurationOption
      Include="Microsoft.Diagnostics.DataContractReader.PageCache.Enabled"
      Value="true"
      Trim="true" />
  <RuntimeHostConfigurationOption
      Include="Microsoft.Diagnostics.DataContractReader.PageCache.PageSize"
      Value="4096" />
  <RuntimeHostConfigurationOption
      Include="Microsoft.Diagnostics.DataContractReader.PageCache.PageCount"
      Value="32" />
</ItemGroup>

These are the defaults when omitted. Disabling the cache avoids allocating its storage. Page size must be a positive power of two, page count must be positive, and their product must fit in a managed byte array.

Performance

This PR: before and after versus native DAC

Heap-mode ICLRDataEnumMemoryRegions using six fixed snapshots and matching native DAC. These are standalone measurements of main cDAC before this PR and the same source with only this page cache added. Values are means from 90 retained observations per provider/workload.

Heap workload Native DAC cDAC before cDAC with this PR cDAC reduction After/native
SmallSimple 2.103 ms 5.447 ms 4.345 ms 20.2% 2.07x
LargeSimple 1.811 ms 5.443 ms 4.408 ms 19.0% 2.43x
SmallComplex 3.631 ms 9.116 ms 7.284 ms 20.1% 2.01x
LargeComplex 9.658 ms 30.413 ms 21.442 ms 29.5% 2.22x
CodeHeavy 3.571 ms 9.837 ms 7.434 ms 24.4% 2.08x
DeepStacks 11.136 ms 40.560 ms 26.359 ms 35.0% 2.37x

Physical target-read callbacks fell by 97.5%-99.6%:

Heap workload Native DAC cDAC before cDAC with this PR
SmallSimple 1,803 9,108 226
LargeSimple 1,819 9,201 232
SmallComplex 3,637 19,330 330
LargeComplex 14,442 84,536 633
CodeHeavy 5,036 23,452 405
DeepStacks 20,198 128,865 477

All 18 Mini/Heap/Triage enumeration outputs matched the reader without this PR.

Mini dumps remain a limitation because sparse pages frequently reject full-page fills and fall back to exact reads.

Note

This PR description and implementation were developed with GitHub Copilot.

Use 32 preallocated 4 KiB pages with dictionary indexing and FIFO eviction.
Retain unavailable-page entries for exact-read fallback, clear on flush
and writes, and preserve logical-read notifications outside the cache.

Cover sparse memory, replacement failures, invalidation, endianness and
logical dump-read reporting in the existing cDAC tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: de3eab4e-b090-430a-8e30-6b204fb1519a
@azure-pipelines

azure-pipelines Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Add direct AppContext/runtime-host options for enabling caching, page size and page count. Keep the 4096-byte/32-page defaults, validate dimensions, and cover configuration in isolated tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: de3eab4e-b090-430a-8e30-6b204fb1519a
Reconstruct loaded-image pointer values when ClrMdDumpHost fills missing dump memory from a PE file, matching SOS image mapping behavior.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: de3eab4e-b090-430a-8e30-6b204fb1519a
@max-charlamb
max-charlamb requested a review from rcj1 November 18, 2026 01:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant