From 4c2f1099489b917a15b292d8e1cf444ede4826eb Mon Sep 17 00:00:00 2001 From: Aleksandar Micic Date: Mon, 29 Jul 2024 16:02:55 -0400 Subject: [PATCH] Increase max TLH for non-batch clear platforms For non-batch TLH clear platform (currently only those based on X h/w) the maximum size is increased to 1MB (from 128K default set by OMR). This allows better scaling on high allocating/high CPU count configurations. Batch clearing platforms stays at 128K max, since clearing too much in a batch may flush useful data from CPU data caches. Signed-off-by: Aleksandar Micic --- runtime/gc_base/GCExtensions.cpp | 4 ++++ runtime/gc_base/GCExtensions.hpp | 9 +++++++++ runtime/gc_modron_startup/mmhelpers.cpp | 11 ++++++++++- runtime/gc_modron_startup/mmparseXgc.cpp | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/runtime/gc_base/GCExtensions.cpp b/runtime/gc_base/GCExtensions.cpp index 33a653ca457..43e00588527 100644 --- a/runtime/gc_base/GCExtensions.cpp +++ b/runtime/gc_base/GCExtensions.cpp @@ -103,6 +103,10 @@ MM_GCExtensions::initialize(MM_EnvironmentBase *env) getJavaVM()->jniArrayCacheMaxSize = J9_GC_JNI_ARRAY_CACHE_SIZE; #endif /* J9VM_GC_JNI_ARRAY_CACHE */ + /* We increase default max TLH size from OMR default value to allow non-batch clear TLH platforms to benefit from it. + * Platforms that use batch clearing (see batchClearTLH) will override later this with a smaller value */ + tlhMaximumSize = J9_MAXIMUM_TLH_SIZE; + #if defined(J9VM_GC_THREAD_LOCAL_HEAP) getJavaVM()->gcInfo.tlhThreshold = J9_GC_TLH_THRESHOLD; getJavaVM()->gcInfo.tlhSize = J9_GC_TLH_SIZE; diff --git a/runtime/gc_base/GCExtensions.hpp b/runtime/gc_base/GCExtensions.hpp index ae5bd4fe90d..75b7b4342b4 100644 --- a/runtime/gc_base/GCExtensions.hpp +++ b/runtime/gc_base/GCExtensions.hpp @@ -81,6 +81,12 @@ class MM_IdleGCManager; #define MINIMUM_SURVIVOR_MINIMUM_FREESIZE 512 #define MINIMUM_SURVIVOR_THRESHOLD 512 + +#define J9_MAXIMUM_TLH_SIZE (1024 * 1024) +#if defined(J9VM_GC_BATCH_CLEAR_TLH) +#define J9_MAXIMUM_TLH_SIZE_BATCH_CLEAR (128 * 1024) +#endif /* defined(J9VM_GC_BATCH_CLEAR_TLH) */ + /** * @todo Provide class documentation * @ingroup GC_Base @@ -193,6 +199,8 @@ class MM_GCExtensions : public MM_GCExtensionsBase { UserSpecifiedParameters userSpecifiedParameters; /**< A collection of user-speicifed parameters */ + bool tlhMaximumSizeSpecified; /**< true, if tlhMaximumSize specified by a command line option */ + bool dynamicHeapAdjustmentForRestore; /**< If set to true, the default heuristic-calculated softmx is prioritized over the user-specified values. */ /** * Values for com.ibm.oti.vm.VM.J9_JIT_STRING_DEDUP_POLICY @@ -417,6 +425,7 @@ class MM_GCExtensions : public MM_GCExtensionsBase { , objectListFragmentCount(0) , numaCommonThreadClassNamePatterns(NULL) , userSpecifiedParameters() + , tlhMaximumSizeSpecified(false) , dynamicHeapAdjustmentForRestore(false) , stringDedupPolicy(J9_JIT_STRING_DEDUP_POLICY_UNDEFINED) , _asyncCallbackKey(-1) diff --git a/runtime/gc_modron_startup/mmhelpers.cpp b/runtime/gc_modron_startup/mmhelpers.cpp index 12ac9c5e4f9..b6e9c66c93d 100644 --- a/runtime/gc_modron_startup/mmhelpers.cpp +++ b/runtime/gc_modron_startup/mmhelpers.cpp @@ -63,7 +63,16 @@ extern void initializeVerboseFunctionTableWithDummies(J9MemoryManagerVerboseInte void allocateZeroedTLHPages(J9JavaVM *javaVM, UDATA flag) { - MM_GCExtensions::getExtensions(javaVM)->batchClearTLH = (flag != 0) ? 1 : 0; + MM_GCExtensions *ext = MM_GCExtensions::getExtensions(javaVM); + + ext->batchClearTLH = (flag != 0) ? 1 : 0; + + /* For batch clearing limit maximum size (since clearing too much may flush useful data from CPU data caches). + * Apply the limit only if user did not specify another value. + */ + if (ext->batchClearTLH && !ext->tlhMaximumSizeSpecified) { + ext->tlhMaximumSize = OMR_MIN(J9_MAXIMUM_TLH_SIZE_BATCH_CLEAR, ext->tlhMaximumSize); + } } /** diff --git a/runtime/gc_modron_startup/mmparseXgc.cpp b/runtime/gc_modron_startup/mmparseXgc.cpp index f2c23c20765..88456ce02bd 100644 --- a/runtime/gc_modron_startup/mmparseXgc.cpp +++ b/runtime/gc_modron_startup/mmparseXgc.cpp @@ -73,6 +73,7 @@ j9gc_initialize_parse_gc_colon(J9JavaVM *javaVM, char **scan_start) if(!scan_udata_helper(javaVM, scan_start, &extensions->tlhMaximumSize, "tlhMaximumSize=")) { goto _error; } + extensions->tlhMaximumSizeSpecified = true; goto _exit; } if(try_scan(scan_start, "tlhIncrementSize=")) {