新TLAB中的分配与TLAB之外的分配 [英] Allocations in new TLAB vs allocations outside TLAB

查看:749
本文介绍了新TLAB中的分配与TLAB之外的分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JDK中的Java Mission Control工具提供有关新TLAB中的对象分配和TLAB外部分配的统计信息。 (它在内存/分配下)。这些统计数据的意义是什么,对于应用程序的性能有什么好处?我应该担心一些对象是否被分配到TLAB之外,如果是的话,我该怎么处理它?<​​b> 解析方案

一个线程本地分配缓冲区。在HotSpot中分配正常方式的对象在TLAB中。因为分配缓冲区是线程本地的,所以只有在获取新的TLAB时才需要同步。

因此,理想的场景是尽可能多的分配在TLAB中完成。



一些对象将被分配在TLAB之外,例如大对象。这是没有什么可担心的,只要TLAB之外的分配百分比与新TLAB中的分配百分比较低即可。



TLAB在每个线程的执行过程中都会动态调整大小。所以,如果一个线程分配非常多,它从堆中获得的新TLAB将会增加。如果你想要,你可以设置标志 -XX:MinTLABSize 来设置最小TLAB大小,例如
-XX:MinTLABSize = 4k



我的同事David Lindholm提供的答案:


The Java Mission Control tool in the JDK provides statistics about object allocation in new TLAB and allocations outside TLAB. (It's under Memory/Allocations). What is the significance of these statistics, what is good for the performance of an application? Should I be worried if some objects are allocated outside TLAB and if yes, what can I do about it?

解决方案

A TLAB is a Thread Local Allocation Buffer. The normal way objects are allocated in HotSpot is within a TLAB. TLAB allocations can be done without synchronization with other threads, since the Allocation Buffer is Thread Local, synchronization is only needed when a new TLAB is fetched.

So, the ideal scenario is that as much as possible of the allocations are done in TLABs.

Some objects will be allocated outside TLABs, for example large objects. This is nothing to worry about as long as the percentage of allocations outside TLABs vs allocations in new TLABs is low.

The TLABs are dynamically resized during the execution for each thread individually. So, if a thread allocates very much, the new TLABs that it gets from the heap will increase in size. If you want you can try to set the flag -XX:MinTLABSize to set minimum TLAB size, for example -XX:MinTLABSize=4k

Answer provided by my colleague David Lindholm :)

这篇关于新TLAB中的分配与TLAB之外的分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆