Skip to content

Commit

Permalink
linux huge pages fallback strategy (mjansson#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored Dec 16, 2021
1 parent 4c10723 commit 07975ec
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rpmalloc/rpmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,18 @@ _rpmalloc_mmap_os(size_t size, size_t* offset) {
void* ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE, flags, fd, 0);
# elif defined(MAP_HUGETLB)
void* ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE | PROT_MAX(PROT_READ | PROT_WRITE), (_memory_huge_pages ? MAP_HUGETLB : 0) | flags, -1, 0);
# if defined(MADV_HUGEPAGE)
// In some configurations, huge pages allocations might fail thus
// we fallback to normal allocations and promote the region as transparent huge page
if ((ptr == MAP_FAILED || !ptr) && _memory_huge_pages) {
ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE, flags, -1, 0);
if (ptr && ptr != MAP_FAILED) {
int prm = madvise(ptr, size + padding, MADV_HUGEPAGE);
(void)prm;
rpmalloc_assert((prm == 0), "Failed to promote the page to THP");
}
}
# endif
# elif defined(MAP_ALIGNED)
const size_t align = (sizeof(size_t) * 8) - (size_t)(__builtin_clzl(size - 1));
void* ptr = mmap(0, size + padding, PROT_READ | PROT_WRITE, (_memory_huge_pages ? MAP_ALIGNED(align) : 0) | flags, -1, 0);
Expand Down

0 comments on commit 07975ec

Please sign in to comment.