Skip to content

Commit d19ec82

Browse files
kpamnanyAdnan Alhomssi
andcommitted
RAI: Disable huge pages for all mmap'ed memory
Prevent transparent huge pages (THP) overallocating pysical memory. Co-authored-by: Adnan Alhomssi <[email protected]>
1 parent 0153d1b commit d19ec82

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/gc-pages.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ char *jl_gc_try_alloc_pages_(int pg_cnt) JL_NOTSAFEPOINT
4747
MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
4848
if (mem == MAP_FAILED)
4949
return NULL;
50+
51+
#ifdef MADV_NOHUGEPAGE
52+
madvise(mem, pages_sz, MADV_NOHUGEPAGE);
53+
#endif
5054
#endif
5155
if (GC_PAGE_SZ > jl_page_size)
5256
// round data pointer up to the nearest gc_page_data-aligned

src/gc-stacks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
6161
munmap(stk, bufsz);
6262
return MAP_FAILED;
6363
}
64+
#ifdef MADV_NOHUGEPAGE
65+
madvise(stk, bufsz, MADV_NOHUGEPAGE);
66+
#endif
6467
#endif
6568
jl_atomic_fetch_add(&num_stack_mappings, 1);
6669
return stk;

src/gc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,6 +4000,9 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offs
40004000
errno = last_errno;
40014001
if (__unlikely(pool == MAP_FAILED))
40024002
return NULL;
4003+
#ifdef MADV_NOHUGEPAGE
4004+
madvise(pool, GC_PERM_POOL_SIZE, MADV_NOHUGEPAGE);
4005+
#endif
40034006
#endif
40044007
gc_perm_pool = (uintptr_t)pool;
40054008
gc_perm_end = gc_perm_pool + GC_PERM_POOL_SIZE;

0 commit comments

Comments
 (0)