Skip to content

Commit

Permalink
RAI: Disable huge pages for all mmap'ed memory
Browse files Browse the repository at this point in the history
Prevent transparent huge pages (THP) overallocating pysical memory.
  • Loading branch information
kpamnany authored and RAI CI (GitHub Action Automation) committed Oct 14, 2023
1 parent 5197b2f commit 5e60b2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gc-pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ static char *jl_gc_try_alloc_pages(int pg_cnt) JL_NOTSAFEPOINT
return NULL;
poolmem_bytes_allocated += pages_sz;
poolmem_blocks_allocated_total++;

#ifdef MADV_NOHUGEPAGE
madvise(mem, pages_sz, MADV_NOHUGEPAGE);
#endif
#endif
if (GC_PAGE_SZ > jl_page_size)
// round data pointer up to the nearest gc_page_data-aligned
Expand Down
3 changes: 3 additions & 0 deletions src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
munmap(stk, bufsz);
return MAP_FAILED;
}
#ifdef MADV_NOHUGEPAGE
madvise(stk, bufsz, MADV_NOHUGEPAGE);
#endif
#endif
jl_atomic_fetch_add(&num_stack_mappings, 1);
return stk;
Expand Down
3 changes: 3 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4171,6 +4171,9 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offs
errno = last_errno;
if (__unlikely(pool == MAP_FAILED))
return NULL;
#ifdef MADV_NOHUGEPAGE
madvise(pool, GC_PERM_POOL_SIZE, MADV_NOHUGEPAGE);
#endif
#endif
gc_perm_pool = (uintptr_t)pool;
gc_perm_end = gc_perm_pool + GC_PERM_POOL_SIZE;
Expand Down

0 comments on commit 5e60b2a

Please sign in to comment.