| 10 Mar 2026 |
Puna | diff --git a/pkgs/by-name/je/jemalloc/package.nix b/pkgs/by-name/je/jemalloc/package.nix
index 202195c152db..88e7b776b28d 100644
--- a/pkgs/by-name/je/jemalloc/package.nix
+++ b/pkgs/by-name/je/jemalloc/package.nix
@@ -13,6 +13,18 @@
# compatibility.
stripPrefix ? stdenv.hostPlatform.isDarwin,
disableInitExecTls ? false,
+ # The upstream default is dependent on the builders' page size
+ # https://github.com/jemalloc/jemalloc/issues/467
+ # https://sources.debian.org/src/jemalloc/5.3.0-3/debian/rules/
+ pageSizeLog2 ?
+ if
+ (
+ stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isLoongArch64 || stdenv.hostPlatform.isPower64
+ )
+ then
+ 16
+ else
+ 12,
}:
stdenv.mkDerivation (finalAttrs: {
@@ -46,21 +58,11 @@ stdenv.mkDerivation (finalAttrs: {
configureFlags = [
"--with-version=${lib.versions.majorMinor finalAttrs.version}.0-0-g${finalAttrs.src.rev}"
"--with-lg-vaddr=${with stdenv.hostPlatform; toString (if isILP32 then 32 else parsed.cpu.bits)}"
+ (lib.strings.withFeatureAs true "lg-page" (toString pageSizeLog2))
]
# see the comment on stripPrefix
++ lib.optional stripPrefix "--with-jemalloc-prefix="
++ lib.optional disableInitExecTls "--disable-initial-exec-tls"
- # The upstream default is dependent on the builders' page size
- # 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) then
- "--with-lg-page=16"
- else
- "--with-lg-page=12"
- )
- ]
# See https://github.com/jemalloc/jemalloc/issues/1997
# Using a value of 48 should work on both emulated and native x86_64-darwin.
++ lib.optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) "--with-lg-vaddr=48";
ig
| 06:02:19 |
Puna | with the isPower64 addition in a separate commit, just to separate that abit more cleanly | 06:03:55 |
amaan | would you prefer that to be before or after the configurable page size? | 06:04:35 |
Puna | doesn't really matter i think | 06:04:58 |
amaan | i was thinking exposing just "pageSize" would be less of a cognitive burden on users | 06:05:11 |
amaan | and just adding a simple mapping | 06:05:23 |
Puna | should be fine as well | 06:08:11 |
amaan | cool, just updated the pr | 06:14:34 |
Puna | if we reject non-int values for pageSizeKiB with an assert + informative message, then supplying an unsupported number actually displays the supported options on my end (Lix)
error: attribute '"32"' missing
at /home/puna/Development/nixpkgs/pkgs/by-name/je/jemalloc/package.nix:76:10:
75| }
76| ."${toString pageSizeKiB}"
| ^
77| }"
note: trace involved the following derivations:
derivation 'jemalloc-5.3.0-unstable-2025-09-12'
Did you mean one of 16, 4 or 64?
maybe useful, prolly overkill. thoughts?
| 06:26:57 |
Puna | * if we reject non-int values for pageSizeKiB with an assert + informative message at the start, then supplying an unsupported number actually displays the supported options on my end (Lix)
error: attribute '"32"' missing
at /home/puna/Development/nixpkgs/pkgs/by-name/je/jemalloc/package.nix:76:10:
75| }
76| ."${toString pageSizeKiB}"
| ^
77| }"
note: trace involved the following derivations:
derivation 'jemalloc-5.3.0-unstable-2025-09-12'
Did you mean one of 16, 4 or 64?
maybe useful, prolly overkill. thoughts?
| 06:27:06 |
amaan | huh i already get that w/o an assert though | 06:29:50 |
amaan | if i pass in 32, for example:
error:
… while evaluating list element at index 2
… while calling the 'toString' builtin
at /home/amaanq/projects/nix/nixpkgs/pkgs/by-name/je/jemalloc/package.nix:70:7:
69| "--with-lg-page=${
70| toString
| ^
71| {
error: attribute '"32"' missing
at /home/amaanq/projects/nix/nixpkgs/pkgs/by-name/je/jemalloc/package.nix:71:9:
70| toString
71| {
| ^
72| "4" = 12;
Did you mean one of 16, 4 or 64?
| 06:30:14 |
Puna | yes, but if you pass i.e. "bla", it doesn't provide any suggestions anymore | 06:31:12 |
amaan | oh yeah, that's a good point | 06:31:27 |
Puna | oh, way to go is prolly
let
pageSizeMap = {
"4" = 12;
"16" = 14;
"64" = 16;
};
in
assert lib.asserts.assertOneOf "pageSizeKiB" (toString pageSizeKiB) (
builtins.attrNames pageSizeMap
);
| 06:32:23 |
amaan | i guess this works?
assert lib.asserts.assertMsg (builtins.isInt pageSizeKiB)
"jemalloc: pageSizeKiB must be an integer (one of 4, 16, or 64), got: ${toString pageSizeKiB}";
| 06:32:41 |
amaan | i guess this works?
assert lib.asserts.assertMsg (builtins.isInt pageSizeKiB)
"jemalloc: pageSizeKiB must be an integer (one of 4, 16, or 64), got: ${toString pageSizeKiB}";
| 06:32:45 |
amaan | tho maybe yours is better | 06:32:54 |
Puna | error: pageSizeKiB must be one of [
"16"
"4"
"64"
], but is: "bla"
| 06:33:02 |
amaan | yea that is nice | 06:33:11 |
amaan | though, not a fan of how it renders the list on multiple lines in this case | 06:35:27 |
amaan | let
pageSizeMap = {
"4" = 12;
"16" = 14;
"64" = 16;
};
in
assert lib.asserts.assertMsg
(builtins.hasAttr (toString pageSizeKiB) pageSizeMap)
"jemalloc: pageSizeKiB must be one of 4, 16, or 64, but is: ${toString pageSizeKiB}";
error: jemalloc: pageSizeKiB must be one of 4, 16, or 64, but is: bla
thoughts on this? | 06:36:20 |
Puna | requires manual updates of the supported values in the string | 06:37:16 |
Puna | (if another supported size is ever added, that is) | 06:37:49 |
amaan | yeah true;
let
pageSizeMap = {
"4" = 12;
"16" = 14;
"64" = 16;
};
in
assert lib.asserts.assertMsg (builtins.hasAttr (toString pageSizeKiB) pageSizeMap)
"jemalloc: pageSizeKiB must be one of ${lib.concatStringsSep ", " (builtins.attrNames pageSizeMap)}, but is: ${toString pageSizeKiB}";
is a bit better then | 06:38:14 |
Puna | i think at that point you're just reinventing assertOneOf, but without the multi-line printing 😅 | 06:39:14 |
amaan | true...then that's fine | 06:39:24 |
amaan | (i do like the presentation a little bit more but it's nbd) | 06:40:02 |
amaan | ok, just pushed that | 06:41:54 |
Puna | seems fine to me, but it's not my package. maybe someone else here who has an opinion on exposing jemalloc's page size setting like this? https://github.com/NixOS/nixpkgs/pull/498442 | 07:54:27 |