Skip to content

Make --with-lg-page=16 the default option on ARM64 architecture #2639

Closed

Description

@theofficialgman

ARM64 architecture supports 4K, 16K, and 64K pagesizes. Most ARM64 server hardware is already using 64K pagesize kernels. Many popular modern ARM64 consumer hardware is using 16K pagesize (Raspberry Pi5 and Apple Silicon Macs).

This proliferation has caused all distributions of jemalloc (distros, toolkits, etc) and applications that bundle jemalloc (chromium and all derivatives, geekbench, rust, etc) to set the --with-lg-page=16 to support them. If they do not then the application will crash due to unsupported pagesize for jemalloc.

A good summary of the bug is here -> k3s-io/k3s#7335 (comment) and #467 (comment) . The TLDR of that is not supporting all supported pagesizes of the ARM64 architecture on default configuration options is a bug by definition.

Activity

  1. clementperon commented on Apr 23, 2024

    @clementperon

    Related to #467

  2. theofficialgman commented on Apr 23, 2024

    @theofficialgman
    Author
  3. theofficialgman commented on Apr 23, 2024

    @theofficialgman
    Author

    also just to add to this comment from the other thread #467 (comment)

    jemalloc's insistence on taking advantage of compile time optimizations by baking in static page size seems to be the reason for a lot of ARM software incompatibility out there on Linux currently

    I do not see why jemalloc could not implement runtime checks for page size to take different codepaths within the binary. You should be able to have your compile time optimizations while also being compatible with the 3 pagesizes supported by the ARM64 architecture (4K/16K/64K) only at the expense of binary size (eg: all three codepaths exists in the final binary but the two non-native pagesize codepaths go unused)

    Of course all that effort is unnecessary if using a binary optimized for 64K pagesize (--with-lg-page=16) on a 4K pagesize does not lead to a considerable (eg: 10%+) regression in performance or memory usage.

  4. madscientist commented on Apr 23, 2024

    @madscientist
    Contributor

    Unfortunately it IS expensive in some ways for jemalloc to run on systems with larger page sizes. Just as an example, we know that heap profiling is seriously impacted by page size, such that if you have a 64k page you may well have to disable it as it uses too much memory. If you have a 4k page size you don't have this problem and you can leave it on always if you want. There are other issues such as the size of VIRT memory which doesn't matter for performance but makes a very big difference for things like coredumps. There have been some attempts to reduce these impacts but they still exist to some extent.

    So, simply always compiling with --with-lg-page=16 by default does have costs. Maybe some projects don't care about these costs, but others do.

    I think it's totally ridiculous for a project to refuse to add this option to their jemalloc config because it's "not standard". We set this ourselves on ARM since Red Hat EL 8 uses 64k page size. However I think most current Linux distributions (RHEL 9, Debian/Ubuntu, etc.) use 4k pages on ARM.

    On the other hand I don't care if jemalloc changes its default setting (for ARM, but NOT for Intel!!) to use 64k pages as long as the docs are clear about this and the --with-lg-page option is still supported to reduce it where that makes sense.

    I don't really see how it will work for a single libjemalloc.a library to provide support for all page sizes and switch at runtime. I'm not a jemalloc dev but if you read the other issues it's pretty clear that changing this value also changes the size etc. of data structures in jemalloc so it's not just a matter of choosing a different set of algorithms at runtime. You'd basically need to link three complete versions of jemalloc, then select the one you want at runtime, and selecting an allocator at runtime is notoriously tricky because it needs to be in place before anything, including pre-main code, tries to allocate any memory.

  5. theofficialgman commented on May 8, 2024

    @theofficialgman
    Author
  6. Fredvs79 commented on May 12, 2024

    @Fredvs79

    Just want to add a few tidbits to the discussion.

    #1, the raspberryPi 5 has optimizations over the rPi4 that include 16K page sizes. I ran into an issue where a package that depends on jemalloc ran fine on the rPi4 but not on the rPi5 with the default kernel. The quick and easy solution was to load a different generic kernel (kernel8) to use a 4K page size.
    #2, per the install.MD for jemalloc

    --with-lg-page=<lg-page>

    • Specify the base 2 log of the allocator page size, which must in turn be at least as large as the system page size. By default the configure script determines the host's page size and sets the allocator page size equal to the system page size, so this option need not be specified unless the system page size may change between configuration and execution, e.g. when cross compiling.

    Am I incorrect to think that for a 16K page size would yield --with-lg-page=4 (not --with-lg-page=16)
    --edit --
    I now realize that setting jemalloc to 64K page size would allow for 4K, 16K, and 64K page sizes, and would work with any kernel.

    #3 There is some discussion about also optimizing jemalloc to use --with-hugepage=21 as the default build environment variable for arch64. #2624

  7. marcan commented on Dec 5, 2024

    @marcan

    So, simply always compiling with --with-lg-page=16 by default does have costs. Maybe some projects don't care about these costs, but others do.

    Then those that do, and which are OK with their builds will be non-portable to all ARM64 machines, can make the choice to change to 4K.

    What doesn't make any sense whatsoever is for the jemalloc default to simply not work on some machines, because it means that every downstream project has to fix this bug for jemalloc by overriding the build options, which is an endless whack-a-mole of contacting downstream projects (and some, like Telegram, refuse because they think jemalloc should do this). The vast, vast, vast majority of projects' goal with pre-built binaries is that they work at all, not that heap profiling is more efficient. If a project wants to sacrifice portability to have more efficient heap profiling, that should be an explicit opt-in choice (and then perhaps the fact that heap profiling is bad on 64K builds should be considered a jemalloc bug to be fixed later).

  8. ilya-fedin commented on Dec 9, 2024

    @ilya-fedin

    Another way for Telegram could be to fix memory usage with glibc (it never releases the RAM allocated for video frames for unknown reason) so jemalloc is not needed at all. Sadly, there's no one to do that work... I believe asahi community has people with low level knowledge of memory allocations, if someone made a call within their community to look at the tdesktop glibc allocations problem and develop a fix, tdesktop worked on asahi and rpi5 since long time ago.

  9. ilya-fedin commented on Dec 9, 2024

    @ilya-fedin

    Alternative solutions like finding a replacement for jemalloc that would work with 16K page size out-of-the-box and releasing the RAM properly are welcome, too.

  10. mullcom commented on Feb 28, 2025

    @mullcom

    Still bo progress it seams. I just did install docker with six hook and find out.......

    This is so bad for open source to not solving this situvation. So is sent easy to come together then blame etch otheras a open source team and not as a company that constantly have this issues because agreed and power. How about get the Pride back by do it instead of blame it.?

  11. ilya-fedin commented on Feb 28, 2025

    @ilya-fedin

    The problem is not in blaming but in the lack of someone who will do the actual work (speaking tdesktop side at least - it just lacks a developer with arm64 machine to really support it and fix arm64 specific bugs)

  12. Fredvs79 commented on Feb 28, 2025

    @Fredvs79

    From where I sit, this seems like a chicken or egg kind of puzzle. Do you set 4K as the default and tell everyone who wants 16K to compile their own instance, or do you set 16K as the default and tell everyone who wants 4K page size to compile their own instance?

    jemalloc currently uses 4K by default, but can support 16K with build arguments.
    Their only option is to custom compile and load jemalloc. That would be fine if there were lots of people who need 4k and very people who need 16k. I don't know what the distribution is, but my hunch is that wherever it is, it is moving in the direction of favor for 16K page size support. So when will jemalloc change to reflect this since there are mounting voices requesting it.

    The counter argument presented was there may exist other people who specifically do not want 16k page size as the default. And whether they are the silent majority, or even if they are the minority, obviously they don't want the odious burden of having to custom build and load jemalloc.

    Unfortunately jemalloc has to pick a side for what the default should be, and which user base they are going to prioritize. As far as I can tell, for "the work", it basically comes down to inserting build flag arguments in a few locations to make 16k the default.

  13. ilya-fedin commented on Mar 1, 2025

    @ilya-fedin

    As far as I can tell, for "the work", it basically comes down to inserting build flag arguments in a few locations to make 16k the default.

    That might be not the solution maintainers want to see? And the solution they want to see might be way harder to implement.

    E.g. tdesktop side, we want page size to not be affected on arches other than arm64 but no one has proposed such a solution. Everyone just suggests to add an argument which changes the size on all arches.

    Ideal solution on tdesktop side would be for someone to do debugging to fix leaking with glibc allocator and just stop using jemalloc altogether. But no one has appealed to that work.

  14. sallyhaj commented on Mar 9, 2025

    @sallyhaj

    I use Raspberry Pi 5 with 16K page sizes.
    For me it fails to launch telegram-desktop from flathub.
    I have already compiled jemcalloc with --with-lg-page=16 but then telegram doesn't work.

  15. marcan commented on Mar 29, 2025

    @marcan
  16. 24 remaining items

  17. marcan commented on Mar 29, 2025

    @marcan
  18. marcan commented on Mar 29, 2025

    @marcan

    Is all this user pain across every downstream project using jemalloc really worth keeping the current broken unportable default?

    Remember that a 4K build only works on 4k systems, while a 64K build works on all systems, and the only downsides presented are that it is less optimal (maybe, no real stats have been shared), may use more memory than a pure 4K buid on 4K systems (maybe, sometimes, no real stats have been shared), and some stuff related to heap profiling. None of those hypotheticals sound like good reasons to keep a broken default that does not work at all on a subset of systems.

    At the end of the day, every downstream project that intends to be portable, which means any project that intends to package itself for distributions or flatpaks or snaps or AppImages or anything else intended to be used by Linux users in general, has to make this change. So regardless of the downsides, people will be living with them, because the alternative is broken software.

    The only people who will willingly keep the 4K default are those who actually know they only run on 4K platforms only and have reason to believe the downsides of a 64K build affect them.

    This is completely backwards. The default should cater to portable software intended to run on heterogeneous platforms. Closed, controlled ecosystems where the page size is known are the ones that should be overriding compile time options for micro-optimization.

  19. theofficialgman commented on Apr 6, 2025

    @theofficialgman
    Author

    @interwq Could you please outline a plan of action for having this (support for all the valid 4k, 16k, and 64k arm pagesizes in one binary (or set of distributable binaries)) resolved? It seems like all users are in agreement that this should be done (all users want software that works, like myself) but no developer of the jemalloc project has any interest in doing it. I think that outlining the process/plan that you and the other maintainers of jemalloc would be willing to merge once completed would help a 3rd party developer come in to implement the changes in the future.

    Additionally, @marcan makes some very valid points here ->

    the only downsides presented are that it is less optimal (maybe, no real stats have been shared), may use more memory than a pure 4K buid on 4K systems (maybe, sometimes, no real stats have been shared), and some stuff related to heap profiling. None of those hypotheticals sound like good reasons to keep a broken default that does not work at all on a subset of systems.

    please do share some test cases and statistics that show these statements to be true. It will help everyone understand the gravity (or lack of) a no-code change to --with-lg-page=16.

  20. dneary commented on May 7, 2025

    @dneary

    I submitted this pull request: #2845

    I hope it is accepted.

  21. added a commit that references this issue on Mar 5, 2026
    e70a50f
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