Package io.netty.buffer
Class PoolThreadCache
java.lang.Object
io.netty.buffer.PoolThreadCache
Acts a Thread cache for allocations. This implementation is moduled after
jemalloc and the descripted
technics of
Scalable memory allocation using jemalloc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static class
private static final class
Cache used for buffers which are backed by NORMAL size.private static final class
Cache used for buffers which are backed by TINY or SMALL size. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
(package private) final PoolArena
<ByteBuffer> private final AtomicBoolean
private final PoolThreadCache.FreeOnFinalize
private final int
(package private) final PoolArena
<byte[]> private static final int
private static final InternalLogger
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[]
private final PoolThreadCache.MemoryRegionCache<byte[]>[]
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[]
private final PoolThreadCache.MemoryRegionCache<byte[]>[]
-
Constructor Summary
ConstructorsConstructorDescriptionPoolThreadCache
(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold, boolean useFinalizer) -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
add
(PoolArena<?> area, PoolChunk chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass) AddPoolChunk
andhandle
to the cache if there is enough room.private boolean
allocate
(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity) (package private) boolean
allocateNormal
(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx) Try to allocate a normal buffer out of the cache.(package private) boolean
allocateSmall
(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx) Try to allocate a small buffer out of the cache.private PoolThreadCache.MemoryRegionCache
<?> cache
(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass) private static <T> PoolThreadCache.MemoryRegionCache
<T> cache
(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx) private PoolThreadCache.MemoryRegionCache
<?> cacheForNormal
(PoolArena<?> area, int sizeIdx) private PoolThreadCache.MemoryRegionCache
<?> cacheForSmall
(PoolArena<?> area, int sizeIdx) private static void
checkCacheMayLeak
(PoolThreadCache.MemoryRegionCache<?>[] caches, String type) private static <T> PoolThreadCache.MemoryRegionCache<T>[]
createNormalCaches
(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area) private static <T> PoolThreadCache.MemoryRegionCache<T>[]
createSubPageCaches
(int cacheSize, int numCaches) (package private) void
free
(boolean finalizer) Should be called if the Thread that uses this cache is about to exist to release resources out of the cacheprivate static int
free
(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer) private static int
free
(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer) (package private) static int
log2
(int val) (package private) void
trim()
private static void
trim
(PoolThreadCache.MemoryRegionCache<?> cache) private static void
trim
(PoolThreadCache.MemoryRegionCache<?>[] caches)
-
Field Details
-
logger
-
INTEGER_SIZE_MINUS_ONE
private static final int INTEGER_SIZE_MINUS_ONE- See Also:
-
heapArena
-
directArena
-
smallSubPageHeapCaches
-
smallSubPageDirectCaches
-
normalHeapCaches
-
normalDirectCaches
-
freeSweepAllocationThreshold
private final int freeSweepAllocationThreshold -
freed
-
freeOnFinalize
-
allocations
private int allocations
-
-
Constructor Details
-
PoolThreadCache
PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold, boolean useFinalizer)
-
-
Method Details
-
createSubPageCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createSubPageCaches(int cacheSize, int numCaches) -
createNormalCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area) -
log2
static int log2(int val) -
allocateSmall
Try to allocate a small buffer out of the cache. Returnstrue
if successfulfalse
otherwise -
allocateNormal
Try to allocate a normal buffer out of the cache. Returnstrue
if successfulfalse
otherwise -
allocate
private boolean allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity) -
add
boolean add(PoolArena<?> area, PoolChunk chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass) AddPoolChunk
andhandle
to the cache if there is enough room. Returnstrue
if it fit into the cachefalse
otherwise. -
cache
private PoolThreadCache.MemoryRegionCache<?> cache(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass) -
free
void free(boolean finalizer) Should be called if the Thread that uses this cache is about to exist to release resources out of the cache -
checkCacheMayLeak
-
free
-
free
-
trim
void trim() -
trim
-
trim
-
cacheForSmall
-
cacheForNormal
-
cache
private static <T> PoolThreadCache.MemoryRegionCache<T> cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx)
-