Memory held for too long by the BRC queue while the owning thread is detached
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python code. If the owner stays detached for a long time — blocked on a lock, in a syscall, waiting on a pipe — the queued objects stay alive for as long as the owner is blocked. The GC drains the queue, but if the objects holds large amounts of memory then it is ineffective.
This was reported in Py314t uses 2× memory: a PyTorch training run uses 10GB on 3.14 and 20GB on 3.14t. The objects are large tensors enqueued on a multiprocessing.Queue, whose feeder thread does the cross-thread decref while the owner sits detached.
I propose to let the queueing thread do the merge itself. When it tries to queue a object of detached owner, it moves the owner from detached to suspended (the same transition stop-the-world uses), merges the refcounts, resumes the owner, and deallocates whatever reached zero outside the bucket mutex.
Linked PRs
- gh-157839
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no menciona archivos ni tests. Empieza siguiendo la free-threaded BRC queue y la transición de detached a suspended; después, examina cómo el GC drena los objetos en cola. Se considera terminado cuando el queueing thread puede fusionar referencias para un detached owner y liberar objetos sin esperar a que ese owner ejecute código Python; valídalo con la carga de trabajo de multiprocessing.Queue descrita en el informe.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- operating-systems, performance
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100