Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a TLAB (Thread Local Allocation Buffer)?

I couldn't find a comprehensive source that would explain the concept in a clear manner. My understanding is that a thread is given some chunk of memory in the eden where it allocates new objects. A competing thread will end up having a somewhat consecutive chunk of eden. What happens if the first thread runs out of free area in its TLAB? Would it request a new chunk of eden?

like image 960
user1745356 Avatar asked May 02 '17 21:05

user1745356


1 Answers

The idea of a TLAB is to reduce the need of synchronization between threads. Using TLABs, this need is reduced as any thread has an area it can use and expect that it is the only thread using this area. Assuming that a TLAB can hold 100 objects, a thread would only need to aquire a lock for claiming more memory when allocating the 101 object. Without TLABs, this would be required for every object. The downside is of course that you potentially waste space.

Large objects are typically allocated outside of a TLAB as they void the advantage of reducing the frequency of synchronized memory allocation. Some objects might not even fit inside of a TLAB.

You can set the size of a TLAB using the -XX:TLABSize flag but generally I do not recommend you to mess with these settings unless you really discovered a problem that you can solve by that.

like image 196
Rafael Winterhalter Avatar answered Oct 02 '22 19:10

Rafael Winterhalter