Skip to content

Commit c1cb70e

Browse files
authored
Merge pull request DeusData#2581 from DeusData/perf/mimalloc-macos-recommit
perf(mem): recommit purged memory on macOS so phys_footprint drops
2 parents ec4fbd3 + 63fb7b3 commit c1cb70e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎scripts/vendored-checksums.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ ce14eb6dfd55f241095b55f70983931a2d92f7a6a622a9b360cdd70ab3b53208 vendored/mimal
10241024
247a9952465eb105be03a9962e922b085ce5d52034775551a61cd8594275be73 vendored/mimalloc/src/prim/osx/prim.c
10251025
cc771788e5ba591efb681829a8724f8662a1f50f3db39cf5ebe7738b8ed57e44 vendored/mimalloc/src/prim/prim.c
10261026
792531421c247fca0766ff7630057ec491173578ca4d1919ae34f05eb289ccf4 vendored/mimalloc/src/prim/readme.md
1027-
c1ae32eaac7ccf18c10058cca99723892f8bd027318590151f5011c929c7e3be vendored/mimalloc/src/prim/unix/prim.c
1027+
20594d38ef4fc0c641f20a8664d17ee03ce195ca21b44e036f43cdb7bcd0bd0d vendored/mimalloc/src/prim/unix/prim.c
10281028
bee9c655a17e1e93bf4908e0a902fd3b566628447b1446fcbfa92bca2e76ca15 vendored/mimalloc/src/prim/wasi/prim.c
10291029
f70e61a1f2fe63da2f51c581895cf4a0918a9bffb0cf8600171f297141446962 vendored/mimalloc/src/prim/windows/etw-mimalloc.wprp
10301030
4f3110ef2054c95cb275be96cb279224d3d46a728c5117bd1435425f382de778 vendored/mimalloc/src/prim/windows/etw.h

‎vendored/mimalloc/src/prim/unix/prim.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,18 @@ int _mi_prim_decommit(void* start, size_t size, bool* needs_recommit) {
500500
// decommit: use MADV_DONTNEED as it decreases rss immediately (unlike MADV_FREE)
501501
err = unix_madvise(start, size, MADV_DONTNEED);
502502
#endif
503-
#if !MI_DEBUG && MI_SECURE<=2
503+
// codebase-memory-mcp local change (2026-10-10): macOS always takes the
504+
// recommit path that upstream reserves for MI_DEBUG / MI_SECURE>2 builds.
505+
// In the release path a purged range stays "committed" and is re-accounted as
506+
// a whole with MADV_FREE_REUSE when the arena hands it out again
507+
// (arena.c, _mi_os_reuse), so macOS charges its pages to phys_footprint
508+
// whether or not they are touched; recommitting instead charges only the
509+
// pages that are written. Measured on the indexer (Apple arm64, macOS 26.6),
510+
// peak phys_footprint release -> this change, wall time unchanged and the
511+
// graph byte-identical: TypeScript 1.98 -> 1.09 GB, kubernetes 2.92 -> 1.88 GB,
512+
// dotnet/runtime 12.7 -> 10.6 GB, linux kernel 16.0 -> 13.5 GB. Other
513+
// platforms keep upstream's behaviour (MADV_DONTNEED drops RSS at once).
514+
#if !MI_DEBUG && MI_SECURE<=2 && !defined(__APPLE__)
504515
*needs_recommit = false;
505516
#else
506517
*needs_recommit = true;

0 commit comments

Comments
 (0)