Simple trim of ArrayPool buffers (#17078)
authorJeremy Kuhne <jeremy.kuhne@microsoft.com>
Wed, 11 Apr 2018 05:25:49 +0000 (22:25 -0700)
committerGitHub <noreply@github.com>
Wed, 11 Apr 2018 05:25:49 +0000 (22:25 -0700)
commita2508f048ccd41d5893275697b73fef39c2497f3
tree4005ba40dccb750b03bea8decc56d4c3ef21c9b9
parent76620c6dd5b340b2ac2c4e01b855b93ce18bf28a
Simple trim of ArrayPool buffers (#17078)

* Simple trim of ArrayPool buffers

Trim ArrayPool buffers on Gen2 GC if the buffer stack hasn't been emptied for awhile. If you haven't pulled all of the buffers in the past 10 seconds, let loose the top buffer on the stack and give the stack another 2 seconds of potential life. When the stack gets it's bottom bufferr returned the clock resets.

* Collect thread locals as well

* Add event

* Incorporate memory pressure into trimming.

Idea is that we normally give buckets a minute of age time unless the pressure starts to ramp up. As it ramps up we'll trim more off the stacks. If it gets really high we'll consider stale to be 10s instead of 1 min.

* Add implementation back for PinnableBufferCacheEventSource.

* Remove security attribute.
Fix GetMemoryInfo signature

* Always use Tls* for shared pools
Add environment variable switch

* Add guid to PinnableBufferCacheEventSource

* Address feedback

- move setting code to CLRConfig
- add constructor to PBCES
- trim large arrays more aggressively
- tweak names (ticks to ms, etc.)
- interlock creating the cleanup callback
- fix project file

Rent/return perf numbers are unchanged

* Remove static constructor
Inline Unsafe.SizeOf

* Fix spacing issue

* Trim all thread locals when memory pressure is high.
Move constants inline.

* Undo formatting changes

* Add back the internal call

* Put the right bits back *sigh*

* Missing the line feed

* Add event for trim polling

* Undo PinnableBufferCacheEventSource reimplementation
src/mscorlib/System.Private.CoreLib.csproj
src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/mscorlib/shared/System/Buffers/ArrayPool.cs
src/mscorlib/shared/System/Buffers/ArrayPoolEventSource.cs
src/mscorlib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
src/mscorlib/shared/System/Gen2GcCallback.cs [new file with mode: 0644]
src/mscorlib/shared/System/Runtime/ConstrainedExecution/CriticalFinalizerObject.cs [moved from src/mscorlib/src/System/Runtime/Reliability/CriticalFinalizerObject.cs with 100% similarity]
src/mscorlib/src/System/CLRConfig.cs
src/mscorlib/src/System/PinnableBufferCache.cs [moved from src/mscorlib/src/System/Threading/PinnableBufferCache.cs with 82% similarity]
src/mscorlib/src/System/PinnableBufferCacheEventSource.cs [new file with mode: 0644]