从零开始实现简易版Netty(九) MyNetty 实现池化内存的线程本地缓存

在lab7、lab8的实现中可以发现,出于空间利用率的考虑,一个PoolArena会同时被多个线程并发访问。因此无论是Normal还是Small规格的池化内存分配,Netty在进行实际的池化内存分配时都或多或少的需要使用互斥锁来确保用于追踪池化内存状态的元数据PoolArena、PoolSubPage等不会被并发的更新而出现问题。

jemalloc的论文中提到,内存分配作为一个高频的操作需要尽可能的减少线程的同步竞争以提高效率,大量线程都阻塞在同步锁上会大大降低内存分配的整体吞吐率,通过引入线程本地缓存可以显著减少同步竞争的频率。


“The main goal of thread caches is to reduce the volume of synchronization events.”


“Minimize lock contention. jemalloc’s independent arenas were inspired by lkmalloc, but as time went on, tcmalloc made it abundantly clear that it’s even better to avoid synchronization altogether, so jemalloc also implements thread-specific caching.”

赞(0)
未经允许不得转载:小狮博客 » 从零开始实现简易版Netty(九) MyNetty 实现池化内存的线程本地缓存
分享到: 更多 (0)

联系我们