-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Enable trimming TLS arrays in ArrayPool.Shared #56316
Conversation
Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-buffers Issue DetailsToday arrays stored in Contributes to #52098
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
Outdated
Show resolved
Hide resolved
The failures are caused by a linker problem. Here is the original finally clause in ::Trim ():
and here is the linked version:
|
cc: @sbomer, @vitek-karas |
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
Show resolved
Hide resolved
@steveisok, how can we unblock this PR? |
@stephentoub failures in runtime-staging configurations do not block merge. Although, I thought they should not show up as red for that reason. |
That's true for test failures only. If you have a build failure, then it'll show up red. |
(I mean, they don't block merge if the failures aren't clearly related. If this change breaks them more, we probably don't want to merge it.) |
That makes sense. |
Right. The problem is that the correct C# code and generated IL introduced by this PR is then getting mutilated by the linker and causing the AOT compiler to seg fault. As a temporary workaround to unblock this PR, I'd be happy to tweak the C# code to avoid whatever pattern is tripping up the linker, if someone can suggest what that pattern is. But it seems to me there's both a bug in the linker (dotnet/linker#2181) and a bug in the AOT compiler (seg faulting in response to bad IL) to be fixed here. |
My guess is that ifdefing the logging specific paths in Trim method for Mono is going to workaround the linker bug:
|
Ok, thanks, I'll give that a go. |
Today arrays stored in `ArrayPool<T>.Shared`'s per-core buckets have trimming applied, but arrays stored in the per-thread buckets are only trimmed when there's high memory pressure. This change enables all buffers to be trimmed (eventually). Every time our gen2 callback runs, it ensures any non-timestamped buffers have a timestamp, and also ensures that any timestamped buffers are still timely... if any aren't, they're eligible for trimming. The timestamp is reset for TLS arrays when they're stored, and for per-core buckets when they transition from empty to non-empty; the latter is just a tweak on the current behavior, which incurs the cost of Environment.TickCount upon that transition, whereas now we only pay it as part of the trimming pass.
Thanks, @DrewScoggins. It wasn't the initial intention of the PR, but I'm glad it had this affect (I expect from removing the TickCount check every time we transitioned from 0 to 1 array stored in the per-core stack). Do you see any movement here that might counteract what you reported in #56555? |
Today arrays stored in
ArrayPool<T>.Shared
's per-core buckets have trimming applied, but arrays stored in the per-thread buckets are only trimmed when there's high memory pressure. This change enables all buffers to be trimmed (eventually). Every time our gen2 callback runs, it ensures any non-timestamped buffers have a timestamp, and also ensures that any timestamped buffers are still timely... if any aren't, they're eligible for trimming. The timestamp is reset for TLS arrays when they're stored, and for per-core buckets when they transition from empty to non-empty; the latter is just a tweak on the current behavior, which incurs the cost of Environment.TickCount upon that transition, whereas now we only pay it as part of the trimming pass.Contributes to #52098
cc: @jkotas, @Maoni0