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.

Co-authored-by: Adnan Alhomssi <[email protected]>
  • Loading branch information
2 people authored and RAI CI (GitHub Action Automation) committed Feb 21, 2024
1 parent 167cc63 commit c988094
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 @@ 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 @@ -4007,6 +4007,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 c988094

Please sign in to comment.