Skip to content

arm64: configs: asahi: Cap the page block order at 2 MiB - #599

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
config/asahi-pageblock-2m
Oct 30, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
config/asahi-pageblock-2m

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

On 16K-page kernels a page block is 32 MiB, so khugepaged sets min_free_kbytes to 360448 kB (352 MiB) on every 8 GB Mac. The low and high watermarks follow at 440 and 528 MiB, and the per-CPU free lists are sized from the low watermark. That is a large share of the "3 GB used at idle" DJ saw on a fresh Fedora install.

Measured on the Neo (8 GB, GNOME, fleet9, idle):

MiB
MemTotal minus MemAvailable ("used") 2993
of which watermark deductions in MemAvailable (high + low from page cache + low/half from slab) ~1203
of which free pages held on per-CPU lists (not counted as free) ~265
real anon + GPU + kernel use ~1525

The M2 MacBook Air shows the same 360448 kB.

This sets CONFIG_PAGE_BLOCK_MAX_ORDER=7 (2 MiB blocks, the 4K arm64 and x86 size) in the shared asahi.config. Predicted for the Neo: min_free_kbytes about 22 MiB, high watermark about 37 MiB, and the reported idle use down by roughly 1.3 GiB. About 0.5 GiB more RAM is left for the page cache before kswapd runs.

Tested:

  • QEMU virt, 6 CPUs, 8 GB, 16K pages, THP madvise, allnoconfig plus the memory options, and only this option changed. Order 11 gives min_free_kbytes 411824 and MemAvailable 7476144 kB. Order 7 gives 45056 and 8026816 kB. QEMU has two zones, so its values are twice a Mac's. A 128 MiB MADV_HUGEPAGE region got 4 of 4 32 MiB THPs with no fallback on both kernels.
  • Merged over the fedora-aurora base config and run through olddefconfig, the value survives as 7.

Not tested yet: a hardware boot. This needs one universal-kernel boot on the Neo or M2 to check /proc/sys/vm/min_free_kbytes, /proc/pagetypeinfo, and the idle free -m. Fedora and ALARM merge asahi.config at build time. nixos-aurora keeps a vendored copy (kernel/asahi.config plus a resolved kernel/config with PAGE_BLOCK_MAX_ORDER=11), so it needs the usual tracking sync.

Trade-off: building a 32 MiB THP needs compaction across 16 page blocks instead of one, so PMD THP is harder to get under fragmentation. The Kconfig help notes this. Our configs use THP only on madvise, and mTHP sizes are below 2 MiB anyway.

🤖 Generated with Claude Code

With 16K pages the page block order follows the PMD order, so a page
block is 32 MiB. khugepaged sizes min_free_kbytes from the page block
size, eleven blocks per zone, which comes to 360448 kB (352 MiB) on
every 8 GB Mac with this config. The low and high watermarks follow at
440 MiB and 528 MiB, and the per-CPU page list limits are derived from
the low watermark, so another 250 to 440 MiB of free pages sits on
per-CPU lists where MemFree and MemAvailable do not count it.

On a MacBook Neo (8 GB) idling at the GNOME desktop this explains about
1.4 GiB of the 2.9 GiB that free and the desktop monitors report as
used: 1.2 GiB of watermark deductions in MemAvailable plus 265 MiB on
the per-CPU lists. kswapd also keeps about half a gigabyte free that
the page cache could use. The M2 MacBook Air shows the same 360448 kB.

Cap the page block order at 7, a 2 MiB block, the same size 4K arm64
and x86 kernels use. min_free_kbytes on the Neo drops to about 22 MiB
and the high watermark to about 37 MiB. 32 MiB transparent huge pages
are still allocated; compaction needs more free blocks to build one,
as the Kconfig help notes. THP is madvise only in our configs. CMA
areas need 2 MiB alignment instead of 32 MiB.

Booted in QEMU (virt, 6 CPUs, 8 GB, 16K pages, THP madvise) with only
this option changed:

  order 11: min_free_kbytes 411824, MemAvailable 7476144 kB
  order 7:  min_free_kbytes 45056,  MemAvailable 8026816 kB

QEMU has two zones, so its values are twice a single-zone Mac's. A
128 MiB MADV_HUGEPAGE region got 4 of 4 32 MiB THPs with no fallback
on both kernels.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Boot-tested in fleet10 (7.3.0-aurora-fleet10): integration/aurora 1173b79 plus 587, 588, 589, 590, 596, 599, 600, 601, 603, 604, 605, 607 and 608, built with the shipping recipe (Fedora Asahi base + asahi.config, 0 mismatches, all distro gates). apple-dcp host selftests 80/80, and the other host tests match integration/aurora exactly (62 pass, the same 26 pre-existing failures). One-shot boots on the Neo (J700), the M2 and the M1 Pro, compared with each machine's fleet9 boot; fleet10 is now the default on all three. Full dmesg and journals are in aurora-ctl reports/fleet10-20261030.

Result for this PR: pass, and the numbers match the prediction.

  • min_free_kbytes: 360448 to 22528 on the Neo, the M2 and the M1 Pro. /proc/pagetypeinfo shows page block order 7.
  • Idle free -m "used" shortly after boot: Neo 1508 MiB (fleet9 2969 MiB at 42 min uptime), M2 1429 MiB (fleet9 2787 MiB), M1 Pro 2099 MiB (fleet9 3919 MiB). MemAvailable on the Neo went from 4.56 to 6.02 GiB.
  • No allocation failures, no new warnings, GPU, Wi-Fi and SEP normal. Uptimes differ between the baselines and the fleet10 boots, so the "used" deltas are approximate; the watermark drop is exact.

@RyanTheTide
RyanTheTide merged commit 7772754 into aurora-wip Oct 30, 2026
@RyanTheTide
RyanTheTide deleted the config/asahi-pageblock-2m branch October 30, 2026 06:11
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

Successfully merging this pull request may close these issues.

1 participant