Skip to content

Optionally disable hugepages for stacks #4001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions runtime/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ uintnat caml_init_main_stack_wsz = 0; /* -Xmain_stack_size= */
uintnat caml_init_thread_stack_wsz = 0; /* -Xthread_stack_size= */
uintnat caml_init_fiber_stack_wsz = 0; /* -Xfiber_stack_size= */

uintnat caml_nohugepage_stacks = 0;

uintnat caml_get_init_stack_wsize (int context)
{
uintnat init_stack_wsize = 0;
Expand Down Expand Up @@ -229,6 +231,12 @@ Caml_inline struct stack_info* alloc_for_stack (mlsize_t wosize)
if (stack == NULL) {
return NULL;
}
#ifdef __linux__
/* On Linux, (optionally) disable *any* hugepage usage for stacks.
(Huge pages are not as beneficial for stacks, because you use the same few
kb over and over again, but can have a significant RAM cost) */
if (caml_nohugepage_stacks) madvise(stack, len, MADV_NOHUGEPAGE);
#endif
// mmap is always expected to return a page-aligned value.
CAMLassert((uintnat)stack % page_size == 0);

Expand Down
2 changes: 2 additions & 0 deletions runtime/gc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern uintnat caml_pool_min_chunk_bsz; /* see shared_heap.c */
extern uintnat caml_percent_sweep_per_mark; /* see major_gc.c */
extern uintnat caml_gc_pacing_policy; /* see major_gc.c */
extern uintnat caml_gc_overhead_adjustment; /* see major_gc.c */
extern uintnat caml_nohugepage_stacks; /* see fiber.c */

CAMLprim value caml_gc_quick_stat(value v)
{
Expand Down Expand Up @@ -443,6 +444,7 @@ static struct gc_tweak gc_tweaks[] = {
{ "percent_sweep_per_mark", &caml_percent_sweep_per_mark, 0 },
{ "gc_pacing_policy", &caml_gc_pacing_policy, 0 },
{ "gc_overhead_adjustment", &caml_gc_overhead_adjustment, 0 },
{ "nohugepage_stacks", &caml_nohugepage_stacks, 0 },
};

enum {N_GC_TWEAKS = sizeof(gc_tweaks)/sizeof(gc_tweaks[0])};
Expand Down
Loading