dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.18k stars 355 forks source link

!eeheap is reporting slightly inaccurate committed bytes. #3482

Closed cshung closed 1 year ago

cshung commented 1 year ago

There are 2 cases where we are reporting slightly wrong numbers for committed bytes in !eeheap. The main problem is that, in general, the number of committed bytes is not exactly heap_segment_committed - heap_segment_mem. We typically have some space before heap_segment_mem to store something.

Case 1: Normal (i.e. not frozen) segments

Case 2: Frozen segments.

The difference should be pseginfo->ibFirstObject as in GCHeap::RegisterFrozenSegment. In the frozen object heap implementation, we specified that as sizeof(ObjHeader).

The inaccuracies are typically small, off by a few bytes up to a page per segment at most.

In https://github.com/dotnet/runtime/pull/72229 (and some earlier work), I introduced gc_heap::committed_by_oh and gc_heap::committed_by_oh_per_heap arrays. These arrays maintain the total number of bytes committed per heap and per object heap.

Whenever the inaccuracies are fixed, we should be able to compare the values stored in the array and the value reported by !eeheap and assert they are equal.

leculver commented 1 year ago

@cshung Is it ok if I assign this to myself and start working on it?

cshung commented 1 year ago

@cshung Is it ok if I assign this to myself and start working on it?

Sure

leculver commented 1 year ago

I have fixed this in ClrMD. PR #3823 has the fixed version.