From 16d93cfd9fa8f5a61f0650d6749b4fcd7353bb86 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Mon, 9 Mar 2026 23:06:57 -0400 Subject: [PATCH 1/2] jemalloc: default to 64KB page size on ppc64 Most ppc64 kernels default to 64KB pages, for example, Fedora, SUSE, Arch POWER, and the upstream kernel itself (for Book3S, i.e. POWER4+) all ship with `CONFIG_PPC_64K_PAGES=y`, however, NixOS forces 4KB pages via `PPC_4K_PAGES`. A higher `--with-lg-page` is forward-compatible with lower page sizes but may waste some memory, so this commit trades a small amount of memory for broader build-host compatibility. --- pkgs/by-name/je/jemalloc/package.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/je/jemalloc/package.nix b/pkgs/by-name/je/jemalloc/package.nix index 202195c152db..389cec8ca60c 100644 --- a/pkgs/by-name/je/jemalloc/package.nix +++ b/pkgs/by-name/je/jemalloc/package.nix @@ -55,7 +55,11 @@ stdenv.mkDerivation (finalAttrs: { # https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/ ++ [ ( - if (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64) then + if + ( + stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64 || stdenv.hostPlatform.isPower64 + ) + then "--with-lg-page=16" else "--with-lg-page=12" From e29eca25fc5c51f34a9af75c83a8f37a677522a7 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Tue, 10 Mar 2026 02:07:47 -0400 Subject: [PATCH 2/2] jemalloc: add overridable `pageSizeKiB` argument This commit exposes the page size as an overridable `pageSizeKiB` argument instead of hardcoding the lg-page logic inline. This lets users tune jemalloc for their specific kernel page size via an overlay, e.g. `jemalloc.override { pageSizeKiB = 4; }` for 4KB-page kernels on a platform that ordinarily would have 64KB pages. --- pkgs/by-name/je/jemalloc/package.nix | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/je/jemalloc/package.nix b/pkgs/by-name/je/jemalloc/package.nix index 389cec8ca60c..0871ff1d4d61 100644 --- a/pkgs/by-name/je/jemalloc/package.nix +++ b/pkgs/by-name/je/jemalloc/package.nix @@ -13,8 +13,31 @@ # compatibility. stripPrefix ? stdenv.hostPlatform.isDarwin, disableInitExecTls ? false, + # Page size in KiB to configure jemalloc for. + # Defaults to 64 on architectures where 64KB pages are common, 4 otherwise. + # Note that a higher value is compatible with lower page sizes but may waste memory. + pageSizeKiB ? + if + ( + stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64 || stdenv.hostPlatform.isPower64 + ) + then + 64 + else + 4, }: +let + pageSizeMap = { + "4" = 12; + "16" = 14; + "64" = 16; + }; +in +assert lib.asserts.assertOneOf "pageSizeKiB" (toString pageSizeKiB) ( + builtins.attrNames pageSizeMap +); + stdenv.mkDerivation (finalAttrs: { pname = "jemalloc"; version = "5.3.0-unstable-2025-09-12"; @@ -54,16 +77,7 @@ stdenv.mkDerivation (finalAttrs: { # https://github.com/jemalloc/jemalloc/issues/467 # https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/ ++ [ - ( - if - ( - stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64 || stdenv.hostPlatform.isPower64 - ) - then - "--with-lg-page=16" - else - "--with-lg-page=12" - ) + "--with-lg-page=${toString pageSizeMap."${toString pageSizeKiB}"}" ] # See https://github.com/jemalloc/jemalloc/issues/1997 # Using a value of 48 should work on both emulated and native x86_64-darwin.