commit:     dcbf7b507eb15048e98043ab2b44c8ded36ffbf8
Author:     Matt Jolly <kangie <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 26 00:41:36 2026 +0000
Commit:     Matt Jolly <kangie <AT> gentoo <DOT> org>
CommitDate: Mon Jan 26 01:32:46 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=dcbf7b50

dev-libs/jemalloc: fix aarch64 non-4k page runtime issue

Jemalloc can't handle running on a system with a larger page size than
it was configured with, resulting in runtime failures if e.g. a binpkg
is used or build-time detection fails (some M1 processors, at least),
resulting in failures like:

        <jemalloc>: Unsupported system page size
        memory allocation of 72 bytes failed

On the other hand, it's quite happy to run when configured with a larger
page size (e.g. 64k) on systems with smaller page sizes (16k, 4k). Apply
an upstream patch to default to 64k on aarch64; users may override this
by passing `--with-lg-pagesize=foo` in `EXTRA_ECONF` if they so desire.

This won't resolve issues on other arches, but it's far less common to
see this sort of weirdness there anyway.

Closes: https://bugs.gentoo.org/964347
Signed-off-by: Matt Jolly <kangie <AT> gentoo.org>

 .../jemalloc-5.3.0-aarch64-64kib-page-size.patch   | 38 +++++++++++++++
 dev-libs/jemalloc/jemalloc-5.3.0-r2.ebuild         | 57 ++++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git 
a/dev-libs/jemalloc/files/jemalloc-5.3.0-aarch64-64kib-page-size.patch 
b/dev-libs/jemalloc/files/jemalloc-5.3.0-aarch64-64kib-page-size.patch
new file mode 100644
index 000000000000..151a5f40b695
--- /dev/null
+++ b/dev-libs/jemalloc/files/jemalloc-5.3.0-aarch64-64kib-page-size.patch
@@ -0,0 +1,38 @@
+https://github.com/facebook/jemalloc/commit/7dcdafea00a3a02cfbc84a798a0cc626515011eb
+From: lexprfuncall <[email protected]>
+Date: Mon, 25 Aug 2025 19:39:30 -0700
+Subject: [PATCH] Change the default page size to 64KiB on Aarch64 Linux
+
+This updates the configuration script to set the default page size to
+64KiB on Aarch64 Linux.  This is motivated by compatibility as a build
+configured for a 64KiB page will work on kernels that use the smaller
+4KiB or 16KiB pages, whereas the reverse is not true.
+
+To make the configured page size setting more visible, the script now
+displays the page size when printing the configuration results.
+
+Users that want to override the page size in to choose a smaller value
+can still do so with the --with-lg-pagesize configuration option.
+--- a/configure.ac
++++ b/configure.ac
+@@ -1990,6 +1990,11 @@ case "${host}" in
+         LG_PAGE=14
+       fi
+       ;;
++  aarch64-unknown-linux-*)
++      if test "x$LG_PAGE" = "xdetect"; then
++        LG_PAGE=16
++      fi
++      ;;
+ esac
+ if test "x$LG_PAGE" = "xdetect"; then
+   AC_CACHE_CHECK([LG_PAGE],
+@@ -3077,6 +3082,8 @@ AC_MSG_RESULT([INCLUDEDIR         : ${INCLUDEDIR}])
+ AC_MSG_RESULT([LIBDIR             : ${LIBDIR}])
+ AC_MSG_RESULT([MANDIR             : ${MANDIR}])
+ AC_MSG_RESULT([])
++AC_MSG_RESULT([LG_PAGE            : ${LG_PAGE}])
++AC_MSG_RESULT([])
+ AC_MSG_RESULT([srcroot            : ${srcroot}])
+ AC_MSG_RESULT([abs_srcroot        : ${abs_srcroot}])
+ AC_MSG_RESULT([objroot            : ${objroot}])

diff --git a/dev-libs/jemalloc/jemalloc-5.3.0-r2.ebuild 
b/dev-libs/jemalloc/jemalloc-5.3.0-r2.ebuild
new file mode 100644
index 000000000000..f8aa7026b069
--- /dev/null
+++ b/dev-libs/jemalloc/jemalloc-5.3.0-r2.ebuild
@@ -0,0 +1,57 @@
+# Copyright 1999-2026 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="8"
+
+inherit autotools multilib-minimal
+
+DESCRIPTION="Jemalloc is a general-purpose scalable concurrent allocator"
+HOMEPAGE="http://jemalloc.net/ https://github.com/jemalloc/jemalloc";
+SRC_URI="https://github.com/jemalloc/jemalloc/releases/download/${PV}/${P}.tar.bz2";
+
+LICENSE="BSD"
+SLOT="0/2"
+KEYWORDS="~alpha amd64 arm arm64 ~hppa ~loong ~m68k ~mips ppc ppc64 ~riscv 
~s390 ~sparc x86"
+IUSE="debug lazy-lock prof stats xmalloc"
+HTML_DOCS=( doc/jemalloc.html )
+PATCHES=(
+       "${FILESDIR}/${PN}-5.3.0-gentoo-fixups.patch"
+       "${FILESDIR}/${PN}-5.3.0-backport-pr-2312.patch"
+       "${FILESDIR}/${PN}-5.3.0-backport-pr-2338.patch"
+       "${FILESDIR}/${PN}-5.3.0-aarch64-64kib-page-size.patch" # users can 
override by passing `--with-lg-pagesize=foo`
+)
+
+MULTILIB_WRAPPED_HEADERS=( /usr/include/jemalloc/jemalloc.h )
+
+src_prepare() {
+       default
+       eautoreconf
+}
+
+multilib_src_configure() {
+       local myconf=(
+               $(use_enable debug)
+               $(use_enable lazy-lock)
+               $(use_enable prof)
+               $(use_enable stats)
+               $(use_enable xmalloc)
+       )
+
+       ECONF_SOURCE="${S}" econf "${myconf[@]}"
+}
+
+multilib_src_install() {
+       # Copy man file which the Makefile looks for
+       cp "${S}/doc/jemalloc.3" "${BUILD_DIR}/doc" || die
+       emake DESTDIR="${D}" install
+}
+
+multilib_src_install_all() {
+       if [[ ${CHOST} == *-darwin* ]] ; then
+               # fixup install_name, #437362
+               install_name_tool \
+                       -id "${EPREFIX}"/usr/$(get_libdir)/libjemalloc.2.dylib \
+                       "${ED}"/usr/$(get_libdir)/libjemalloc.2.dylib || die
+       fi
+       find "${ED}" -name '*.a' -delete || die
+}

Reply via email to