Ubuntu
Update dir structure
06bbd08
{
"number": 100002,
"title": "Skip ro segments which are not in range when walking heap for GC diagnostics",
"body": "Fixed crash in gc_heap::walk_heap_per_heap when walking frozen segments\r\n\r\n**Motivation:**\r\n\r\nEnabling `COR_PRF_MONITOR_GC` GC Heap diagnostics flag causes crash after initiating AssemblyLoadContext unloading with the following callstack.\r\n\r\n```\r\n[Inline Frame] coreclr.dll!WKS::my_get_size(Object *) Line 11572\tC++\tSymbols loaded.\r\n>\tcoreclr.dll!WKS::gc_heap::walk_heap_per_heap(bool(*)(Object *, void *) fn, void * context, int gen_number, int walk_large_object_heap_p) Line 51974\tC++\tSymbols loaded.\r\n \tcoreclr.dll!GCProfileWalkHeapWorker(int fProfilerPinned, int fShouldWalkHeapRootsForEtw, int fShouldWalkHeapObjectsForEtw) Line 727\tC++\tSymbols loaded.\r\n \tcoreclr.dll!GCToEEInterface::DiagGCEnd(unsigned __int64 fConcurrent, int index, int gen, bool reason) Line 818\tC++\tSymbols loaded.\r\n \tcoreclr.dll!WKS::gc_heap::do_post_gc() Line 50183\tC++\tSymbols loaded.\r\n \tcoreclr.dll!WKS::gc_heap::gc1() Line 22865\tC++\tSymbols loaded.\r\n \t[Inline Frame] coreclr.dll!GCToOSInterface::GetLowPrecisionTimeStamp() Line 1091\tC++\tSymbols loaded.\r\n \tcoreclr.dll!WKS::gc_heap::garbage_collect(int n) Line 24329\tC++\tSymbols loaded.\r\n \tcoreclr.dll!WKS::GCHeap::GarbageCollectGeneration(unsigned int gen, gc_reason reason) Line 50526\tC++\tSymbols loaded.\r\n \tcoreclr.dll!WKS::GCHeap::GarbageCollect(int generation, bool low_memory_p, int mode) Line 49681\tC++\tSymbols loaded.\r\n \tcoreclr.dll!ETW::GCLog::ForceGCForDiagnostics() Line 492\tC++\tSymbols loaded.\r\n \t[Inline Frame] coreclr.dll!ETW::GCLog::ForceGC(__int64) Line 431\tC++\t\r\n```\r\n\r\nI was suspecting invalid profiler setup, however the issue was also reproducible with [PerfView](https://github.com/microsoft/perfview) tool without enabling `COR_PRF_MONITOR_GC` flag via profiler dll at startup - tool crashes on GC Heap dump once one of assemblies from AssemblyLoadContext gets unloaded.\r\n\r\nI was suspecting then heap corruption, but was not able to gather any proof of that by running `gc::verify_heap` every GC and native/managed transition (the latter was painfully slow 😁). Further comparison with `gc::verify_heap` yielded that heap verification uses `heap_segment_in_range/heap_segment_next_in_range` methods [to get the heap segment to iterate over](https://github.com/dotnet/runtime/blob/main/src/coreclr/gc/gc.cpp#L47873). `heap_segment_in_range` checks that segment is not readonly/frozen (`heap_segment_flags_readonly` flag) or if it is “in range” (`heap_segment_flags_inrange` flag). At the same time `gc_heap::walk_heap_per_heap` scans through all segments.\r\n\r\n**Changes**:\r\n\r\nMy hypothesis is that assembly unloading may free/rollback segments that are used for string/type/etc data in frozen segments and thus we need to skip such segments when traversing heap for diagnostics. I might be wrong given my limited understanding of `USE_RANGES` feature and would appreciate other ideas 😄 ",
"createdAt": "2024-03-20T09:15:59Z",
"closedAt": "2024-03-29T16:36:08Z",
"mergedAt": null,
"state": "CLOSED",
"author": {
"login": "alexey-zakharov"
},
"labels": {
"nodes": [
{
"name": "area-GC-coreclr"
},
{
"name": "community-contribution"
}
]
},
"headRefName": "upstream-walk_heap-skip-frozen-segments",
"additions": 5,
"deletions": 5,
"changedFiles": 1,
"comments": {
"totalCount": 10,
"nodes": [
{
"body": "Tagging subscribers to this area: @dotnet/gc\nSee info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.\n<!-- Policy app identification https://img.shields.io/static/v1?label=PullRequestIssueManagement. -->",
"createdAt": "2024-03-20T09:16:29Z"
},
{
"body": "@dotnet-policy-service agree company=\"Unity Technologies\"",
"createdAt": "2024-03-20T09:24:34Z"
},
{
"body": "cc @cshung \r\n\r\n> My hypothesis is that assembly unloading may free/rollback segments that are used for string/type/etc data in frozen segments\r\n\r\nWe currently never unregister/remove such segments and never put stuff from unloadable ALCs there 🤔 ",
"createdAt": "2024-03-20T15:33:07Z"
},
{
"body": "> We currently never unregister/remove such segments and never put stuff from unloadable ALCs there 🤔\r\n\r\nthanks! ok, then my understanding was wrong and perhaps we do have segments corruption or there is another mechanism that may unmark segments\r\nin case of corruption the question then would be how to diagnose it assuming verify_heap skips such segments and never crashes? 🤔 (perhaps protect frozen segments memory with READONLY flag)",
"createdAt": "2024-03-20T15:43:51Z"
},
{
"body": "@alexey-zakharov, is the crash something you can share with us a repro?",
"createdAt": "2024-03-20T16:34:43Z"
},
{
"body": "> @alexey-zakharov, is the crash something you can share with us a repro?\r\n\r\n@cshung yes, I think so - do you know what are the guidelines for sharing?\r\nand should I make an issue instead?",
"createdAt": "2024-03-21T08:41:47Z"
},
{
"body": "> Do you know what are the guidelines for sharing? and should I make an issue instead?\r\n\r\nThanks for planning to share! I don't think we have guidelines for sharing repro, but we have a template for opening bug issues and there are some general questions that you can answer there.\r\n\r\nhttps://github.com/dotnet/runtime/issues/new?assignees=&labels=&projects=&template=01_bug_report.yml",
"createdAt": "2024-03-21T17:57:04Z"
},
{
"body": "Is this superseded by https://github.com/dotnet/runtime/pull/100444 ?",
"createdAt": "2024-03-29T16:21:46Z"
},
{
"body": "> Is this superseded by #100444 ?\r\n\r\nyes, I've dug deeper into the issue and we've figured a better fix\r\nI'm closing this PR",
"createdAt": "2024-03-29T16:36:08Z"
},
{
"body": "(the real issue we had was that SzArray of a collectible type was allocated on a frozen heap and once LoaderAllocator gets destroyed object's MethodTable points to a bad memory which leads to random consequences when iterating heap)",
"createdAt": "2024-03-29T16:39:12Z"
}
]
},
"reviewThreads": {
"totalCount": 0,
"nodes": []
},
"commits": {
"totalCount": 1,
"nodes": [
{
"commit": {
"oid": "397d04883ccec635d21d6891c4beea3cd26150bd",
"message": "Skip ro segments which are not in range when walking heap for GC diagnostics",
"committedDate": "2024-03-20T09:09:08Z"
}
}
]
}
}