Allow to retrieve the number of active bytes per PoolArena.
Motivation: To better understand how much memory is used by Netty for ByteBufs it is useful to understand how many bytes are currently active (allocated) per PoolArena. Modifications: - Add PoolArenaMetric.numActiveBytes() Result: The user is able to get better insight into the PooledByteBufAllocator.
This commit is contained in:
parent
c5b74afe58
commit
3a1eb6a149
@ -65,6 +65,7 @@ abstract class PoolArena<T> implements PoolArenaMetric {
|
|||||||
private final LongCounter allocationsTiny = PlatformDependent.newLongCounter();
|
private final LongCounter allocationsTiny = PlatformDependent.newLongCounter();
|
||||||
private final LongCounter allocationsSmall = PlatformDependent.newLongCounter();
|
private final LongCounter allocationsSmall = PlatformDependent.newLongCounter();
|
||||||
private final LongCounter allocationsHuge = PlatformDependent.newLongCounter();
|
private final LongCounter allocationsHuge = PlatformDependent.newLongCounter();
|
||||||
|
private final LongCounter activeBytesHuge = PlatformDependent.newLongCounter();
|
||||||
|
|
||||||
private long deallocationsTiny;
|
private long deallocationsTiny;
|
||||||
private long deallocationsSmall;
|
private long deallocationsSmall;
|
||||||
@ -242,13 +243,17 @@ abstract class PoolArena<T> implements PoolArenaMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void allocateHuge(PooledByteBuf<T> buf, int reqCapacity) {
|
private void allocateHuge(PooledByteBuf<T> buf, int reqCapacity) {
|
||||||
buf.initUnpooled(newUnpooledChunk(reqCapacity), reqCapacity);
|
PoolChunk<T> chunk = newUnpooledChunk(reqCapacity);
|
||||||
|
activeBytesHuge.add(chunk.chunkSize());
|
||||||
|
buf.initUnpooled(chunk, reqCapacity);
|
||||||
allocationsHuge.increment();
|
allocationsHuge.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(PoolChunk<T> chunk, long handle, int normCapacity, PoolThreadCache cache) {
|
void free(PoolChunk<T> chunk, long handle, int normCapacity, PoolThreadCache cache) {
|
||||||
if (chunk.unpooled) {
|
if (chunk.unpooled) {
|
||||||
|
int size = chunk.chunkSize();
|
||||||
destroyChunk(chunk);
|
destroyChunk(chunk);
|
||||||
|
activeBytesHuge.add(-size);
|
||||||
deallocationsHuge.decrement();
|
deallocationsHuge.decrement();
|
||||||
} else {
|
} else {
|
||||||
SizeClass sizeClass = sizeClass(normCapacity);
|
SizeClass sizeClass = sizeClass(normCapacity);
|
||||||
@ -537,6 +542,19 @@ abstract class PoolArena<T> implements PoolArenaMetric {
|
|||||||
return max(numHugeAllocations() - numHugeDeallocations(), 0);
|
return max(numHugeAllocations() - numHugeDeallocations(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long numActiveBytes() {
|
||||||
|
long val = activeBytesHuge.value();
|
||||||
|
synchronized (this) {
|
||||||
|
for (int i = 0; i < chunkListMetrics.size(); i++) {
|
||||||
|
for (PoolChunkMetric m: chunkListMetrics.get(i)) {
|
||||||
|
val += m.chunkSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max(0, val);
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract PoolChunk<T> newChunk(int pageSize, int maxOrder, int pageShifts, int chunkSize);
|
protected abstract PoolChunk<T> newChunk(int pageSize, int maxOrder, int pageShifts, int chunkSize);
|
||||||
protected abstract PoolChunk<T> newUnpooledChunk(int capacity);
|
protected abstract PoolChunk<T> newUnpooledChunk(int capacity);
|
||||||
protected abstract PooledByteBuf<T> newByteBuf(int maxCapacity);
|
protected abstract PooledByteBuf<T> newByteBuf(int maxCapacity);
|
||||||
|
@ -127,4 +127,9 @@ public interface PoolArenaMetric {
|
|||||||
* Return the number of currently active huge allocations.
|
* Return the number of currently active huge allocations.
|
||||||
*/
|
*/
|
||||||
long numActiveHugeAllocations();
|
long numActiveHugeAllocations();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of active bytes that are currently allocated by the arena.
|
||||||
|
*/
|
||||||
|
long numActiveBytes();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user