Skip to content

Commit e8351ce

Browse files
committed
More options
1 parent d39b31c commit e8351ce

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎Objects/obmalloc.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,23 @@ _PyMem_RawFree(void *Py_UNUSED(ctx), void *ptr)
9393
static bool count_blocks(const mi_heap_t *, const mi_heap_area_t *,
9494
void *, size_t, void *);
9595

96-
// mimalloc v3 delays returning freed memory to the OS for much longer than v2
97-
// did (1000 ms purge delay and 4x arena multiplier, vs 10 ms and 10x), which
98-
// noticeably increases peak RSS. Restore the v2 timings, which have no
99-
// measurable speed cost. MIMALLOC_PURGE_DELAY and MIMALLOC_ARENA_PURGE_MULT
100-
// still take precedence.
96+
// mimalloc v3 keeps freed memory resident much longer than v2 did, which
97+
// noticeably increases peak RSS of short-running processes:
98+
// - All purges use purge_delay * arena_purge_mult (1000 ms * 4 by default),
99+
// while v2 purged freed pages after just purge_delay (10 ms).
100+
// - Delayed purges only release freed ranges of at least the minimal purge
101+
// size, which is 2 MiB when transparent huge pages are detected.
102+
// - Abandoned full pages hold memory that is not reused promptly.
103+
// Use v2-like timings, purge freed ranges at page granularity, and retain full
104+
// pages in their owning thread. None of these has a measurable speed cost.
105+
// The corresponding MIMALLOC_* environment variables still take precedence.
101106
static void
102107
set_mimalloc_defaults(void)
103108
{
104109
mi_option_set_default(mi_option_purge_delay, 10);
105-
mi_option_set_default(mi_option_arena_purge_mult, 10);
110+
mi_option_set_default(mi_option_arena_purge_mult, 1);
111+
mi_option_set_default(mi_option_arena_purge_min_size, 64); // KiB
112+
mi_option_set_default(mi_option_page_full_retain, -1);
106113
}
107114

108115
#ifdef Py_GIL_DISABLED
@@ -218,7 +225,6 @@ _PyMem_InitMimalloc(PyInterpreterState *interp)
218225
}
219226
mimalloc_init_qsbr = NULL;
220227
return 0;
221-
#endif
222228
}
223229

224230
void

0 commit comments

Comments
 (0)