Skip to content

Commit 9fc90b2

Browse files
kpamnanyAdnan Alhomssi
authored 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 09eadfe commit 9fc90b2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/gc-pages.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ char *jl_gc_try_alloc_pages_(int pg_cnt) JL_NOTSAFEPOINT
7777
MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
7878
if (mem == MAP_FAILED)
7979
return NULL;
80+
81+
#ifdef MADV_NOHUGEPAGE
82+
madvise(mem, pages_sz, MADV_NOHUGEPAGE);
83+
#endif
84+
8085
#endif
8186
if (GC_PAGE_SZ > jl_page_size)
8287
// round data pointer up to the nearest gc_page_data-aligned

src/gc-stacks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
7272
munmap(stk, bufsz);
7373
return MAP_FAILED;
7474
}
75-
# endif
76-
75+
#ifdef MADV_NOHUGEPAGE
76+
madvise(stk, bufsz, MADV_NOHUGEPAGE);
77+
#endif
78+
#endif
7779
jl_atomic_fetch_add_relaxed(&num_stack_mappings, 1);
7880
return stk;
7981
}

src/gc-stock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,9 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offs
39113911
errno = last_errno;
39123912
if (__unlikely(pool == MAP_FAILED))
39133913
return NULL;
3914+
#ifdef MADV_NOHUGEPAGE
3915+
madvise(pool, GC_PERM_POOL_SIZE, MADV_NOHUGEPAGE);
3916+
#endif
39143917
#endif
39153918
gc_perm_pool = (uintptr_t)pool;
39163919
gc_perm_end = gc_perm_pool + GC_PERM_POOL_SIZE;

0 commit comments

Comments
 (0)