On macOS 27, Go's MADV_FREE_REUSABLE (and DONTNEED, FREE) leave freed
pages in phys_footprint, which Activity Monitor shows as Memory, until
the system is short of memory. An idle magpie showed ~98MB while ~69MB
of it was heap Go had already given back. A MAP_FIXED anonymous remap
does take the pages out.
build/darwin/footprint-overlay.sh writes a copy of the toolchain's
runtime/mem_darwin.go whose sysUnusedOS maps fresh pages over the range
(falling back to MADV_FREE_REUSABLE), and prints an -overlay flag.
make build, cli, build-release (so make app) and release-cli use it.
It replaces a darwin-only file, so Linux and Windows builds are the
same; release-linux, release-windows and install are unchanged. The
script fails the build if sysUnusedOS is not found.
Run:
- Real config, sandbox HOME on mote, 6 minutes, footprint every 15s:
main (w26) settles at 87MB, with this (w27) at 77-79MB; the first
two minutes are the same (131-137MB, then ~123MB). Idle CPU over
90s: 0.19% vs 0.31% of one core; the page release is 10ms in both
profiles (madvise vs mmap), the rest is GC marking, which varies
run to run.
- build/darwin TestFreedHeapLeavesFootprint on mote (darwin, runs the
program) and in WSL (cross-compiles for darwin/arm64): ok.
- Broken by hand: a toy that frees 128MB shows 205MB without the
overlay and 8.4MB with it; with the script's replacement removed the
test's content check fails.
- make cli with the overlay on mote: builds.
Not tried: an Intel Mac; macOS before 27.