Smarter unpinning of MemoryPoolBlock2 in SocketOutput

This commit is contained in:
Stephen Halter 2015-11-20 12:59:53 -08:00
parent 2572256d3f
commit 0dbf108353
3 changed files with 13 additions and 7 deletions

View File

@ -305,12 +305,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
var returnBlock = block;
block = block.Next;
returnBlock.Unpin();
returnBlock.Pool?.Return(returnBlock);
}
_tail.Unpin();
if (_isProducing)
{
_returnFromOnProducingComplete = _tail;
@ -381,6 +378,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
var writeReq = new UvWriteReq(Self._log);
writeReq.Init(Self._thread.Loop);
writeReq.Write(Self._socket, _lockedStart, _lockedEnd, _bufferCount, (_writeReq, status, error, state) =>
{
_writeReq.Dispose();
@ -453,6 +451,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
returnBlock.Unpin();
returnBlock.Pool?.Return(returnBlock);
}
_lockedEnd.Block.Unpin();
}
private void LockWrite()

View File

@ -105,15 +105,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
/// <returns></returns>
public IntPtr Pin()
{
Debug.Assert(!_pinHandle.IsAllocated);
if (_dataArrayPtr != IntPtr.Zero)
{
// this is a slab managed block - use the native address of the slab which is always locked
return _dataArrayPtr;
}
else if (_pinHandle.IsAllocated)
{
return _pinHandle.AddrOfPinnedObject();
}
else
{
// this is one-time-use memory - lock the managed memory until Unpin is called

View File

@ -85,6 +85,14 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
_callback = null;
_state = null;
Unpin(this);
var block = start.Block;
for (var index = 0; index < nBuffers; index++)
{
block.Unpin();
block = block.Next;
}
throw;
}
}