From 5a0d0daed3e4e815e7a69a54ed5fdd0ca8b2eec1 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 5 Apr 2016 11:46:25 +0200 Subject: [PATCH] Only increment metric for huge / normal allocations after the allocation was really done. Motivation: We should only increment the metric for the huge / normal allocation after it is done. Also we should only decrement once deallocate. Modifications: - Move increment after the allocation. - Fix deallocation metric and move it after deallocation Result: More correct metrics. --- buffer/src/main/java/io/netty/buffer/PoolArena.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PoolArena.java b/buffer/src/main/java/io/netty/buffer/PoolArena.java index 1e0db7c8b3..6899a6a912 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolArena.java +++ b/buffer/src/main/java/io/netty/buffer/PoolArena.java @@ -223,30 +223,31 @@ abstract class PoolArena implements PoolArenaMetric { } private synchronized void allocateNormal(PooledByteBuf buf, int reqCapacity, int normCapacity) { - ++allocationsNormal; if (q050.allocate(buf, reqCapacity, normCapacity) || q025.allocate(buf, reqCapacity, normCapacity) || q000.allocate(buf, reqCapacity, normCapacity) || qInit.allocate(buf, reqCapacity, normCapacity) || q075.allocate(buf, reqCapacity, normCapacity) || q100.allocate(buf, reqCapacity, normCapacity)) { + ++allocationsNormal; return; } // Add a new chunk. PoolChunk c = newChunk(pageSize, maxOrder, pageShifts, chunkSize); long handle = c.allocate(normCapacity); + ++allocationsNormal; assert handle > 0; c.initBuf(buf, handle, reqCapacity); qInit.add(c); } private void allocateHuge(PooledByteBuf buf, int reqCapacity) { - allocationsHuge.increment(); buf.initUnpooled(newUnpooledChunk(reqCapacity), reqCapacity); + allocationsHuge.increment(); } void free(PoolChunk chunk, long handle, int normCapacity, PoolThreadCache cache) { if (chunk.unpooled) { - allocationsHuge.decrement(); destroyChunk(chunk); + deallocationsHuge.decrement(); } else { SizeClass sizeClass = sizeClass(normCapacity); if (cache != null && cache.add(this, chunk, handle, normCapacity, sizeClass)) {