From 040228e18703d8629c3cc1c905778aeee13cb401 Mon Sep 17 00:00:00 2001 From: SajinaKandy Date: Tue, 24 Oct 2023 18:33:56 -0700 Subject: [PATCH] Fix code cache allocation with large pages enabled When large pages/huge pages are enabled and page size >= 1GB, code cache size is rounded up to the page size. When codecachetotal is lesser than the page size, this can make the size of code cache segment bigger than the total code cache size. In this case, page size should be recalculated to a smaller value. Also a warning message should be printed in the verbose output. Closes: ##18274 Signed-off-by: SajinaKandy --- runtime/compiler/runtime/J9CodeCacheManager.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/runtime/compiler/runtime/J9CodeCacheManager.cpp b/runtime/compiler/runtime/J9CodeCacheManager.cpp index 370ee352fb9..ca4ff7c29ee 100644 --- a/runtime/compiler/runtime/J9CodeCacheManager.cpp +++ b/runtime/compiler/runtime/J9CodeCacheManager.cpp @@ -286,6 +286,8 @@ J9::CodeCacheManager::allocateCodeCacheSegment(size_t segmentSize, TR::CodeCacheConfig &config = self()->codeCacheConfig(); + UDATA ccTotalSizeB = config.codeCacheTotalKB() << 10; + size_t largeCodePageSize = config.largeCodePageSize(); #if defined(TR_TARGET_POWER) && defined(TR_HOST_POWER) /* Use largeCodePageSize on PPC only if its 16M. @@ -298,6 +300,19 @@ J9::CodeCacheManager::allocateCodeCacheSegment(size_t segmentSize, { vmemParams.pageSize = largeCodePageSize; vmemParams.pageFlags = config.largeCodePageFlags(); + + // Recalculate the page size if using large pages + UDATA *pageSizes = j9vmem_supported_page_sizes(); + if(vmemParams.pageSize > ccTotalSizeB) + { + for (UDATA pageIndex = 0; 0 != pageSizes[pageIndex]; ++pageIndex) + { + if(pageSizes[pageIndex] <= ccTotalSizeB) + vmemParams.pageSize = pageSizes[pageIndex]; + } + if (config.verboseCodeCache() || config.verbosePerformance()) + TR_VerboseLog::writeLineLocked(TR_Vlog_CODECACHE,"Warning: Using page size %zu instead of large page size %zu", (size_t)vmemParams.pageSize, largeCodePageSize); + } } UDATA mode = J9PORT_VMEM_MEMORY_MODE_READ |