Netty multi-threaded local implementation principle

PoolThreadCache

PoolThreadCache contains a variety of MemoryRegionCache, cached

    // 容量与 heapArena 一致
    private final MemoryRegionCache<byte[]>[] smallSubPageHeapCaches;
    // 容量与 directArena 一致
    private final MemoryRegionCache<ByteBuffer>[] smallSubPageDirectCaches;
    private final MemoryRegionCache<byte[]>[] normalHeapCaches;
    private final MemoryRegionCache<ByteBuffer>[] normalDirectCaches;

1. The recycling of PoolThreadCache triggers the recycling of MemoryRegionCache, and the recycling of MemoryRegionCache actually triggers the recycling of PoolArena.
2. The allocation of PoolThreadCache triggers the allocation of MemoryRegionCache, and finally triggers the allocation of smallSubPageHeapCaches, smallSubPageDirectCaches, normalHeapCaches, and normalDirectCaches. The main difference between smallSubPageHeapCaches, smallSubPageDirectCaches, normalHeapCaches, and normalDirectCaches lies in two places
: 1) Whether it is direct memory or heap memory
; 2) Different rules. small is smaller than normal

MemoryRegionCache

MemoryRegionCache is a queue, each element is Entry, and Entry encapsulates PoolChunk, ByteBuffer, and Handle.
1. The allocation of MemoryRegionCache is to encapsulate PoolArena into Entry and add it to Queue.
2. The recycling of MemoryRegionCache actually triggers the recycling of PoolArena

Guess you like

Origin blog.csdn.net/wenxueliu/article/details/130695275