Make dump reader caches safe for concurrent reads#1471
Open
leculver wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates ClrMD’s file-backed dump reader caching and ELF/core-dump lazy state initialization to be safe under concurrent readers, primarily by switching from per-page locks to atomic “first publisher wins” patterns and ensuring published pages remain immutable/usable by in-flight readers.
Changes:
- Reworked Windows segment cache entry page population to use
Volatile.Read+Interlocked.CompareExchangepublication, with a hook to discard unpublished pages (for returning unused pooled buffers). - Updated the ArrayPool-backed cache entry eviction behavior to avoid returning published/evicted buffers to
ArrayPoolwhile concurrent readers may still hold references. - Converted several Linux ELF/core-dump lazily initialized caches to lock-free or locked-first-publisher patterns (
Volatile/Interlockedor explicit lock + publication flag), and marked the Linux coredump reader as thread-safe.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Diagnostics.Runtime/Windows/CacheEntryBase.cs | Removes per-page RW locks and publishes cache pages via CAS; adds DiscardUnusedPage for safe cleanup of unpublished pages. |
| src/Microsoft.Diagnostics.Runtime/Windows/ArrayPoolBasedCacheEntry.cs | Adapts page-in to possible concurrent execution; returns only unpublished loser buffers to ArrayPool, and makes eviction CAS-based without returning published buffers. |
| src/Microsoft.Diagnostics.Runtime/Linux/ElfFile.cs | Makes DynamicSection and virtual-address reader initialization safe for concurrent callers using Volatile/CAS. |
| src/Microsoft.Diagnostics.Runtime/Linux/ElfCoreFile.cs | Makes loaded-images publication lock-free, virtual address space init lock-free, and auxv table loading single-writer with a publication flag. |
| src/Microsoft.Diagnostics.Runtime/DataReaders/Core/CoreDumpReader.cs | Makes coredump reader caches publish safely under concurrency; changes IsThreadSafe to true and replaces nullable bool cache with atomic tri-state int. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 1
Comment on lines
+64
to
+66
| bool result = SpecialDiagInfo.TryReadSpecialDiagInfo(this, out _); | ||
| Interlocked.CompareExchange(ref _isCreatedByDotNetRuntimeState, result ? 2 : 1, 0); | ||
| return result; |
Fix thread-safety in the file-backed dump reader cache layer without changing DAC behavior. Publish CoreDumpReader and ELF-derived lazy state with atomic/locked first-publisher patterns, and make the Windows cached reader publish immutable pages safely for concurrent readers. Preserve ArrayPool safety by returning only unpublished CAS-loser buffers and leaving published evicted buffers to normal GC so in-flight readers cannot observe reused arrays.
544d124 to
35794a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the file-backed dump reader cache layer safe for concurrent readers without changing DAC behavior.
This PR fixes managed cache publication in the dump-reader/cache-entry layer:
Part of #420.
Validation
dotnet build src/Microsoft.Diagnostics.Runtime/Microsoft.Diagnostics.Runtime.csproj --framework net10.0-- passed with 0 warnings and 0 errors.lockfree-mmf-threadsafe; all non-stress paths matched the original combined branch.