From 4c79e7d59caec01b4d2bdae2f7d25f1dd24ffbf6 Mon Sep 17 00:00:00 2001 From: Ivan Walulya Date: Thu, 12 Oct 2023 10:28:52 +0000 Subject: [PATCH] 8170817: G1: Returning MinTLABSize from unsafe_max_tlab_alloc causes TLAB flapping Reviewed-by: tschatzl, ayang --- src/hotspot/share/gc/g1/g1Allocator.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1Allocator.cpp b/src/hotspot/share/gc/g1/g1Allocator.cpp index cf44b68fc86..ffd2b65f555 100644 --- a/src/hotspot/share/gc/g1/g1Allocator.cpp +++ b/src/hotspot/share/gc/g1/g1Allocator.cpp @@ -191,11 +191,14 @@ size_t G1Allocator::unsafe_max_tlab_alloc() { uint node_index = current_node_index(); HeapRegion* hr = mutator_alloc_region(node_index)->get(); size_t max_tlab = _g1h->max_tlab_size() * wordSize; - if (hr == nullptr) { + + if (hr == nullptr || hr->free() < MinTLABSize) { + // The next TLAB allocation will most probably happen in a new region, + // therefore we can attempt to allocate the maximum allowed TLAB size. return max_tlab; - } else { - return clamp(hr->free(), MinTLABSize, max_tlab); } + + return MIN2(hr->free(), max_tlab); } size_t G1Allocator::used_in_alloc_regions() {