You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GC does not scale well with a lot of objects created in destructor #13670
changed the title [-]GC does not scale well with a lot of isolated cycles[/-][+]GC does not scale well with a lot of objects created in destructor[/+]on Mar 11, 2024
This is triggering some edge case where collection does not decrease the number of roots (because garbage is created in destructors), and the GC threshold is not updated because this does not match heuristics. As a result, num_roots is permanently greater than gc_threadshold, so collections are run every time we create potential garbage.
I think we need to update the condition here to look at the decrease of num_roots rather than the number of collected roots:
diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c
index 572e3b66fd4..08634c29424 100644
--- a/Zend/zend_gc.c+++ b/Zend/zend_gc.c@@ -604,11 +604,12 @@ static void gc_grow_root_buffer(void)
static void gc_adjust_threshold(int count)
{
uint32_t new_threshold;
+ uint32_t old_num_roots = GC_G(num_roots);
/* TODO Very simple heuristic for dynamic GC buffer resizing:
* If there are "too few" collections, increase the collection threshold
* by a fixed step */
- if (count < GC_THRESHOLD_TRIGGER) {+ if (GC_G(num_roots) > old_num_roots || (old_num_roots - GC_G(num_roots)) < GC_THRESHOLD_TRIGGER) {
/* increase */
if (GC_G(gc_threshold) < GC_THRESHOLD_MAX) {
new_threshold = GC_G(gc_threshold) + GC_THRESHOLD_STEP;
This fixes the issue, but I need to think more about it.
Activity
[-]Segfault when GC is put on limits[/-][+]Segfault when GC/destructors are put on limits[/+][-]Segfault when GC/destructors are put on limits[/-][+]Segfault when GC/destructors are put on their limits[/+][-]Segfault when GC/destructors are put on their limits[/-][+]GC does not scale well[/+][-]GC does not scale well[/-][+]GC does not scale well with a lot of isolated cycles[/+][-]GC does not scale well with a lot of isolated cycles[/-][+]GC does not scale well with a lot of objects created in destructor[/+]arnaud-lb commentedon Mar 11, 2024
This is triggering some edge case where collection does not decrease the number of roots (because garbage is created in destructors), and the GC threshold is not updated because this does not match heuristics. As a result, num_roots is permanently greater than gc_threadshold, so collections are run every time we create potential garbage.
I think we need to update the condition here to look at the decrease of
num_rootsrather than the number of collected roots:This fixes the issue, but I need to think more about it.
arnaud-lb commentedon Mar 25, 2024
Fixed by #13758
mvorisek commentedon Mar 25, 2024
Thank you!