Repository navigation
Free-threading: RAM may not be released to the OS - #9429
Open
crusaderky wants to merge 2 commits into
Open
crusaderky wants to merge 2 commits into
crusaderky wants to merge 2 commits into
Conversation
Contributor
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 48 files ±0 48 suites ±0 14h 51m 34s ⏱️ + 11m 14s For more details on these errors, see this check. Results for commit 26b7a94. ± Comparison against base commit 88a19ad. ♻️ This comment has been updated with latest results. |
The last section of test_memory leaks 100 MiB strings in each worker,
clears them, and asserts that the process RSS drops accordingly. That
assertion is about the interpreter's allocator, not about distributed:
free-threaded builds allocate all Python objects with mimalloc instead
of pymalloc, and mimalloc never hands those pages back. The RSS of the
worker stays at its peak and the test fails with
Expected 0 MiB <= unmanaged <= 500.56 MiB; got:
Process memory (RSS) : 550.72 MiB
- unmanaged (old) : 550.72 MiB
Reproduced standalone on Linux:
object GIL 3.14 free-threaded 3.14
str 212 -> 12 MiB 214 -> 214 MiB
bytearray 212 -> 12 MiB 314 -> 314 MiB
bytes 212 -> 12 MiB 314 -> 314 MiB
gc.collect(), repeated collections and waiting 18s after the free change
nothing, and MIMALLOC_PURGE_DELAY=0 does not help for strings. This is a
documented limitation of the free-threaded build:
https://docs.python.org/3/howto/free-threading-python.html#mimalloc-allocator-vs-pymalloc
Skip the section on free-threaded builds, exactly like it is already
skipped on MacOS and Windows, and add a FREE_THREADED flag to
distributed.compatibility for this and future use.
crusaderky
force-pushed
the
test-memory-freethreading
branch
from
December 3, 2026 21:26
9f67a12 to
26b7a94
Compare
crusaderky
marked this pull request as ready for review
December 3, 2026 21:30
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_memorydereferences 100 MiB of unmanaged memory and expects that the RSS will drop soon afterwards - i.e. the memory will be returned to the OS.This is not meant to happen instantaneously on free-threaded builds, which use mimalloc. This is by design, as mimalloc implements a userspace arena that delays releasing memory to the OS by up to 100ms.
There is currently an upstream issue (python/cpython#158972) which causes the RAM to never be released.
Impact
In production, this has the potential to mess up all Dask heuristics based on RSS readings:
pausedstate;In other words, this is indistinguishable from a genuine memory leak, which Dask routes around.
I'm still triaging how actually likely this is in production.
Changes
This PR neuters
test_memoryfor the time being, preventing