Skip to content
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

Is it possible to detect kAddressBits at runtime? #82

Open
rojkov opened this issue May 31, 2021 · 5 comments
Open

Is it possible to detect kAddressBits at runtime? #82

rojkov opened this issue May 31, 2021 · 5 comments

Comments

@rojkov
Copy link
Contributor

rojkov commented May 31, 2021

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?

@ckennelly
Copy link
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.

@vchrisb
Copy link

vchrisb commented Jun 1, 2021

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.

@fandahao17
Copy link

+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?

@PKizzle
Copy link

PKizzle commented Feb 20, 2023

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).

copybara-service bot pushed a commit that referenced this issue Feb 22, 2023
kAddressBits may be too large when CONFIG_PGTABLE_LEVELS=3 (#82).

PiperOrigin-RevId: 511575218
Change-Id: I5001342968266b73fcbfdd7b65884cda3488dde7
@tristanmorgan
Copy link

Code that detects the address space size.. https://github.com/ptitSeb/box64/blob/e42001b2bc030f93bdba582bf12d6eac63fae345/src/custommem.c#L1444

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

No branches or pull requests

6 participants