#include <stdio.h>
#include <string.h>
#include <stdarg.h>
+#include <stdint.h>
#include <dirent.h>
#include <sys/time.h>
#include <time.h>
}
flags &= ~MAP_HUGETLB;
ret = mmap(req, size, prot, flags, -1, 0);
+#ifdef MADV_HUGEPAGE
+ if (ret != MAP_FAILED && ((uintptr_t)ret & (2*1024*1024 - 1))) {
+ // try to manually realign assuming bottom-to-top alloc
+ munmap(ret, size);
+ ret = (void *)((uintptr_t)ret & ~(2*1024*1024 - 1));
+ ret = mmap(ret, size, prot, flags, -1, 0);
+ }
+ if (ret != MAP_FAILED)
+ madvise(ret, size, MADV_HUGEPAGE);
+#endif
}
if (ret == MAP_FAILED)
return NULL;