- Notifications
You must be signed in to change notification settings - Fork5.2k
Enable trimming TLS arrays in ArrayPool.Shared#56316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedJul 26, 2021
Tagging subscribers to this area:@GrabYourPitchforks, @dotnet/area-system-buffers Issue DetailsToday arrays stored in Contributes to#52098
|
jkotas left a comment
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
vargaz commentedJul 29, 2021
The failures are caused by a linker problem. Here is the original finally clause in ::Trim (): and here is the linked version: |
stephentoub commentedJul 29, 2021
|
danmoseley commentedJul 29, 2021
src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
stephentoub commentedJul 30, 2021
@steveisok, how can we unblock this PR? |
danmoseley commentedJul 30, 2021
@stephentoub failures in runtime-staging configurations do not block merge. Although, I thought they should not show up as red for that reason. |
steveisok commentedJul 30, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
That's true for test failures only. If you have a build failure, then it'll show up red. |
danmoseley commentedJul 30, 2021
(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.) |
danmoseley commentedJul 30, 2021
That makes sense. |
stephentoub commentedJul 30, 2021
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. |
jkotas commentedJul 30, 2021
My guess is that ifdefing the logging specific paths in Trim method for Mono is going to workaround the linker bug: |
stephentoub commentedJul 30, 2021
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.
DrewScoggins commentedAug 5, 2021
stephentoub commentedAug 5, 2021
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