rubylinuxhuge-pages

Why don't transparent huge pages work for a program spawned from within Ruby?


I have a simple page fault stress test program, where I use madvise(..., MADV_HUGEPAGE) to enable THP (my Linux machine's THP mode is "madvise"). However, when I run it from Ruby, e.g. with system("..."), THP doesn't work. I can tell that because the performance is extremely bimodal depending on whether THP is on for it, and I see the "off" performance consistently. I've also tried spawning the program with Process.spawn and Open3.popen3, and still no luck. Does anyone know what might be happening here? I'm using Linux RHEL 7.9 with an x86-64 Intel CPU.


Solution

  • THP is disabled in Ruby since version 2.6:

    eval.c (ruby_setup): disable THP on Linux

    Transparent Huge Pages (THP) decrease the effectiveness of
    CoW-friendly GC because it decreases page granularity. That is,
    a forked process dirtying one bit of CoW-shared memory can
    trigger a copy of a huge page (2MB on x86-64) instead of a smaller,
    standard page (4K).

    Based on the commit message, it seems the THP-disabled behavior carries over to child processes, which would explain the behavior you're seeing.