Skip to content

Rename SlabMemoryPool #31609 #31752

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Servers/HttpSys/src/HttpSysListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ 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.
// Due to this bug in downlevel operating systems the FileCompletionNotificationModes.SkipCompletionPortOnSuccess
// 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<byte> MemoryPool { get; } = SlabMemoryPoolFactory.Create();
internal MemoryPool<byte> MemoryPool { get; } = PinnedBlockMemoryPoolFactory.Create();

private volatile State _state; // m_State is set only within lock blocks, but often read outside locks.

Expand Down
2 changes: 1 addition & 1 deletion src/Servers/IIS/IIS/src/Core/IISHttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class IISHttpServer : IServer
private const string WebSocketVersionString = "WEBSOCKET_VERSION";

private IISContextFactory? _iisContextFactory;
private readonly MemoryPool<byte> _memoryPool = new SlabMemoryPool();
private readonly MemoryPool<byte> _memoryPool = new PinnedBlockMemoryPool();
private GCHandle _httpServerHandle;
private readonly IHostApplicationLifetime _applicationLifetime;
private readonly ILogger<IISHttpServer> _logger;
Expand Down
30 changes: 15 additions & 15 deletions src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class ConcurrentPipeWriterTests
[Fact]
public async Task PassthroughIfAllFlushesAreAwaited()
{
using (var slabPool = new SlabMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
using (var memoryPool = new PinnedBlockMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
{
var pipeWriterFlushTcsArray = new[] {
new TaskCompletionSource<FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
Expand Down Expand Up @@ -79,8 +79,8 @@ public async Task PassthroughIfAllFlushesAreAwaited()
[Fact]
public async Task QueuesIfFlushIsNotAwaited()
{
using (var slabPool = new SlabMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
using (var memoryPool = new PinnedBlockMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
{
var pipeWriterFlushTcsArray = new[] {
new TaskCompletionSource<FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
Expand Down Expand Up @@ -177,8 +177,8 @@ public async Task QueuesIfFlushIsNotAwaited()
[Fact]
public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance()
{
using (var slabPool = new SlabMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
using (var memoryPool = new PinnedBlockMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
{
var pipeWriterFlushTcsArray = new[] {
new TaskCompletionSource<FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -261,8 +261,8 @@ public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance()
[Fact]
public async Task CompleteFlushesQueuedBytes()
{
using (var slabPool = new SlabMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
using (var memoryPool = new PinnedBlockMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
{
var pipeWriterFlushTcsArray = new[] {
new TaskCompletionSource<FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
Expand Down Expand Up @@ -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);
Expand All @@ -329,8 +329,8 @@ public async Task CompleteFlushesQueuedBytes()
[Fact]
public async Task CancelPendingFlushInterruptsFlushLoop()
{
using (var slabPool = new SlabMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
using (var memoryPool = new PinnedBlockMemoryPool())
using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
{
var pipeWriterFlushTcsArray = new[] {
new TaskCompletionSource<FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
Expand Down Expand Up @@ -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<FlushResult>[] _flushResults;

Expand Down Expand Up @@ -440,7 +440,7 @@ public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellation
public override Memory<byte> GetMemory(int sizeHint = 0)
{
GetMemoryCallCount++;
return new Memory<byte>(new byte[sizeHint == 0 ? SlabMemoryPoolBlockSize : sizeHint]);
return new Memory<byte>(new byte[sizeHint == 0 ? PinnedBlockMemoryPoolBlockSize : sizeHint]);
}

public override Span<byte> GetSpan(int sizeHint = 0)
Expand Down
8 changes: 4 additions & 4 deletions src/Servers/Kestrel/Core/test/DiagnosticMemoryPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Internal.Test
{
public class DiagnosticMemoryPoolTests: MemoryPoolTests
{
protected override MemoryPool<byte> CreatePool() => new DiagnosticMemoryPool(new SlabMemoryPool());
protected override MemoryPool<byte> CreatePool() => new DiagnosticMemoryPool(new PinnedBlockMemoryPool());

[Fact]
public void DoubleDisposeThrows()
Expand Down Expand Up @@ -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();
Expand All @@ -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();

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/Http1ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/OutputProducerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OutputProducerTests : IDisposable

public OutputProducerTests()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Microsoft.Extensions.Internal.Test
{
public class SlabMemoryPoolTests: MemoryPoolTests
public class PinnedBlockMemoryPoolTests: MemoryPoolTests
{
protected override MemoryPool<byte> CreatePool() => new SlabMemoryPool();
protected override MemoryPool<byte> CreatePool() => new PinnedBlockMemoryPool();

[Fact]
public void DoubleDisposeWorks()
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/PipelineExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class PipelineExtensionTests : IDisposable
private const int _ulongMaxValueLength = 20;

private readonly Pipe _pipe;
private readonly MemoryPool<byte> _memoryPool = SlabMemoryPoolFactory.Create();
private readonly MemoryPool<byte> _memoryPool = PinnedBlockMemoryPoolFactory.Create();

public PipelineExtensionTests()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/StartLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/TestHelpers/TestInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UvStreamHandle, int, object> _readCallback =
(handle, status, state) => ReadCallback(handle, status, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create;
internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create;

private static int ProcessorThreadCount
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class LibuvOutputConsumerTests : IDisposable

public LibuvOutputConsumerTests()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
_mockLibuv = new MockLibuv();

var context = new TestLibuvTransportContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class QuicTransportOptions
/// </summary>
public long? MaxWriteBufferSize { get; set; } = 64 * 1024;

internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create;
internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public class SocketTransportOptions
/// </remarks>
public bool UnsafePreferInlineScheduling { get; set; }

internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.SlabMemoryPoolFactory.Create;
internal Func<MemoryPool<byte>> MemoryPoolFactory { get; set; } = System.Buffers.PinnedBlockMemoryPoolFactory.Create;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Http1LargeWritingBenchmark
[GlobalSetup]
public void GlobalSetup()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
_http1Connection = MakeHttp1Connection();
_consumeResponseBodyTask = ConsumeResponseBody();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Http1ReadingBenchmark
[GlobalSetup]
public void GlobalSetup()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
_http1Connection = MakeHttp1Connection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Http1WritingBenchmark
[GlobalSetup]
public void GlobalSetup()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
_http1Connection = MakeHttp1Connection();
_consumeResponseBodyTask = ConsumeResponseBody();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PipeThroughputBenchmark
[IterationSetup]
public void Setup()
{
_memoryPool = SlabMemoryPoolFactory.Create();
_memoryPool = PinnedBlockMemoryPoolFactory.Create();
_pipe = new Pipe(new PipeOptions(_memoryPool));
}

Expand Down
Loading