@@ -291,7 +291,36 @@ void cbm_mem_init_with_cap(double ram_fraction, size_t hard_cap_bytes) {
291291 }
292292#endif
293293
294+ /* Lazy arena commit costs address-space FRAGMENTATION, and on Linux we now
295+ * pay it for every allocation in the process. mimalloc commits a range with
296+ * mprotect(PROT_READ|PROT_WRITE) over a sub-range of a PROT_NONE reservation
297+ * (prim/unix/prim.c), and each partial commit SPLITS the reserved VMA. While
298+ * mimalloc only served the bound populations (sqlite, tree_sitter) that was a
299+ * handful of mappings. Since #1360 routed ordinary malloc/new through
300+ * mimalloc on Linux, an index worker peaked at ~22k mappings against
301+ * v0.9.0's 10 (Go corpus, 18 workers). The count tracks CONCURRENCY, not
302+ * corpus size — sampled mid-run it was 999 at 1 worker, 8460 at 4 and 11965
303+ * at 18, while v0.9.0 stayed at 10 regardless — so every worker thread
304+ * fragments the address space independently.
305+ *
306+ * Two consequences, both reported as #1654 on a 96-CPU/376 GB host: the
307+ * mmap/mprotect churn serialises on the kernel's per-process mmap_lock (the
308+ * reporter saw 1.2% of extraction in 45 minutes, where v0.9.0 finished the
309+ * tree in ~13), and the VMA count climbs toward vm.max_map_count, after
310+ * which mmap fails for ANY size — hence mimalloc reporting it "cannot
311+ * allocate" 10 KB while `free -g` still showed 246 GB available.
312+ *
313+ * mimalloc's own default is 2, meaning "eager-commit arenas only on an OS
314+ * with overcommit (i.e. linux)" — precisely because commit is free there
315+ * until the pages are touched. Overriding it to 0 opted Linux out of the
316+ * default written for it. Restore the default on Linux; keep the lazy
317+ * setting everywhere else, where commit is NOT free and the upfront-memory
318+ * reason for it still holds (Windows especially — see #581). */
319+ #if defined(__linux__ )
320+ mem_option_set_verified (mi_option_arena_eager_commit , 2 , "arena_eager_commit" );
321+ #else
294322 mem_option_set_verified (mi_option_arena_eager_commit , 0 , "arena_eager_commit" );
323+ #endif
295324 mem_option_set_verified (mi_option_purge_decommits , SKIP_ONE , "purge_decommits" );
296325 mem_option_set_verified (mi_option_purge_delay , 0 , "purge_delay" ); /* immediate */
297326 /* v3 (#832): reclaim abandoned pages on ANY thread's free (=1), restoring the
0 commit comments