7373#include "caml/io.h"
7474#include "caml/alloc.h"
7575#include "caml/platform.h"
76+ #include "caml/startup_aux.h"
7677
7778#ifndef S_ISREG
7879#define S_ISREG (mode ) (((mode) & S_IFMT) == S_IFREG)
@@ -536,9 +537,11 @@ static void* mmap_named(void* addr, size_t length, int prot, int flags,
536537}
537538#endif
538539
539- void * caml_plat_mem_map (uintnat size , int reserve_only , const char * name )
540+ void * caml_plat_mem_map (uintnat size , uintnat caml_flags , const char * name )
540541{
541542 uintnat alignment = caml_plat_hugepagesize ;
543+ uintnat reserve_only = caml_flags & CAML_MAP_RESERVE_ONLY ;
544+ uintnat no_hugetlb = caml_flags & CAML_MAP_NO_HUGETLB ;
542545#ifdef WITH_ADDRESS_SANITIZER
543546 return aligned_alloc (alignment , (size + (alignment - 1 )) & ~(alignment - 1 ));
544547#else
@@ -555,6 +558,15 @@ void *caml_plat_mem_map(uintnat size, int reserve_only, const char* name)
555558 return mem ;
556559 }
557560
561+ #ifdef HAS_HUGE_PAGES
562+ if (caml_params -> use_hugetlb_pages && !reserve_only && !no_hugetlb ) {
563+ /* If requested, try mapping with MAP_HUGETLB */
564+ mem = mmap_named (0 , size , prot , flags | MAP_HUGETLB , -1 , 0 , name );
565+ if (mem == MAP_FAILED ) mem = NULL ;
566+ return mem ;
567+ }
568+ #endif
569+
558570 /* Sensible kernels (on Linux, that means >= 6.7) will always provide aligned
559571 mappings. To avoid penalising such kernels, try mapping the exact desired
560572 size first and see if it happens to be aligned. */
@@ -599,9 +611,10 @@ static void* map_fixed(void* mem, uintnat size, int prot, const char* name)
599611 done using mprotect, since Cygwin's mmap doesn't implement the required
600612 functions for committing using mmap. */
601613
602- void * caml_plat_mem_map (uintnat size , int reserve_only , const char * name )
614+ void * caml_plat_mem_map (uintnat size , uintnat flags , const char * name )
603615{
604616 void * mem ;
617+ uintnat reserve_only = flags & CAML_MAP_RESERVE_ONLY ;
605618
606619 mem = mmap (0 , size , reserve_only ? PROT_NONE : (PROT_READ | PROT_WRITE ),
607620 MAP_PRIVATE | MAP_ANONYMOUS , -1 , 0 );
0 commit comments