From 148787cd8a949e142c0a23575253224915eb7744 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Tue, 4 Aug 2026 15:15:21 -0400 Subject: [PATCH 1/2] Isolate macOS from Linux mmap optimizations. --- include/bitcoin/database/impl/memory/mmap_staging.ipp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/bitcoin/database/impl/memory/mmap_staging.ipp b/include/bitcoin/database/impl/memory/mmap_staging.ipp index c3d053f63..a3323c196 100644 --- a/include/bitcoin/database/impl/memory/mmap_staging.ipp +++ b/include/bitcoin/database/impl/memory/mmap_staging.ipp @@ -938,10 +938,15 @@ void CLASS::settler_run_() NOEXCEPT } #endif +#if !defined(HAVE_APPLE) // Scarcity is read directly: clean cache is reclaimable, so the // kernel pressure level does not raise while free memory exhausts. + // Apple is excluded: the sweep corrects linux victim selection, and + // ubc/compressor reclaim measured competent without it (its free + // signal is also perpetually low on darwin, running the sweep hot). if (system_free() < scarce) evict_next_(sweep); +#endif auto bytes = backlog(); if (is_zero(bytes)) @@ -998,6 +1003,7 @@ void CLASS::head_run_() NOEXCEPT still = (top == mark) ? std::min(add1(still), idle_seconds) : zero; mark = top; +#if !defined(HAVE_APPLE) // Touch pass: assert working-set residency at a bounded rate. // Hash-uniform probing is per-page sparse in every phase, so the // kernel ages head pages cold and swaps them under cache pressure, From 02e6779b1806b07ec54e2b7b0e6c2890a34822f1 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Tue, 4 Aug 2026 15:15:36 -0400 Subject: [PATCH 2/2] Restore known-good darwin (no sweep, no touch lap, normal advice). --- include/bitcoin/database/impl/memory/mmap_staging.ipp | 1 + include/bitcoin/database/memory/settings.hpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/memory/mmap_staging.ipp b/include/bitcoin/database/impl/memory/mmap_staging.ipp index a3323c196..0e8cd343e 100644 --- a/include/bitcoin/database/impl/memory/mmap_staging.ipp +++ b/include/bitcoin/database/impl/memory/mmap_staging.ipp @@ -1047,6 +1047,7 @@ void CLASS::head_run_() NOEXCEPT } } } +#endif // !HAVE_APPLE if ((still < idle_seconds) || (transferred == top)) continue; diff --git a/include/bitcoin/database/memory/settings.hpp b/include/bitcoin/database/memory/settings.hpp index 43508a81f..2d3879aa5 100644 --- a/include/bitcoin/database/memory/settings.hpp +++ b/include/bitcoin/database/memory/settings.hpp @@ -60,8 +60,14 @@ struct storage_settings /// scattered: they are far too large to reside, and validation reads /// prevouts from arbitrary earlier blocks, so read-ahead manufactures /// cache that is never used and displaces the resident head set. Heads - /// override to random (preloaded) at construction. + /// override to random (preloaded) at construction. Apple retains normal + /// (its measured known-good): darwin fault clustering serves scattered + /// prevout reads that MADV_RANDOM would reduce to single-page faults. +#if defined(HAVE_APPLE) + advice access{ advice::normal }; +#else advice access{ advice::scattered }; +#endif }; } // namespace database