Skip to content

Commit 8972ea6

Browse files
authored
Break-glass merge PR DeusData#2212
2 parents 2058d49 + 172787d commit 8972ea6

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎src/foundation/mem.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
#include <malloc/malloc.h> /* malloc_zone_pressure_relief */
3636
#else
3737
#include <unistd.h>
38-
#if defined(__GLIBC__)
39-
#include <malloc.h> /* malloc_trim */
40-
#endif
4138
#endif
4239

4340
/* Does THIS build ask mimalloc to replace ordinary malloc process-wide?
@@ -606,11 +603,15 @@ size_t cbm_mem_footprint(void) {
606603
}
607604

608605
void cbm_mem_release_to_os(void) {
606+
/* mi_collect is the release: on Linux and Windows mimalloc owns malloc, so
607+
* there is no libc heap to trim. glibc's malloc_trim was called here once
608+
* and cost the static Linux release its link: the reference pulls
609+
* libc.a(malloc.o) in beside mimalloc's malloc/free (multiple definition,
610+
* release run 34948714902, 2026-09-15). macOS keeps the system heap for
611+
* everything outside the core, hence the pressure-relief call there. */
609612
mi_collect(true);
610613
#if defined(__APPLE__)
611614
(void)malloc_zone_pressure_relief(NULL, 0);
612-
#elif defined(__GLIBC__)
613-
(void)malloc_trim(0);
614615
#endif
615616
}
616617

‎src/foundation/mem.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ void cbm_mem_collect(void);
119119
size_t cbm_mem_footprint(void);
120120

121121
/* Hand freed memory back to the OS on every allocator this process uses:
122-
* mimalloc (mi_collect), the macOS system zones (malloc_zone_pressure_relief)
123-
* and glibc (malloc_trim). Costs a few ms; call at phase boundaries after a
124-
* bulk release, never per allocation. */
122+
* mimalloc (mi_collect) and, on macOS, the system zones
123+
* (malloc_zone_pressure_relief). Never glibc's malloc_trim: on Linux mimalloc
124+
* owns malloc, and the reference alone breaks the static release link. Costs
125+
* a few ms; call at phase boundaries after a bulk release, never per
126+
* allocation. */
125127
void cbm_mem_release_to_os(void);
126128

127129
/* ── Memory map: where does the process's memory actually live? ──────

0 commit comments

Comments
 (0)