Skip to content

Commit 992e4e3

Browse files
committed
Rename used counter
1 parent d991f44 commit 992e4e3

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/Servers/Connections.Abstractions/src/MemoryPoolOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Connections;
66
/// <summary>
77
/// Options for configuring a memory pool.
88
/// </summary>
9-
public sealed class MemoryPoolOptions
9+
public class MemoryPoolOptions
1010
{
1111
/// <summary>
1212
/// Gets or sets the owner of the memory pool. This is used for logging and diagnostics purposes.

src/Servers/Kestrel/Core/test/PinnedBlockMemoryPoolFactoryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void CreatePool()
2020
var pool = factory.Create();
2121
Assert.NotNull(pool);
2222
Assert.IsType<PinnedBlockMemoryPool>(pool);
23+
Assert.Null(Assert.IsType<PinnedBlockMemoryPool>(pool).Owner);
2324
}
2425

2526
[Fact]

src/Shared/Buffers.MemoryPool/MemoryPoolMetrics.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ internal sealed class MemoryPoolMetrics
1212
{
1313
public const string MeterName = "Microsoft.AspNetCore.MemoryPool";
1414

15-
public const string UsedMemoryName = "aspnetcore.memory_pool.used";
15+
public const string PooledMemoryName = "aspnetcore.memory_pool.pooled";
1616
public const string AllocatedMemoryName = "aspnetcore.memory_pool.allocated";
1717
public const string EvictedMemoryName = "aspnetcore.memory_pool.evicted";
1818
public const string RentedMemoryName = "aspnetcore.memory_pool.rented";
1919

2020
private readonly Meter _meter;
21-
private readonly UpDownCounter<long> _usedMemoryCounter;
21+
private readonly UpDownCounter<long> _pooledMemoryCounter;
2222
private readonly Counter<long> _allocatedMemoryCounter;
2323
private readonly Counter<long> _evictedMemoryCounter;
2424
private readonly Counter<long> _rentedMemoryCounter;
@@ -27,41 +27,41 @@ public MemoryPoolMetrics(IMeterFactory meterFactory)
2727
{
2828
_meter = meterFactory.Create(MeterName);
2929

30-
_usedMemoryCounter = _meter.CreateUpDownCounter<long>(
31-
UsedMemoryName,
30+
_pooledMemoryCounter = _meter.CreateUpDownCounter<long>(
31+
PooledMemoryName,
3232
unit: "By",
33-
description: "Number of bytes that are currently used by the pool.");
33+
description: "Number of bytes currently held by the memory pool and available for reuse.");
3434

3535
_allocatedMemoryCounter = _meter.CreateCounter<long>(
36-
AllocatedMemoryName,
36+
AllocatedMemoryName,
3737
unit: "By",
38-
description: "Total number of allocations made by the pool.");
38+
description: "Total number of allocations made by the memory pool.");
3939

4040
_evictedMemoryCounter = _meter.CreateCounter<long>(
41-
EvictedMemoryName,
41+
EvictedMemoryName,
4242
unit: "By",
43-
description: "Total number of bytes that have been evicted from the pool.");
43+
description: "Total number of bytes that have been evicted from the memory pool.");
4444

4545
_rentedMemoryCounter = _meter.CreateCounter<long>(
4646
RentedMemoryName,
4747
unit: "By",
48-
description: "Total number of bytes rented from the pool.");
48+
description: "Total number of bytes rented from the memory pool.");
4949
}
5050

51-
public void UpdateUsedMemory(int bytes, string? owner)
51+
public void UpdatePooledMemory(int bytes, string? owner)
5252
{
53-
if (_usedMemoryCounter.Enabled)
53+
if (_pooledMemoryCounter.Enabled)
5454
{
55-
UpdateUsedMemoryCore(bytes, owner);
55+
UpdatePooledMemoryCore(bytes, owner);
5656
}
5757
}
5858

59-
private void UpdateUsedMemoryCore(int bytes, string? owner)
59+
private void UpdatePooledMemoryCore(int bytes, string? owner)
6060
{
6161
var tags = new TagList();
6262
AddOwner(ref tags, owner);
6363

64-
_usedMemoryCounter.Add(bytes, tags);
64+
_pooledMemoryCounter.Add(bytes, tags);
6565
}
6666

6767
public void AddAllocatedMemory(int bytes, string? owner)

src/Shared/Buffers.MemoryPool/PinnedBlockMemoryPool.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal sealed class PinnedBlockMemoryPool : MemoryPool<byte>, IThreadPoolWorkI
6363
private object? _onPoolDisposedState;
6464

6565
// Internal for tests.
66-
internal string Owner => _owner;
66+
internal string? Owner => _owner;
6767

6868
/// <summary>
6969
/// This default value passed in to Rent to use the default value for the pool.
@@ -102,7 +102,7 @@ public override IMemoryOwner<byte> Rent(int size = AnySize)
102102

103103
if (_blocks.TryDequeue(out var block))
104104
{
105-
_metrics?.UpdateUsedMemory(-block.Memory.Length, _owner);
105+
_metrics?.UpdatePooledMemory(-block.Memory.Length, _owner);
106106
_metrics?.AddRentedMemory(block.Memory.Length, _owner);
107107

108108
// block successfully taken from the stack - return it
@@ -131,16 +131,16 @@ public override IMemoryOwner<byte> Rent(int size = AnySize)
131131
internal void Return(MemoryPoolBlock block)
132132
{
133133
#if BLOCK_LEASE_TRACKING
134-
Debug.Assert(block.Pool == this, "Returned block was not leased from this pool");
135-
Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}");
136-
block.IsLeased = false;
134+
Debug.Assert(block.Pool == this, "Returned block was not leased from this pool");
135+
Debug.Assert(block.IsLeased, $"Block being returned to pool twice: {block.Leaser}{Environment.NewLine}");
136+
block.IsLeased = false;
137137
#endif
138138

139139
Interlocked.Increment(ref _returnCount);
140140

141141
if (!_isDisposed)
142142
{
143-
_metrics?.UpdateUsedMemory(block.Memory.Length, _owner);
143+
_metrics?.UpdatePooledMemory(block.Memory.Length, _owner);
144144

145145
_blocks.Enqueue(block);
146146
}
@@ -214,7 +214,7 @@ internal void PerformEviction()
214214
// Remove from queue and let GC clean the memory up
215215
while (burstAmount > 0 && _blocks.TryDequeue(out var block))
216216
{
217-
_metrics?.UpdateUsedMemory(-block.Memory.Length, _owner);
217+
_metrics?.UpdatePooledMemory(-block.Memory.Length, _owner);
218218
_metrics?.AddEvictedMemory(block.Memory.Length, _owner);
219219

220220
burstAmount--;

0 commit comments

Comments
 (0)