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

Conversation

stedolan
Copy link
Contributor

@stedolan stedolan commented May 14, 2025

Hugepages are not necessarily a good idea for stacks: they mean that every stack takes 2MB of RAM, even though most programs confine themselves to a few k of stacks. This patch adds a new GC tweak to optionally disable hugepages for stacks (Xnohugepage_stacks=1), by passing MADV_NOHUGEPAGE to madvise.

On this program:

let n = Atomic.make 0
let () =
  let _ = List.init 100 (fun _ -> Thread.create (fun () -> Atomic.incr n; Unix.sleep 100) ()) in
  while Atomic.get n < 100 do Thread.yield () done;
  ()

the new flag makes the memory consumption go from 400 MB to 200 MB. (I think the remaining 2MB per thread is the glibc pthread stack).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant