Skip to content

Commit 375d11e

Browse files
committed
revert(diagnostics): take the allocation profiler out of the build
The hosted windows-11-arm shards crash at process load (STATUS_ILLEGAL_INSTRUCTION, pass=0, secs=0) while main passes them, and removing the TLS detach callback did not help -- so the remaining candidate is this layer, which touches every allocation on Windows through the interposer. It declares a _Thread_local guard read on every malloc, and thread-local storage in a static MinGW aarch64 link is exactly the fragile case; nothing in it needs to ship. The profiler did its job: it produced the attribution that identified #581's mechanism, and that analysis is recorded. Sources stay in the tree, unbuilt, so a future investigation can re-enable them deliberately. Signed-off-by: Martin Vogel <[email protected]>
1 parent f843db8 commit 375d11e

4 files changed

Lines changed: 11 additions & 60 deletions

File tree

‎Makefile.cbm‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ endif
133133
# and redirecting malloc into mimalloc underneath ASan's own interception mixes
134134
# two allocators on the same pointers. Windows keeps its wrap flags everywhere,
135135
# because there the shim is what makes mimalloc own the allocations at all.
136-
LDFLAGS = -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS) $(MIMALLOC_WRAP_FLAGS_POSIX)
136+
LDFLAGS = -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS)
137137
LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz $(SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
138138
LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz $(TSAN_SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
139139

@@ -155,8 +155,6 @@ FOUNDATION_SRCS = \
155155
src/foundation/compat_fs.c \
156156
src/foundation/compat_regex.c \
157157
src/foundation/mem.c \
158-
src/foundation/mem_profile.c \
159-
src/foundation/mem_override_posix.c \
160158
src/foundation/diagnostics.c \
161159
src/foundation/profile.c \
162160
src/foundation/dump_verify.c \

‎internal/cbm/cbm.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "foundation/constants.h"
2222
#include "mimalloc.h" // mi_malloc/mi_calloc/mi_realloc/mi_free/mi_usable_size — bind 3rd-party allocators (#424)
2323
#if defined(CBM_BIND_TS_ALLOCATOR) && CBM_BIND_TS_ALLOCATOR
24-
#include "foundation/mem_profile.h"
2524
#include "sqlite3.h" // sqlite3_mem_methods, sqlite3_config, SQLITE_CONFIG_MALLOC — bind sqlite to mimalloc
2625
#endif
2726
#include <stdint.h> // uint32_t, uint64_t, int64_t
@@ -269,19 +268,14 @@ static TSParser *get_thread_parser(const TSLanguage *ts_lang, CBMLanguage lang)
269268
* (#581). */
270269
static void *cbm_sqlite_malloc(int n) {
271270
void *block = mi_malloc((size_t)n);
272-
cbm_mem_profile_alloc_at(block, (size_t)n, __builtin_return_address(0));
273271
return block;
274272
}
275273
static void cbm_sqlite_free(void *p) {
276-
cbm_mem_profile_free(p);
277274
mi_free(p);
278275
}
279276
static void *cbm_sqlite_realloc(void *p, int n) {
280-
if (p) {
281-
cbm_mem_profile_free(p);
282-
}
277+
if (p) {}
283278
void *grown = mi_realloc(p, (size_t)n);
284-
cbm_mem_profile_alloc_at(grown, (size_t)n, __builtin_return_address(0));
285279
return grown;
286280
}
287281
static int cbm_sqlite_size(void *p) {
@@ -294,24 +288,18 @@ static int cbm_sqlite_roundup(int n) {
294288
* through these, and they too skip the interposer. */
295289
static void *cbm_ts_malloc(size_t n) {
296290
void *block = mi_malloc(n);
297-
cbm_mem_profile_alloc_at(block, n, __builtin_return_address(0));
298291
return block;
299292
}
300293
static void *cbm_ts_calloc(size_t count, size_t size) {
301294
void *block = mi_calloc(count, size);
302-
cbm_mem_profile_alloc_at(block, count * size, __builtin_return_address(0));
303295
return block;
304296
}
305297
static void *cbm_ts_realloc(void *p, size_t n) {
306-
if (p) {
307-
cbm_mem_profile_free(p);
308-
}
298+
if (p) {}
309299
void *grown = mi_realloc(p, n);
310-
cbm_mem_profile_alloc_at(grown, n, __builtin_return_address(0));
311300
return grown;
312301
}
313302
static void cbm_ts_free(void *p) {
314-
cbm_mem_profile_free(p);
315303
mi_free(p);
316304
}
317305

‎src/foundation/mem.c‎

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "log.h"
1212
#include "compat_fs.h"
1313
#include "compat_thread.h"
14-
#include "mem_profile.h"
1514

1615
#include "foundation/constants.h"
1716

@@ -351,16 +350,6 @@ void cbm_mem_init_with_cap(double ram_fraction, size_t hard_cap_bytes) {
351350
char ram_mb[CBM_SZ_32];
352351
snprintf(budget_mb, sizeof(budget_mb), "%zu", g_budget / MB_DIVISOR);
353352
snprintf(ram_mb, sizeof(ram_mb), "%zu", info.total_ram / MB_DIVISOR);
354-
{
355-
/* Report the profiler gate once. Without this, "no records" cannot be
356-
* told apart from "never enabled" — and that ambiguity already cost
357-
* three measurement rounds. */
358-
char profile_threshold[CBM_SZ_32];
359-
(void)snprintf(profile_threshold, sizeof(profile_threshold), "%zu",
360-
cbm_mem_profile_threshold());
361-
cbm_log_info("mem.profile.gate", "enabled", cbm_mem_profile_enabled() ? "true" : "false",
362-
"threshold", profile_threshold);
363-
}
364353
cbm_log_info("mem.init", "budget_mb", budget_mb, "total_ram_mb", ram_mb, "source",
365354
resolved.source);
366355
}
@@ -903,8 +892,6 @@ void cbm_mem_census_log(const char *tag) {
903892
/* Attribution alongside the pool totals: the census says which pool holds
904893
* the memory, the profile says which call sites put it there. Emitting
905894
* both from one place keeps the two views on the same sample. */
906-
cbm_mem_profile_totals_t profile;
907-
cbm_mem_profile_totals(&profile);
908895
/* The allocator's OWN view, next to the OS view. If mimalloc's committed
909896
* area tracks the process's private commit, the memory is the allocator's
910897
* and it is holding pages against tiny live data; if it stays flat while
@@ -916,26 +903,12 @@ void cbm_mem_census_log(const char *tag) {
916903
char map_area_kb[CBM_SZ_32];
917904
(void)snprintf(map_live_kb, sizeof(map_live_kb), "%zu", map.live_bytes / CBM_SZ_1K);
918905
(void)snprintf(map_area_kb, sizeof(map_area_kb), "%zu", map.area_committed_bytes / CBM_SZ_1K);
919-
char prof_live_kb[CBM_SZ_32];
920-
char prof_sites[CBM_SZ_32];
921-
char prof_lost[CBM_SZ_32];
922-
char prof_total_kb[CBM_SZ_32];
923-
(void)snprintf(prof_live_kb, sizeof(prof_live_kb), "%zu", profile.live_bytes / CBM_SZ_1K);
924-
(void)snprintf(prof_sites, sizeof(prof_sites), "%zu", profile.sites);
925-
(void)snprintf(prof_total_kb, sizeof(prof_total_kb), "%zu", profile.total_bytes / CBM_SZ_1K);
926-
(void)snprintf(prof_lost, sizeof(prof_lost), "%zu",
927-
profile.site_table_full + profile.pointer_table_full + profile.capture_failed);
928-
char profile_path[CBM_SZ_1K];
929-
if (cbm_safe_getenv("CBM_MEM_PROFILE_OUT", profile_path, sizeof(profile_path), NULL) != NULL) {
930-
(void)cbm_mem_profile_dump(profile_path, tag ? tag : "?");
931-
}
932-
cbm_log_info("mem.census", "at", tag ? tag : "?", "prof_live_kb", prof_live_kb, "mi_area_kb",
933-
map_area_kb, "mi_live_kb", map_live_kb, "prof_sites", prof_sites, "prof_total_kb",
934-
prof_total_kb, "prof_lost", prof_lost, "priv_kb", priv_kb, "crt_kb", crt_kb,
935-
"crt_busy_kb", busy_kb, "mapped_kb", mapped_kb, "rss_kb", rss_kb, "biggest_kb",
936-
biggest_kb, "regions", regions, "big_regions", big_regions, "heaps", heaps,
937-
"biggest_base", base, "priv_small_kb", psmall, "priv_med_kb", pmed,
938-
"priv_large_kb", plarge, "priv_counts", pcounts, "large_map", large_map);
906+
cbm_log_info("mem.census", "at", tag ? tag : "?", "mi_area_kb", map_area_kb, "mi_live_kb",
907+
map_live_kb, "priv_kb", priv_kb, "crt_kb", crt_kb, "crt_busy_kb", busy_kb,
908+
"mapped_kb", mapped_kb, "rss_kb", rss_kb, "biggest_kb", biggest_kb, "regions",
909+
regions, "big_regions", big_regions, "heaps", heaps, "biggest_base", base,
910+
"priv_small_kb", psmall, "priv_med_kb", pmed, "priv_large_kb", plarge,
911+
"priv_counts", pcounts, "large_map", large_map);
939912
/* The phase table answers WHICH bracketed path the committed bytes stayed
940913
* in. Emitted once at the end rather than per request: it is cumulative,
941914
* so only the final table carries the verdict. */

‎src/foundation/mem_override_win.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
* mimalloc is always safe.
4343
*/
4444
#include "foundation/mem.h"
45-
#include "foundation/mem_profile.h"
4645

4746
#include <mimalloc.h>
4847
#include <stddef.h>
@@ -70,15 +69,11 @@ static inline bool mem_override_is_ours(const void *block) {
7069
}
7170

7271
void *__wrap_malloc(size_t size) {
73-
void *block = mi_malloc(size);
74-
cbm_mem_profile_alloc_at(block, size, __builtin_return_address(0));
75-
return block;
72+
return mi_malloc(size);
7673
}
7774

7875
void *__wrap_calloc(size_t count, size_t size) {
79-
void *block = mi_calloc(count, size);
80-
cbm_mem_profile_alloc_at(block, count * size, __builtin_return_address(0));
81-
return block;
76+
return mi_calloc(count, size);
8277
}
8378

8479
char *__wrap_strdup(const char *text) {
@@ -100,7 +95,6 @@ void __wrap_free(void *block) {
10095
return;
10196
}
10297
if (mem_override_is_ours(block)) {
103-
cbm_mem_profile_free(block);
10498
mi_free(block);
10599
return;
106100
}
@@ -126,9 +120,7 @@ void *__wrap_realloc(void *block, size_t size) {
126120
return mi_malloc(size);
127121
}
128122
if (mem_override_is_ours(block)) {
129-
cbm_mem_profile_free(block);
130123
void *grown = mi_realloc(block, size);
131-
cbm_mem_profile_alloc_at(grown, size, __builtin_return_address(0));
132124
return grown;
133125
}
134126
/* A CRT block cannot be handed to mi_realloc, and the CRT's realloc must

0 commit comments

Comments
 (0)