From 6704c534405b0d3fb4252846d84272baa8beeb4c Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 13 Apr 2021 17:45:32 +0300 Subject: [PATCH 1/2] Rename SlabMemoryPool #31609 --- src/Servers/HttpSys/src/HttpSysListener.cs | 8 ++++---- src/Servers/IIS/IIS/src/Core/IISHttpServer.cs | 2 +- .../Core/test/ConcurrentPipeWriterTests.cs | 20 +++++++++---------- .../Core/test/DiagnosticMemoryPoolTests.cs | 8 ++++---- .../Kestrel/Core/test/Http1ConnectionTests.cs | 2 +- .../Core/test/HttpResponseHeadersTests.cs | 2 +- .../Kestrel/Core/test/OutputProducerTests.cs | 2 +- .../Core/test/PipelineExtensionTests.cs | 2 +- .../Kestrel/Core/test/SlabMemoryPoolTests.cs | 4 ++-- .../Kestrel/Core/test/StartLineTests.cs | 2 +- .../Core/test/TestHelpers/TestInput.cs | 2 +- .../src/Internal/LibuvConnection.cs | 2 +- .../src/LibuvTransportOptions.cs | 2 +- .../test/LibuvOutputConsumerTests.cs | 2 +- .../src/QuicTransportOptions.cs | 2 +- .../src/Internal/SocketConnection.cs | 2 +- .../src/SocketTransportOptions.cs | 2 +- .../Microbenchmarks/ChunkWriterBenchmark.cs | 2 +- .../Http1ConnectionBenchmark.cs | 2 +- ...Http1ConnectionParsingOverheadBenchmark.cs | 2 +- .../Http1LargeWritingBenchmark.cs | 2 +- .../Microbenchmarks/Http1ReadingBenchmark.cs | 2 +- .../Microbenchmarks/Http1WritingBenchmark.cs | 2 +- .../Http2ConnectionBenchmarkBase.cs | 2 +- .../Http2FrameWriterBenchmark.cs | 2 +- .../HttpProtocolFeatureCollection.cs | 2 +- .../PipeThroughputBenchmark.cs | 2 +- .../RequestParsingBenchmark.cs | 2 +- .../ResponseHeaderCollectionBenchmark.cs | 2 +- .../Kestrel/shared/test/TestContextFactory.cs | 2 +- .../Kestrel/shared/test/TestServiceContext.cs | 2 +- .../DiagnosticMemoryPoolFactory.cs | 2 +- .../Http2/Http2TestBase.cs | 2 +- .../Http3/Http3TestBase.cs | 2 +- .../Buffers.MemoryPool/MemoryPoolBlock.cs | 4 ++-- .../Buffers.MemoryPool/MemoryPoolFactory.cs | 10 +++++----- ...MemoryPool.cs => PinnedBlockMemoryPool.cs} | 2 +- 37 files changed, 58 insertions(+), 58 deletions(-) rename src/Shared/Buffers.MemoryPool/{SlabMemoryPool.cs => PinnedBlockMemoryPool.cs} (98%) diff --git a/src/Servers/HttpSys/src/HttpSysListener.cs b/src/Servers/HttpSys/src/HttpSysListener.cs index ec3a8d5d314b..2007c64f95ad 100644 --- a/src/Servers/HttpSys/src/HttpSysListener.cs +++ b/src/Servers/HttpSys/src/HttpSysListener.cs @@ -20,7 +20,7 @@ internal partial class HttpSysListener : IDisposable { // Win8# 559317 fixed a bug in Http.sys's HttpReceiveClientCertificate method. // Without this fix IOCP callbacks were not being called although ERROR_IO_PENDING was - // returned from HttpReceiveClientCertificate when using the + // returned from HttpReceiveClientCertificate when using the // FileCompletionNotificationModes.SkipCompletionPortOnSuccess flag. // This bug was only hit when the buffer passed into HttpReceiveClientCertificate // (1500 bytes initially) is too small for the certificate. @@ -28,12 +28,12 @@ internal partial class HttpSysListener : IDisposable // flag is only used on Win8 and later. internal static readonly bool SkipIOCPCallbackOnSuccess = ComNetOS.IsWin8orLater; - // Mitigate potential DOS attacks by limiting the number of unknown headers we accept. Numerous header names - // with hash collisions will cause the server to consume excess CPU. 1000 headers limits CPU time to under + // Mitigate potential DOS attacks by limiting the number of unknown headers we accept. Numerous header names + // with hash collisions will cause the server to consume excess CPU. 1000 headers limits CPU time to under // 0.5 seconds per request. Respond with a 400 Bad Request. private const int UnknownHeaderLimit = 1000; - internal MemoryPool MemoryPool { get; } = SlabMemoryPoolFactory.Create(); + internal MemoryPool MemoryPool { get; } = PinnedBlockMemoryPoolFactory.Create(); private volatile State _state; // m_State is set only within lock blocks, but often read outside locks. diff --git a/src/Servers/IIS/IIS/src/Core/IISHttpServer.cs b/src/Servers/IIS/IIS/src/Core/IISHttpServer.cs index 1d6ba9dadd3c..f4af6b2ba98e 100644 --- a/src/Servers/IIS/IIS/src/Core/IISHttpServer.cs +++ b/src/Servers/IIS/IIS/src/Core/IISHttpServer.cs @@ -23,7 +23,7 @@ internal class IISHttpServer : IServer private const string WebSocketVersionString = "WEBSOCKET_VERSION"; private IISContextFactory? _iisContextFactory; - private readonly MemoryPool _memoryPool = new SlabMemoryPool(); + private readonly MemoryPool _memoryPool = new PinnedBlockMemoryPool(); private GCHandle _httpServerHandle; private readonly IHostApplicationLifetime _applicationLifetime; private readonly ILogger _logger; diff --git a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs index 246795b355e6..e734f016438a 100644 --- a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs +++ b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs @@ -16,7 +16,7 @@ public class ConcurrentPipeWriterTests [Fact] public async Task PassthroughIfAllFlushesAreAwaited() { - using (var slabPool = new SlabMemoryPool()) + using (var slabPool = new PinnedBlockMemoryPool()) using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) { var pipeWriterFlushTcsArray = new[] { @@ -79,7 +79,7 @@ public async Task PassthroughIfAllFlushesAreAwaited() [Fact] public async Task QueuesIfFlushIsNotAwaited() { - using (var slabPool = new SlabMemoryPool()) + using (var slabPool = new PinnedBlockMemoryPool()) using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) { var pipeWriterFlushTcsArray = new[] { @@ -177,7 +177,7 @@ public async Task QueuesIfFlushIsNotAwaited() [Fact] public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() { - using (var slabPool = new SlabMemoryPool()) + using (var slabPool = new PinnedBlockMemoryPool()) using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) { var pipeWriterFlushTcsArray = new[] { @@ -229,7 +229,7 @@ public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() } // Now that we flushed the ConcurrentPipeWriter again, the GetMemory() and Advance() calls are replayed. - // Make sure that MockPipeWriter.SlabMemoryPoolBlockSize matches SlabMemoryPool._blockSize or else + // Make sure that MockPipeWriter.PinnedBlockMemoryPoolBlockSize matches PinnedBlockMemoryPool._blockSize or else // it might take more or less calls to the inner PipeWriter's GetMemory method to copy all the data. Assert.Equal(3, mockPipeWriter.GetMemoryCallCount); Assert.Equal(3, mockPipeWriter.AdvanceCallCount); @@ -261,7 +261,7 @@ public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() [Fact] public async Task CompleteFlushesQueuedBytes() { - using (var slabPool = new SlabMemoryPool()) + using (var slabPool = new PinnedBlockMemoryPool()) using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) { var pipeWriterFlushTcsArray = new[] { @@ -317,7 +317,7 @@ public async Task CompleteFlushesQueuedBytes() await completeTask.DefaultTimeout(); // Now that we completed the ConcurrentPipeWriter, the GetMemory() and Advance() calls are replayed. - // Make sure that MockPipeWriter.SlabMemoryPoolBlockSize matches SlabMemoryPool._blockSize or else + // Make sure that MockPipeWriter.PinnedBlockMemoryPoolBlockSize matches PinnedBlockMemoryPool._blockSize or else // it might take more or less calls to the inner PipeWriter's GetMemory method to copy all the data. Assert.Equal(3, mockPipeWriter.GetMemoryCallCount); Assert.Equal(3, mockPipeWriter.AdvanceCallCount); @@ -329,7 +329,7 @@ public async Task CompleteFlushesQueuedBytes() [Fact] public async Task CancelPendingFlushInterruptsFlushLoop() { - using (var slabPool = new SlabMemoryPool()) + using (var slabPool = new PinnedBlockMemoryPool()) using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) { var pipeWriterFlushTcsArray = new[] { @@ -411,8 +411,8 @@ public async Task CancelPendingFlushInterruptsFlushLoop() private class MockPipeWriter : PipeWriter { - // It's important that this matches SlabMemoryPool._blockSize for all the tests to pass. - private const int SlabMemoryPoolBlockSize = 4096; + // It's important that this matches PinnedBlockMemoryPool._blockSize for all the tests to pass. + private const int PinnedBlockMemoryPoolBlockSize = 4096; private readonly TaskCompletionSource[] _flushResults; @@ -440,7 +440,7 @@ public override ValueTask FlushAsync(CancellationToken cancellation public override Memory GetMemory(int sizeHint = 0) { GetMemoryCallCount++; - return new Memory(new byte[sizeHint == 0 ? SlabMemoryPoolBlockSize : sizeHint]); + return new Memory(new byte[sizeHint == 0 ? PinnedBlockMemoryPoolBlockSize : sizeHint]); } public override Span GetSpan(int sizeHint = 0) diff --git a/src/Servers/Kestrel/Core/test/DiagnosticMemoryPoolTests.cs b/src/Servers/Kestrel/Core/test/DiagnosticMemoryPoolTests.cs index 51c9a9fcdcb4..001e969928be 100644 --- a/src/Servers/Kestrel/Core/test/DiagnosticMemoryPoolTests.cs +++ b/src/Servers/Kestrel/Core/test/DiagnosticMemoryPoolTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Internal.Test { public class DiagnosticMemoryPoolTests: MemoryPoolTests { - protected override MemoryPool CreatePool() => new DiagnosticMemoryPool(new SlabMemoryPool()); + protected override MemoryPool CreatePool() => new DiagnosticMemoryPool(new PinnedBlockMemoryPool()); [Fact] public void DoubleDisposeThrows() @@ -176,7 +176,7 @@ public void GetMemoryTryGetArrayOfDisposedThrows() [Fact] public async Task DoesNotThrowWithLateReturns() { - var memoryPool = new DiagnosticMemoryPool(new SlabMemoryPool(), allowLateReturn: true); + var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), allowLateReturn: true); var block = memoryPool.Rent(); memoryPool.Dispose(); block.Dispose(); @@ -186,7 +186,7 @@ public async Task DoesNotThrowWithLateReturns() [Fact] public async Task ThrowsOnAccessToLateBlocks() { - var memoryPool = new DiagnosticMemoryPool(new SlabMemoryPool(), allowLateReturn: true); + var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), allowLateReturn: true); var block = memoryPool.Rent(); memoryPool.Dispose(); @@ -202,7 +202,7 @@ public async Task ThrowsOnAccessToLateBlocks() [Fact] public void ExceptionsContainStackTraceWhenEnabled() { - var memoryPool = new DiagnosticMemoryPool(new SlabMemoryPool(), rentTracking: true); + var memoryPool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), rentTracking: true); var block = memoryPool.Rent(); ExpectDisposeException(memoryPool); diff --git a/src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs b/src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs index 8a8ddd0ac000..85c6026694f4 100644 --- a/src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs +++ b/src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs @@ -42,7 +42,7 @@ public class Http1ConnectionTests : IDisposable public Http1ConnectionTests() { - _pipelineFactory = SlabMemoryPoolFactory.Create(); + _pipelineFactory = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(_pipelineFactory, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs b/src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs index f5865dbc3e76..a04a497271ec 100644 --- a/src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs +++ b/src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs @@ -23,7 +23,7 @@ public class HttpResponseHeadersTests [Fact] public void InitialDictionaryIsEmpty() { - using (var memoryPool = SlabMemoryPoolFactory.Create()) + using (var memoryPool = PinnedBlockMemoryPoolFactory.Create()) { var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/Core/test/OutputProducerTests.cs b/src/Servers/Kestrel/Core/test/OutputProducerTests.cs index fffc897d7dad..a32afaba3fe7 100644 --- a/src/Servers/Kestrel/Core/test/OutputProducerTests.cs +++ b/src/Servers/Kestrel/Core/test/OutputProducerTests.cs @@ -21,7 +21,7 @@ public class OutputProducerTests : IDisposable public OutputProducerTests() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); } public void Dispose() diff --git a/src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs b/src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs index 3f8170385310..7df5b8f4efdf 100644 --- a/src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs +++ b/src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs @@ -17,7 +17,7 @@ public class PipelineExtensionTests : IDisposable private const int _ulongMaxValueLength = 20; private readonly Pipe _pipe; - private readonly MemoryPool _memoryPool = SlabMemoryPoolFactory.Create(); + private readonly MemoryPool _memoryPool = PinnedBlockMemoryPoolFactory.Create(); public PipelineExtensionTests() { diff --git a/src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs b/src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs index 796dc2f5df83..d74ca35ee4a8 100644 --- a/src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs +++ b/src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs @@ -6,9 +6,9 @@ namespace Microsoft.Extensions.Internal.Test { - public class SlabMemoryPoolTests: MemoryPoolTests + public class PinnedBlockMemoryPoolTests: MemoryPoolTests { - protected override MemoryPool CreatePool() => new SlabMemoryPool(); + protected override MemoryPool CreatePool() => new PinnedBlockMemoryPool(); [Fact] public void DoubleDisposeWorks() diff --git a/src/Servers/Kestrel/Core/test/StartLineTests.cs b/src/Servers/Kestrel/Core/test/StartLineTests.cs index 812eb9b18c0a..1657199345ff 100644 --- a/src/Servers/Kestrel/Core/test/StartLineTests.cs +++ b/src/Servers/Kestrel/Core/test/StartLineTests.cs @@ -518,7 +518,7 @@ public void AuthorityForms(string rawTarget, string path, string query) public StartLineTests() { - MemoryPool = SlabMemoryPoolFactory.Create(); + MemoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(MemoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); Transport = pair.Transport; diff --git a/src/Servers/Kestrel/Core/test/TestHelpers/TestInput.cs b/src/Servers/Kestrel/Core/test/TestHelpers/TestInput.cs index a73e828453b9..96ecdce60a96 100644 --- a/src/Servers/Kestrel/Core/test/TestHelpers/TestInput.cs +++ b/src/Servers/Kestrel/Core/test/TestHelpers/TestInput.cs @@ -23,7 +23,7 @@ class TestInput : IDisposable public TestInput(IKestrelTrace log = null, ITimeoutControl timeoutControl = null) { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); Transport = pair.Transport; diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs index ed192c7f8f98..3fb4579f135c 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { internal partial class LibuvConnection : TransportConnection { - private static readonly int MinAllocBufferSize = SlabMemoryPool.BlockSize / 2; + private static readonly int MinAllocBufferSize = PinnedBlockMemoryPool.BlockSize / 2; private static readonly Action _readCallback = (handle, status, state) => ReadCallback(handle, status, state); diff --git a/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs b/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs index 6545f134e822..2a5c4172e27c 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/LibuvTransportOptions.cs @@ -45,7 +45,7 @@ public class LibuvTransportOptions [Obsolete("The libuv transport is obsolete and will be removed in a future release. See https://aka.ms/libuvtransport for details.", error: false)] // Remove after .NET 6. public long? MaxWriteBufferSize { get; set; } = 64 * 1024; - internal Func> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; + internal Func> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create; private static int ProcessorThreadCount { diff --git a/src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs index a9fa3e62ed6e..5bfaa397f5ff 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/LibuvOutputConsumerTests.cs @@ -41,7 +41,7 @@ public class LibuvOutputConsumerTests : IDisposable public LibuvOutputConsumerTests() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _mockLibuv = new MockLibuv(); var context = new TestLibuvTransportContext(); diff --git a/src/Servers/Kestrel/Transport.Quic/src/QuicTransportOptions.cs b/src/Servers/Kestrel/Transport.Quic/src/QuicTransportOptions.cs index 22fbf064de94..8a3890f8bfe0 100644 --- a/src/Servers/Kestrel/Transport.Quic/src/QuicTransportOptions.cs +++ b/src/Servers/Kestrel/Transport.Quic/src/QuicTransportOptions.cs @@ -42,7 +42,7 @@ public class QuicTransportOptions /// public long? MaxWriteBufferSize { get; set; } = 64 * 1024; - internal Func> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; + internal Func> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create; } } diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs index 35b7c66113ec..17e662a69f0a 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { internal sealed partial class SocketConnection : TransportConnection { - private static readonly int MinAllocBufferSize = SlabMemoryPool.BlockSize / 2; + private static readonly int MinAllocBufferSize = PinnedBlockMemoryPool.BlockSize / 2; private readonly Socket _socket; private readonly ISocketsTrace _trace; diff --git a/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs index 94350412cede..1c6ab6114886 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs @@ -65,6 +65,6 @@ public class SocketTransportOptions /// public bool UnsafePreferInlineScheduling { get; set; } - internal Func> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; + internal Func> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create; } } diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/ChunkWriterBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/ChunkWriterBenchmark.cs index d1df2cd0cbc5..a93a085dcb9e 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/ChunkWriterBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/ChunkWriterBenchmark.cs @@ -20,7 +20,7 @@ public class ChunkWriterBenchmark [GlobalSetup] public void Setup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); var pipe = new Pipe(new PipeOptions(_memoryPool)); _reader = pipe.Reader; _writer = pipe.Writer; diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionBenchmark.cs index 230c6a664208..45ddff65c3a6 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionBenchmark.cs @@ -29,7 +29,7 @@ public class Http1ConnectionBenchmark [GlobalSetup] public void Setup() { - var memoryPool = SlabMemoryPoolFactory.Create(); + var memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs index 79f5518740ef..70211fffc8da 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs @@ -23,7 +23,7 @@ public class Http1ConnectionParsingOverheadBenchmark [IterationSetup] public void Setup() { - var memoryPool = SlabMemoryPoolFactory.Create(); + var memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http1LargeWritingBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http1LargeWritingBenchmark.cs index abcfc6e07d80..54fbeda66c7d 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http1LargeWritingBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http1LargeWritingBenchmark.cs @@ -28,7 +28,7 @@ public class Http1LargeWritingBenchmark [GlobalSetup] public void GlobalSetup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _http1Connection = MakeHttp1Connection(); _consumeResponseBodyTask = ConsumeResponseBody(); } diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ReadingBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ReadingBenchmark.cs index 227c853a3062..1b87d80e0890 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http1ReadingBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http1ReadingBenchmark.cs @@ -35,7 +35,7 @@ public class Http1ReadingBenchmark [GlobalSetup] public void GlobalSetup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _http1Connection = MakeHttp1Connection(); } diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http1WritingBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http1WritingBenchmark.cs index cbcf63f3b212..1139d47ea073 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http1WritingBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http1WritingBenchmark.cs @@ -35,7 +35,7 @@ public class Http1WritingBenchmark [GlobalSetup] public void GlobalSetup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _http1Connection = MakeHttp1Connection(); _consumeResponseBodyTask = ConsumeResponseBody(); } diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http2ConnectionBenchmarkBase.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http2ConnectionBenchmarkBase.cs index 0c49f277eff6..94038447a964 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http2ConnectionBenchmarkBase.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http2ConnectionBenchmarkBase.cs @@ -42,7 +42,7 @@ public abstract class Http2ConnectionBenchmarkBase public virtual void GlobalSetup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _httpFrame = new Http2Frame(); var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/Http2FrameWriterBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/Http2FrameWriterBenchmark.cs index 19b69c55d538..4153da140b0d 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/Http2FrameWriterBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/Http2FrameWriterBenchmark.cs @@ -24,7 +24,7 @@ public class Http2FrameWriterBenchmark [GlobalSetup] public void GlobalSetup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); _pipe = new Pipe(options); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/HttpProtocolFeatureCollection.cs b/src/Servers/Kestrel/perf/Microbenchmarks/HttpProtocolFeatureCollection.cs index ee0fc5c7f45e..0cc086ce2c3a 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/HttpProtocolFeatureCollection.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/HttpProtocolFeatureCollection.cs @@ -226,7 +226,7 @@ public IHttpNotFoundFeature Get_IHttpNotFoundFeature() public HttpProtocolFeatureCollection() { - var memoryPool = SlabMemoryPoolFactory.Create(); + var memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/PipeThroughputBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/PipeThroughputBenchmark.cs index 720730c53867..7c55fbea2852 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/PipeThroughputBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/PipeThroughputBenchmark.cs @@ -19,7 +19,7 @@ public class PipeThroughputBenchmark [IterationSetup] public void Setup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); _pipe = new Pipe(new PipeOptions(_memoryPool)); } diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/RequestParsingBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/RequestParsingBenchmark.cs index 5efb68844f51..74b49ee14597 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/RequestParsingBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/RequestParsingBenchmark.cs @@ -24,7 +24,7 @@ public class RequestParsingBenchmark [IterationSetup] public void Setup() { - _memoryPool = SlabMemoryPoolFactory.Create(); + _memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/perf/Microbenchmarks/ResponseHeaderCollectionBenchmark.cs b/src/Servers/Kestrel/perf/Microbenchmarks/ResponseHeaderCollectionBenchmark.cs index 856e8c6f4bb2..019ffeae62ef 100644 --- a/src/Servers/Kestrel/perf/Microbenchmarks/ResponseHeaderCollectionBenchmark.cs +++ b/src/Servers/Kestrel/perf/Microbenchmarks/ResponseHeaderCollectionBenchmark.cs @@ -172,7 +172,7 @@ private void Unknown(int count) [IterationSetup] public void Setup() { - var memoryPool = SlabMemoryPoolFactory.Create(); + var memoryPool = PinnedBlockMemoryPoolFactory.Create(); var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); diff --git a/src/Servers/Kestrel/shared/test/TestContextFactory.cs b/src/Servers/Kestrel/shared/test/TestContextFactory.cs index 09687a3fd7c0..4b64ac289435 100644 --- a/src/Servers/Kestrel/shared/test/TestContextFactory.cs +++ b/src/Servers/Kestrel/shared/test/TestContextFactory.cs @@ -87,7 +87,7 @@ public static Http3ConnectionContext CreateHttp3ConnectionContext( connectionContext ?? new TestMultiplexedConnectionContext(), serviceContext ?? CreateServiceContext(new KestrelServerOptions()), connectionFeatures ?? new FeatureCollection(), - memoryPool ?? SlabMemoryPoolFactory.Create(), + memoryPool ?? PinnedBlockMemoryPoolFactory.Create(), localEndPoint, remoteEndPoint); http3ConnectionContext.TimeoutControl = timeoutControl; diff --git a/src/Servers/Kestrel/shared/test/TestServiceContext.cs b/src/Servers/Kestrel/shared/test/TestServiceContext.cs index 6b3ca5da959e..2b9da35b6a30 100644 --- a/src/Servers/Kestrel/shared/test/TestServiceContext.cs +++ b/src/Servers/Kestrel/shared/test/TestServiceContext.cs @@ -74,7 +74,7 @@ private void Initialize(ILoggerFactory loggerFactory, IKestrelTrace kestrelTrace public MockSystemClock MockSystemClock { get; set; } - public Func> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create; + public Func> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create; public string DateHeaderValue => DateHeaderValueManager.GetDateHeaderValues().String; } diff --git a/src/Servers/Kestrel/shared/test/TransportTestHelpers/DiagnosticMemoryPoolFactory.cs b/src/Servers/Kestrel/shared/test/TransportTestHelpers/DiagnosticMemoryPoolFactory.cs index 26c8746e3985..333717caf3fe 100644 --- a/src/Servers/Kestrel/shared/test/TransportTestHelpers/DiagnosticMemoryPoolFactory.cs +++ b/src/Servers/Kestrel/shared/test/TransportTestHelpers/DiagnosticMemoryPoolFactory.cs @@ -28,7 +28,7 @@ public MemoryPool Create() { lock (_pools) { - var pool = new DiagnosticMemoryPool(new SlabMemoryPool(), _allowLateReturn, _rentTracking); + var pool = new DiagnosticMemoryPool(new PinnedBlockMemoryPool(), _allowLateReturn, _rentTracking); _pools.Add(pool); return pool; } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index 8e288cb2de6e..ed710fdc6b61 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -119,7 +119,7 @@ protected static IEnumerable> ReadRateRequestHeader protected static readonly byte[] _noData = new byte[0]; protected static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2PeerSettings.MinAllowedMaxFrameSize)); - private readonly MemoryPool _memoryPool = SlabMemoryPoolFactory.Create(); + private readonly MemoryPool _memoryPool = PinnedBlockMemoryPoolFactory.Create(); internal readonly Http2PeerSettings _clientSettings = new Http2PeerSettings(); internal readonly HPackDecoder _hpackDecoder; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs index 44ce3ac90d39..d4efefeecac6 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs @@ -41,7 +41,7 @@ public class Http3TestBase : TestApplicationErrorLoggerLoggedTest, IDisposable internal readonly Mock _mockKestrelTrace = new Mock(); internal readonly Mock _mockTimeoutHandler = new Mock(); internal readonly Mock _mockTimeoutControl; - internal readonly MemoryPool _memoryPool = SlabMemoryPoolFactory.Create(); + internal readonly MemoryPool _memoryPool = PinnedBlockMemoryPoolFactory.Create(); protected Task _connectionTask; protected readonly TaskCompletionSource _closedStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); diff --git a/src/Shared/Buffers.MemoryPool/MemoryPoolBlock.cs b/src/Shared/Buffers.MemoryPool/MemoryPoolBlock.cs index d829983c91d9..464c1548f96d 100644 --- a/src/Shared/Buffers.MemoryPool/MemoryPoolBlock.cs +++ b/src/Shared/Buffers.MemoryPool/MemoryPoolBlock.cs @@ -10,7 +10,7 @@ namespace System.Buffers /// internal sealed class MemoryPoolBlock : IMemoryOwner { - internal MemoryPoolBlock(SlabMemoryPool pool, int length) + internal MemoryPoolBlock(PinnedBlockMemoryPool pool, int length) { Pool = pool; @@ -22,7 +22,7 @@ internal MemoryPoolBlock(SlabMemoryPool pool, int length) /// /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. /// - public SlabMemoryPool Pool { get; } + public PinnedBlockMemoryPool Pool { get; } public Memory Memory { get; } diff --git a/src/Shared/Buffers.MemoryPool/MemoryPoolFactory.cs b/src/Shared/Buffers.MemoryPool/MemoryPoolFactory.cs index 655b640c4547..64718c30706a 100644 --- a/src/Shared/Buffers.MemoryPool/MemoryPoolFactory.cs +++ b/src/Shared/Buffers.MemoryPool/MemoryPoolFactory.cs @@ -3,20 +3,20 @@ namespace System.Buffers { - internal static class SlabMemoryPoolFactory + internal static class PinnedBlockMemoryPoolFactory { public static MemoryPool Create() { #if DEBUG - return new DiagnosticMemoryPool(CreateSlabMemoryPool()); + return new DiagnosticMemoryPool(CreatePinnedBlockMemoryPool()); #else - return CreateSlabMemoryPool(); + return CreatePinnedBlockMemoryPool(); #endif } - public static MemoryPool CreateSlabMemoryPool() + public static MemoryPool CreatePinnedBlockMemoryPool() { - return new SlabMemoryPool(); + return new PinnedBlockMemoryPool(); } } } diff --git a/src/Shared/Buffers.MemoryPool/SlabMemoryPool.cs b/src/Shared/Buffers.MemoryPool/PinnedBlockMemoryPool.cs similarity index 98% rename from src/Shared/Buffers.MemoryPool/SlabMemoryPool.cs rename to src/Shared/Buffers.MemoryPool/PinnedBlockMemoryPool.cs index 4e766904bb3d..c86267b7a22b 100644 --- a/src/Shared/Buffers.MemoryPool/SlabMemoryPool.cs +++ b/src/Shared/Buffers.MemoryPool/PinnedBlockMemoryPool.cs @@ -10,7 +10,7 @@ namespace System.Buffers /// /// Used to allocate and distribute re-usable blocks of memory. /// - internal sealed class SlabMemoryPool : MemoryPool + internal sealed class PinnedBlockMemoryPool : MemoryPool { /// /// The size of a block. 4096 is chosen because most operating systems use 4k pages. From 228f257080eff7d1fedcf76453f5fd36052969bb Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 13 Apr 2021 23:07:53 +0300 Subject: [PATCH 2/2] Rename SlabMemoryPool #31609 fixed review comments --- .../Core/test/ConcurrentPipeWriterTests.cs | 20 +++++++++---------- ...Tests.cs => PinnedBlockMemoryPoolTests.cs} | 0 2 files changed, 10 insertions(+), 10 deletions(-) rename src/Servers/Kestrel/Core/test/{SlabMemoryPoolTests.cs => PinnedBlockMemoryPoolTests.cs} (100%) diff --git a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs index e734f016438a..0ae82a8e0ab2 100644 --- a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs +++ b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs @@ -16,8 +16,8 @@ public class ConcurrentPipeWriterTests [Fact] public async Task PassthroughIfAllFlushesAreAwaited() { - using (var slabPool = new PinnedBlockMemoryPool()) - using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) + using (var memoryPool = new PinnedBlockMemoryPool()) + using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool)) { var pipeWriterFlushTcsArray = new[] { new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), @@ -79,8 +79,8 @@ public async Task PassthroughIfAllFlushesAreAwaited() [Fact] public async Task QueuesIfFlushIsNotAwaited() { - using (var slabPool = new PinnedBlockMemoryPool()) - using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) + using (var memoryPool = new PinnedBlockMemoryPool()) + using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool)) { var pipeWriterFlushTcsArray = new[] { new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), @@ -177,8 +177,8 @@ public async Task QueuesIfFlushIsNotAwaited() [Fact] public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() { - using (var slabPool = new PinnedBlockMemoryPool()) - using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) + using (var memoryPool = new PinnedBlockMemoryPool()) + using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool)) { var pipeWriterFlushTcsArray = new[] { new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), @@ -261,8 +261,8 @@ public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() [Fact] public async Task CompleteFlushesQueuedBytes() { - using (var slabPool = new PinnedBlockMemoryPool()) - using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) + using (var memoryPool = new PinnedBlockMemoryPool()) + using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool)) { var pipeWriterFlushTcsArray = new[] { new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), @@ -329,8 +329,8 @@ public async Task CompleteFlushesQueuedBytes() [Fact] public async Task CancelPendingFlushInterruptsFlushLoop() { - using (var slabPool = new PinnedBlockMemoryPool()) - using (var diagnosticPool = new DiagnosticMemoryPool(slabPool)) + using (var memoryPool = new PinnedBlockMemoryPool()) + using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool)) { var pipeWriterFlushTcsArray = new[] { new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously), diff --git a/src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs b/src/Servers/Kestrel/Core/test/PinnedBlockMemoryPoolTests.cs similarity index 100% rename from src/Servers/Kestrel/Core/test/SlabMemoryPoolTests.cs rename to src/Servers/Kestrel/Core/test/PinnedBlockMemoryPoolTests.cs