Skip to content

Is it possible to detect kAddressBits at runtime? #82

Description

@rojkov

As noted in #33 page tables on Aarch64 can have either 3 or 4 levels. tcmalloc assumes 4 levels for Aarch64 (kAddressBits = 48), but for example RaspberryOS for Aarch64 runs on a kernel with CONFIG_PGTABLE_LEVELS=3. As result all programs using tcmalloc fail without patching it to set kAddressBits = 39.

Is it possible to detect kAddressBits at runtime?

Activity

  1. ckennelly commented on May 31, 2021

    @ckennelly
    Collaborator

    It would be possible to make kAddressBits be runtime configurable (albeit at a slight performance cost, since we'd need to load the constant rather than use an immediate)--but I think one challenge is reliably detecting the value at runtime.

    Other than reading /proc/config.gz--which would be a bit involved while allocating memory--the only strategy that I'm aware of seems to be trial and error. I seem to recall a proposed kernel patch that would have exposed it (maybe as a proc file?) but I don't think it ever landed.

  2. vchrisb commented on Jun 1, 2021

    @vchrisb

    maybe the following does help: openjdk/jdk#40
    And the thread on the topic: http://openjdk.5641.n7.nabble.com/ZGC-aarch64-Unable-to-allocate-heap-for-certain-Linux-kernel-configurations-td420728.html

    I think this is how the folks ad openjdk are handling it by trial and error.

  3. fandahao17 commented on Sep 23, 2021

    @fandahao17

    +1 after struggling with a mysterious SIGABRT for a whole day and finally finding this issue. As a low-level library, tcmalloc may be depended by projects whose developers even don't know its existence. If detect the correct value of kAddressBits is hard, could we detect whether kAddressBits is misconfigured at runtime so we can abort in a more user-friendly way?

  4. PKizzle commented on Feb 20, 2023

    @PKizzle

    As checking for the kernel build config in /proc/config.gz requires CONFIG_IKCONFIG_PROC to be set, the best option would be for tcmalloc to use the proposed trial and error approach. Also a way to manually force kAddressBits to be set during compilation would be appreciated (without any automatic detection).

  5. tristanmorgan commented on Dec 17, 2023

    @tristanmorgan
  6. ketanhwr commented on Sep 8, 2025

    @ketanhwr

    V8 does a best-effort runtime detection (with fallback to compile time constants) for determining virtual address space size, can something similar be tried in tcmalloc during initialization?

    https://github.com/v8/v8/blob/14.1-lkgr/src/sandbox/sandbox.cc#L39-L99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions