From d14afe88a434d278d9492a4c092801601656da8b Mon Sep 17 00:00:00 2001 From: garywu Date: Mon, 13 Apr 2015 13:41:25 +0800 Subject: [PATCH] [#2925] Bug fix for NormalMemoryRegionCache overbooked for PoolThreadCache Motivation: When create NormalMemoryRegionCache for PoolThreadCache, we overbooked cache array size. This means unnecessary overhead for thread local cache as we will create multi cache enties for each element in cache array. Modifications: change: int arraySize = Math.max(1, max / area.pageSize); to: int arraySize = Math.max(1, log2(max / area.pageSize) + 1); Result: Now arraySize won't introduce unnecessary overhead. Changes to be committed: modified: buffer/src/main/java/io/netty/buffer/PoolThreadCache.java --- buffer/src/main/java/io/netty/buffer/PoolThreadCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buffer/src/main/java/io/netty/buffer/PoolThreadCache.java b/buffer/src/main/java/io/netty/buffer/PoolThreadCache.java index 755f1573ed..fbcfaafffb 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolThreadCache.java +++ b/buffer/src/main/java/io/netty/buffer/PoolThreadCache.java @@ -129,7 +129,7 @@ final class PoolThreadCache { int cacheSize, int maxCachedBufferCapacity, PoolArena area) { if (cacheSize > 0) { int max = Math.min(area.chunkSize, maxCachedBufferCapacity); - int arraySize = Math.max(1, max / area.pageSize); + int arraySize = Math.max(1, log2(max / area.pageSize) + 1); @SuppressWarnings("unchecked") NormalMemoryRegionCache[] cache = new NormalMemoryRegionCache[arraySize];