Skip to content

Fix BGC allocation context accounting - #134855

Merged
janvorli merged 2 commits into
dotnet:mainfrom
kkokosa:fix-issue-134724-getallocatedbytesforcur
Nov 13, 2026
Merged

janvorli merged 2 commits into
dotnet:mainfrom
kkokosa:fix-issue-134724-getallocatedbytesforcur

Conversation

@kkokosa

@kkokosa kkokosa commented Sep 29, 2026

Copy link
Copy Markdown
Member

Fixes #134724.

Background GC cleared abandoned allocation contexts without retiring their unused bytes, causing GC.GetAllocatedBytesForCurrentThread() to report phantom allocations.

The fix reuses the normal allocation-context accounting path and adds a server-GC join so one designated worker retires all contexts exactly once during the existing stop-the-world phase.

Note

This pull request description was generated by GitHub Copilot.

@azure-pipelines

azure-pipelines Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 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: @anicka-net, @dotnet/gc
See info in area-owners.md if you want to be subscribed.

@janvorli

janvorli commented Oct 1, 2026

Copy link
Copy Markdown
Member

@kkokosa the test could be improved by checking if background GC has occurred to make sure it always exercises the problematic path.

DaveBeusing added a commit to DaveBeusing/Forgeline that referenced this pull request Oct 18, 2026
…ication

Repair rendering foundation qualification and physical supply lifecycle

Render preparation repeatedly acquired adapter diagnostics and computed unused work inside timed phases. Reuse render-owner observations and remove that work while preserving exact pixels, frame/resource lifetime and ten-second fence limits. Correct WARP admission, smoke progress, test-module isolation, HDR clear, audio publication and writer lifetime without increasing deadlines.

The required terminal gate exposed inherited logistics and tactical stalls. Repair dock-exit turning, dispatchable loading completion, source selection, reconnaissance ownership and supported continuation, mature freight demand and formation-bound providers. Let misordered arrivals physically evacuate a reserved dock approach. Exclude currently identified non-combat infrastructure before tactical AI replaces a valid advance with an attack the combat system cannot execute. Existing visibility, collision, weapon and strategic deadline rules remain active; no resources or result are forced.

Allocation CI failures also expose the .NET background-GC counter-accounting issue (dotnet/runtime#134724, dotnet/runtime#134855). A standalone Windows x64 .NET 10.0.12 diagnostic reports nonzero bytes in five of 256 empty intervals with concurrent GC, versus zero with it disabled; real allocation controls remain exactly 64 bytes in both. Disable concurrent GC only in Presentation.Tests. Restore the original measured loops, warmups and zero-byte assertions, removing insufficient dedicated-thread workarounds. Add a configuration guard and allocating positive control. Production GC settings remain unchanged. The two exact-zero HUD allocation benchmark steps also set process-local DOTNET_gcConcurrent=0; these separate executables do not inherit test-host runtimeconfig. The benchmark rejects uncontrolled exact-allocation mode before measurement. Native/scalability/frame-timing modes retain their original policy.
@anasik

anasik commented Nov 6, 2026 •

Copy link
Copy Markdown

Independent repro, found through flaky zero-allocation tests (Linux arm64, .NET 8.0.33 and 10.0.14, workstation GC):

  • Allocating a 24-byte marker before and after each empty interval: every nonzero GetAllocatedBytesForCurrentThread() delta coincided with the second marker landing in a new allocation context.
  • In those cases, delta + bytes already used in the old context was always 8,200 (6,376 + 1,824 and 1,696 + 6,504).
  • With DOTNET_gcConcurrent=0 there were 0 deltas in 5.2M intervals, vs 24 in 17.9M with it on.
  • release/8.0 and release/10.0 have the same mark_absorb_new_alloc() / repair_allocation_contexts(FALSE) path.

Is anything left before this comes out of draft?

Generated with AI 🤖

@janvorli
janvorli marked this pull request as ready for review November 13, 2026 19:03
@janvorli
janvorli merged commit c3bb0a4 into dotnet:main Nov 13, 2026
108 checks passed
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.

GC.GetAllocatedBytesForCurrentThread reports positive deltas for no-inline SpinWait-only intervals on macOS ARM64

3 participants