python / python/cpython

Inc GC in 3.14t can defer too much, resulting in high memory use

オープン
#148,937 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core performance topic-free-threading type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

In the process of testing the default build incremental GC, I noticed a problem with the 3.14t GC. Shortly before the 3.14.0 release, I added some additional logic to defer GC triggering if the process memory use has not increased by 10% since the last collection. Unfortunately that does not work well with how mimalloc handles memory. It does not promptly return memory to the OS or mark pages as unused (e.g. with madvise). So, the process size from the point of view of the OS does not decrease after the GC frees cyclic trash.

For programs that create even modest amounts of cyclic garbage, this is a major problem. It acts as if the GC threshold has been set to 40x the "threshold0" value. By default, that means full GC collection every 80,000 net new objects. This is not a continuous memory leak but it means the process uses uses way more memory than it should.

The simple fix would be to just remove that process size based defer. However, that would result in regressing on the GH-132917 issue, so I wouldn't recommend that. I have a fairly simple fix that "asks mimalloc" how much memory is being used, rather than asking the OS. Based on my testing, that works well.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-148940
  • gh-149371
  • gh-149475

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まずリンクされている PR gh-148940、gh-149371、gh-149475 を確認し、次に Linux 上での 3.14 のインクリメンタル GC におけるプロセスサイズベースの延期を追跡してください。そのメモリ使用量チェックを mimalloc が報告する使用量と比較し、レポートで説明されている過剰なメモリ増加なしに循環ガベージが収集されることを検証してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
performance
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。