Memory held for too long by the BRC queue while the owning thread is detached
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 没有指定文件或测试。首先跟踪 free-threaded BRC queue 以及从 detached 到 suspended 的转换,然后检查 GC 如何排出队列中的对象。完成的标准是,queueing thread 可以为 detached owner 合并引用并释放对象,而无需等待该 owner 运行 Python 代码;使用报告中描述的 multiprocessing.Queue 工作负载进行验证。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems, performance
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100