gh-132917: Check resident set size (RSS) before GC trigger. (gh-133399)

For the free-threaded build, check the process resident set size (RSS)
increase before triggering a full automatic garbage collection.  If the RSS
has not increased 10% since the last collection then it is deferred.
This commit is contained in:
Neil Schemenauer 2025-05-05 10:17:05 -07:00 committed by GitHub
parent 8e08ac9f32
commit 5c245ffce7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 230 additions and 5 deletions

View file

@ -245,6 +245,16 @@ struct _gc_runtime_state {
/* True if gc.freeze() has been used. */
int freeze_active;
/* Resident set size (RSS) of the process after last GC. */
Py_ssize_t last_rss;
/* This accumulates the new object count whenever collection is deferred
due to the RSS increase condition not being meet. Reset on collection. */
Py_ssize_t deferred_count;
/* Mutex held for gc_should_collect_rss(). */
PyMutex mutex;
#endif
};