PoolThreadCache
PoolThreadCache 包含多种 MemoryRegionCache,缓存的
// 容量与 heapArena 一致
private final MemoryRegionCache<byte[]>[] smallSubPageHeapCaches;
// 容量与 directArena 一致
private final MemoryRegionCache<ByteBuffer>[] smallSubPageDirectCaches;
private final MemoryRegionCache<byte[]>[] normalHeapCaches;
private final MemoryRegionCache<ByteBuffer>[] normalDirectCaches;
1、PoolThreadCache 回收触发 MemoryRegionCache 的回收,MemoryRegionCache 的回收实际触发 PoolArena 的回收
2、PoolThreadCache 分配触发 MemoryRegionCache 的分配,最后触发在 smallSubPageHeapCaches、smallSubPageDirectCaches、normalHeapCaches、normalDirectCaches的分配。而 smallSubPageHeapCaches、smallSubPageDirectCaches、normalHeapCaches、normalDirectCaches 的主要区别在两个地方
1)是否是直接内存还是堆内存
2)不同规则。small 就比 normal 小
MemoryRegionCache
MemoryRegionCache 是一个队列,每个元素是 Entry,Entry 封装了 PoolChunk、ByteBuffer,Handle。
1、MemoryRegionCache 的分配是将 PoolArena 封装成 Entry 加入 Queue
2、MemoryRegionCache 的回收实际触发 PoolArena 的回收