From ce1870f3c73f82b844111de3e69e9a2e80e37f79 Mon Sep 17 00:00:00 2001 From: Amarpreet Singh Date: Tue, 4 Jun 2024 14:48:55 -0400 Subject: [PATCH] If no 4K pages, use smallest one as per omrvmem_startup Co-authored-by: Tobi Ajila Co-authored-by: Marius Pirvu Co-authored-by: Nathan Henderson Signed-off-by: Amarpreet Singh --- port/common/omrmem32helpers.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/port/common/omrmem32helpers.c b/port/common/omrmem32helpers.c index e7a969289ea..b139593e001 100644 --- a/port/common/omrmem32helpers.c +++ b/port/common/omrmem32helpers.c @@ -532,6 +532,7 @@ allocateVmemRegion32(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, J */ #if defined(OMR_PORT_CAN_RESERVE_SPECIFIC_ADDRESS) J9PortVmemIdentifier *vmemID = NULL; + uintptr_t *pageSizes = NULL; uintptr_t pageSize = 0; uintptr_t i = 0; J9HeapWrapper *wrapper = NULL; @@ -556,8 +557,10 @@ allocateVmemRegion32(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, J return NULL; } + pageSizes = portLibrary->vmem_supported_page_sizes(portLibrary); + /* get the default page size */ - pageSize = portLibrary->vmem_supported_page_sizes(portLibrary)[0]; + pageSize = pageSizes[0]; if (0 == pageSize) { Trc_PRT_mem_allocate_memory32_failed_page(callSite); portLibrary->mem_free_memory(portLibrary, vmemID); @@ -570,7 +573,15 @@ allocateVmemRegion32(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, J // pageSize = 0x1000; // } /* Make sure that we only allocate 4k pages. */ - pageSize = 0x1000; + // pageSize = 0x1000; + /* If 4K is not the default page size, then look for the smallest one as per omrvmem_startup. */ + if (0x1000 != pageSize) { + for (i = 0 ; pageSizes[i] != 0 ; i++) { + if (pageSize > pageSizes[i]) { + pageSize = pageSizes[i]; + } + } + } #if defined(LINUX) if (OMR_ARE_ALL_BITS_SET(PPG_mem32BitFlags, OMRPORT_MEM_32BIT_FLAGS_TMP_FILE_BACKED_VMEM)) {