Project Loom technical questions

Ignaz Birnstingl ignazb at gmail.com
Sat Jul 31 15:25:06 UTC 2021


Hi Ron,

Thanks for replying!
Questions 2. and 3. are answered.

>> The default stack size for platform threads in Java is 1 MB on Linux  
>> and Mac. Kernel threads cannot resize
>> their stack because they do not know how it’s used by the language;  
>> user-mode threads can. Loom’s virtual
>> threads automatically grow and shrink depending on how much stack is  
>> currently used. TLABs are unrelated,
>> and are associated with the OS threads internally used by the Java  
>> runtime rather than with virtual threads.
If your process starts a million threads then for each thread 1 MB of  
stack would be reserved in its address space. Since address space in 64  
bit applications is big enough that should not be a problem.
But since the memory would initially not be used this would not contribute  
to the process' RSS. Or at least it should not. So it should not  
contribute to the "memory usage" which is considered for memory limits in  
container environments.
Therefore I would argue that the memory usage for stacks should be roughly  
the same for kernel threads and virtual threads.

Having one million TLABs would certainly have more memory overhead than -  
say - 8. That is where I see the biggest benefit of using virtual threads.
But this problem could theoretically be mitigated with core-local  
allocation buffers: Instead of having allocation buffers per kernel thread  
these would have to be per CPU core. Of course that would mean that  
special care would have to be taken by the JVM if/when a thread gets moved  
to a different CPU core.

-- 
Ignaz


More information about the loom-dev mailing list