Skip to content

Commit d960cbb

Browse files
committed
Fix TSAN warnings, improve comments.
1 parent 53e5e9b commit d960cbb

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

Python/gc_free_threading.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,27 +2055,29 @@ gc_should_collect_mem_usage(GCState *gcstate)
20552055
int threshold = gcstate->young.threshold;
20562056
Py_ssize_t deferred = _Py_atomic_load_ssize_relaxed(&gcstate->deferred_count);
20572057
if (deferred > threshold * 40) {
2058-
// Too many new container objects since last GC, even though RSS
2058+
// Too many new container objects since last GC, even though memory use
20592059
// might not have increased much. This is intended to avoid resource
20602060
// exhaustion if some objects consume resources but don't result in a
2061-
// RSS increase. We use 40x as the factor here because older versions
2062-
// of Python would do full collections after roughly every 70,000 new
2063-
// container objects.
2061+
// memory usage increase. We use 40x as the factor here because older
2062+
// versions of Python would do full collections after roughly every
2063+
// 70,000 new container objects.
20642064
return true;
20652065
}
20662066
Py_ssize_t last_mem = gcstate->last_mem;
20672067
Py_ssize_t mem_threshold = Py_MAX(last_mem / 10, 128);
20682068
if ((mem - last_mem) > mem_threshold) {
2069-
// The RSS has increased too much, do a collection.
2069+
// The process memory usage has increased too much, do a collection.
20702070
return true;
20712071
}
20722072
else {
2073-
// The RSS has not increased enough, defer the collection and clear
2074-
// the young object count so we don't check RSS again on the next call
2075-
// to gc_should_collect().
2073+
// The memory usage has not increased enough, defer the collection and
2074+
// clear the young object count so we don't check memory usage again
2075+
// on the next call to gc_should_collect().
20762076
PyMutex_Lock(&gcstate->mutex);
2077-
gcstate->deferred_count += gcstate->young.count;
2078-
gcstate->young.count = 0;
2077+
_Py_atomic_store_ssize_relaxed(&gcstate->deferred_count,
2078+
gcstate->deferred_count +
2079+
gcstate->young.count);
2080+
_Py_atomic_store_int(&gcstate->young.count, 0);
20792081
PyMutex_Unlock(&gcstate->mutex);
20802082
return false;
20812083
}

0 commit comments

Comments
 (0)