From 61dce1db4441be727a193311c895c70f9e52a189 Mon Sep 17 00:00:00 2001 From: Amarpreet Singh Date: Mon, 3 Jun 2024 15:20:24 -0400 Subject: [PATCH 1/2] Make sure that we only allocate 4k pages Co-authored-by: Tobi Ajila Signed-off-by: Amarpreet Singh --- port/common/omrmem32helpers.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/port/common/omrmem32helpers.c b/port/common/omrmem32helpers.c index 4dcad2be154..e7a969289ea 100644 --- a/port/common/omrmem32helpers.c +++ b/port/common/omrmem32helpers.c @@ -566,9 +566,11 @@ allocateVmemRegion32(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, J } /* use a minimum 4K page size */ - if (pageSize < 0x1000) { - pageSize = 0x1000; - } + // if (pageSize < 0x1000) { + // pageSize = 0x1000; + // } + /* Make sure that we only allocate 4k pages. */ + pageSize = 0x1000; #if defined(LINUX) if (OMR_ARE_ALL_BITS_SET(PPG_mem32BitFlags, OMRPORT_MEM_32BIT_FLAGS_TMP_FILE_BACKED_VMEM)) { From 6b1b092647b4f4236ca784e55c4fc5b1e01c0d9f Mon Sep 17 00:00:00 2001 From: Amarpreet Singh Date: Tue, 4 Jun 2024 14:48:55 -0400 Subject: [PATCH 2/2] 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)) {