Skip to content

Measured allocations randomly zero #118826

Closed

Description

@timcassell

Description

dotnet/BenchmarkDotNet#2822

Reproduction Steps

Run the provided repro in dotnet/BenchmarkDotNet#2822 (comment)

Expected behavior

Allocated bytes are reported correctly.

Actual behavior

Allocated bytes sometimes report zero.

Regression?

Yes, it repros in .Net 9 and 10, does not repro in .Net 8.

Known Workarounds

No response

Configuration

BenchmarkDotNet v0.15.2, Windows 10 (10.0.19045.6216/22H2/2022Update)
AMD Ryzen 7 9800X3D 4.70GHz, 1 CPU, 16 logical and 8 physical cores
.NET SDK 10.0.100-preview.6.25358.103
  [Host]     : .NET 8.0.18 (8.0.1825.31117), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-AIONMJ : .NET 10.0.0 (10.0.25.35903), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-YDJZTJ : .NET 8.0.18 (8.0.1825.31117), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-XGIHIM : .NET 9.0.7 (9.0.725.31616), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI

Other information

No response

Activity

  1. added
    untriaged
    on Aug 17, 2025
  2. added
    needs-area-label
    on Aug 17, 2025
  3. EgorBo commented on Aug 17, 2025

    @EgorBo
    Member

    @timcassell can you point to the code that is measuring memory allocations in BDN?

  4. added and removed
    needs-area-label
    on Aug 17, 2025
  5. dotnet-policy-service commented on Aug 17, 2025

    @dotnet-policy-service
    Contributor

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

  6. EgorBo commented on Aug 17, 2025

    @EgorBo
    Member

    Thanks, I was curious if GetTotalAllocatedBytes result could be accidentally boxed (JIT may hoist allocations in some cases), but it's clearly not the case here.

  7. removed
    untriaged
    on Aug 18, 2025
  8. added this to the 10.0.0 milestone on Aug 18, 2025
  9. kg commented on Aug 18, 2025

    @kg
    Contributor

    Could this be another symptom of #106712 ? I see code in the GcStats.cs that clamps values to zero if they are negative.

  10. timcassell commented on Aug 18, 2025

    @timcassell
    Author

    That does not appear to be the case here. I printed the read values before the subtraction (where the clamp occurs), and both are positive, but the second read is smaller than the first read.

    Allocated Initial: 130296238672, Final: 123078689664
    
  11. added
    untriaged
    on Sep 19, 2025
  12. removed
    untriaged
    on Sep 19, 2025
  13. AdrianoAE commented on Oct 15, 2025

    @AdrianoAE

    The issue seems to have gotten worse in RC2, not only the random 0 happen a lot more (even with just a simple benchmark) but also starts "hallucinating" with very high values like from 368 B to 1616 B

    Image

    Unfortunately all the benchmarks I'm working with are having this issue making the results unusable unless I do multiple runs and then manually merge the values that seem to be correct

    EDIT: got another run with the high values (NOTE: this benchmark is different from the one above):

    Image

    Expected (one run without the bug)

    Image
  14. adamsitnik commented on Oct 20, 2025

    @adamsitnik
    Member

    @dotnet/gc could you PTAL?

  15. timcassell commented on Dec 1, 2025

    @timcassell
    Author

    Is anyone looking at this? It's blocking BDN from updating tests to newer tfm (it will cause MemoryDiagnoser tests to fail).

  16. agocke commented on Jan 5, 2026

    @agocke
    Member

    @dotnet/dotnet-diag Any ideas?

  17. jkotas commented on Jan 6, 2026

    @jkotas
    Member

    It is accounting bug in the GC, likely introduced by the regions feature. It may be useful to check whether it repros with regions turned off. @timcassell Could you please try to set DOTNET_GCName=clrgc.dll and check whether the problem goes away?

  18. timcassell commented on Jan 6, 2026

    @timcassell
    Author

    Could you please try to set DOTNET_GCName=clrgc.dll and check whether the problem goes away?

    I was unable to repro with that.

  19. jkotas commented on Jan 6, 2026

    @jkotas
    Member

    Thanks, it confirms the theory that this is likely a bug in GC regions feature.

  20. added 4 commits that reference this issue on Jul 20, 2026
    903862d
    5648bcd
    8ae297a
    9d7d71a
  21. locked and limited conversation to collaborators on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions