Using huge pages for Rust generated binaries

48 points whatmatrix

Hi,

I've been seeing a large number of iTLB misses in my code. I am trying to see if huge pages can be helpful to reduce iTLB misses.

I'm following https://easyperf.net/blog/2022/09/01/Utilizing-Huge-Pages-For-Code but stuck at multiple points.

LD_PRELOAD=libhugetlbfs.so {any rust binaries} will fail.

$ LD_PRELOAD=libhugetlbfs.so hugectl --text -v -v -v target/debug/hb
hugectl: INFO: HUGETLB_VERBOSE='5'
hugectl: INFO: LD_LIBRARY_PATH='/usr/local/lib:/usr/local/lib64:'
hugectl: INFO: HUGETLB_ELFMAP='R'
hugectl: WARNING: LD_PRELOAD not appropriate for this map combination
libhugetlbfs [REDACTED]: INFO: Found pagesize 2048 kB
libhugetlbfs [REDACTED]: INFO: Parsed kernel version: [5] . [10] . [144]
libhugetlbfs [REDACTED]: INFO: Feature private_reservations is present in this kernel
libhugetlbfs [REDACTED]: INFO: Feature noreserve_safe is present in this kernel
libhugetlbfs [REDACTED]: INFO: Feature map_hugetlb is present in this kernel
libhugetlbfs [REDACTED]: INFO: Kernel has MAP_PRIVATE reservations.  Disabling heap prefaulting.
libhugetlbfs [REDACTED]: INFO: Kernel supports MAP_HUGETLB
libhugetlbfs [REDACTED]: INFO: HUGETLB_SHARE=0, sharing disabled
libhugetlbfs [REDACTED]: INFO: HUGETLB_NO_RESERVE=no, reservations enabled
libhugetlbfs [REDACTED]: INFO: Segment 0 (phdr 2): 0-0x4a078  (filesz=0x4a078) (prot = 0x5)
libhugetlbfs [REDACTED]: INFO: libhugetlbfs version: 2.20
libhugetlbfs [REDACTED]: INFO: Mapped hugeseg at 0x7fc456400000. Copying 0x4a078 bytes and 0 extra bytes from (nil)...libhugetlbfs [REDACTED]: INFO: Prepare succeeded
Failed to map hugepage segment 0: 0-200000 (errno=1)
Aborted

Building a binary with "-Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152" won't result in the text page aligned in 2MiB boundary.

I tried the following. RUSTFLAGS='-Clink-arg=-Wl,-zcommon-page-size=2097152 -Clink-arg=-Wl,-zmax-page-size=2097152' cargo build ...

By doing readelf -S --wide target/..., it won't show the text section aligned like the web page mentioned above.

Is anyone successful using huge pages with Rust binaries?

Best regards,