Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
wip: report allocator ownership in the memory map
Martin Vogeld8443bcc0d8f
diff --git a/src/foundation/diagnostics.c b/src/foundation/diagnostics.cindex e88d1f90c..d8f466213 100644--- a/src/foundation/diagnostics.c+++ b/src/foundation/diagnostics.c@@ -489,6 +489,7 @@ static void write_diagnostics(void) {" \"query_total_us\": %lld,\n"" \"query_avg_us\": %lld,\n"" \"query_max_us\": %lld,\n"+ " \"mem_malloc_owned\": %s,\n"" \"mem_live_bytes\": %zu,\n"" \"mem_live_blocks\": %zu,\n"" \"mem_area_committed_bytes\": %zu,\n"@@ -498,7 +499,7 @@ static void write_diagnostics(void) {" \"pid\": %d\n""}\n",uptime, current_rss, peak_rss, current_commit, peak_commit, page_faults,- fds, qcount, qerrors, qtime, qavg, qmax, map.live_bytes, map.live_blocks,+ fds, qcount, qerrors, qtime, qavg, qmax, map.malloc_is_allocator_owned ? "true" : "false", map.live_bytes, map.live_blocks,map.area_committed_bytes, residual, buckets, phases, (int)getpid());if (length <= 0 || (size_t)length >= sizeof(snapshot) ||!diag_write_file(DIAG_SNAPSHOT_TMP_NAME, snapshot, (size_t)length, false) ||diff --git a/src/foundation/mem.c b/src/foundation/mem.cindex 336f040d9..4b8702e3d 100644--- a/src/foundation/mem.c+++ b/src/foundation/mem.c@@ -440,6 +440,18 @@ bool cbm_mem_map_collect(cbm_mem_map_t *out) {out->os_rss_bytes = current_rss ? current_rss : cbm_mem_rss();out->os_committed_bytes = current_commit;+ /* Does plain malloc actually land in the allocator's regions? This single+ * bit distinguishes "nothing is live" from "the allocator does not own+ * this build's allocations", which are opposite conclusions from the same+ * zero. Probe with a real malloc/free pair rather than inferring from+ * build flags, because the Windows static-CRT override is defined at+ * compile time yet can still fail to take effect at link time. */+ void *probe = malloc(CBM_SZ_64);+ if (probe) {+ out->malloc_is_allocator_owned = mi_is_in_heap_region(probe);+ free(probe);+ }+/* Walk areas only (visit_blocks=false): O(areas), safe on a live heap from* the diagnostics path. mi_heap_main() is the aggregate heap rather than* just this thread's, so coverage is wider than a per-thread walk — but itdiff --git a/src/foundation/mem.h b/src/foundation/mem.hindex eeef2cdb0..ea0ec7cb6 100644--- a/src/foundation/mem.h+++ b/src/foundation/mem.h@@ -111,6 +111,14 @@ void cbm_mem_collect_periodic(void);enum { CBM_MEM_MAP_BUCKETS = 8 };typedef struct {+ /* Is plain malloc actually served by the configured allocator on this+ * build? If false, every allocator tuning in cbm_mem_init (immediate+ * purge, page reclaim, arena policy) is inert for ordinary allocations,+ * the walk below sees nothing, and freed pages stay committed until the+ * platform's own heap decides otherwise. Checked FIRST when reading a+ * map: a false here explains a zero live_bytes, and is a platform-parity+ * defect in its own right (#581 on Windows). */+ bool malloc_is_allocator_owned;size_t os_committed_bytes;size_t os_rss_bytes;size_t live_bytes;