Skip to content

gh-114746: Avoid quadratic behavior in free-threaded GC #114817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Jan 31, 2024

The free-threaded build's GC implementation is non-generational, but was scheduled as if it were collecting a young generation leading to quadratic behavior. This increases the minimum threshold and scales it to the number of live objects as we do for the old generation in the default build.

Note that the scheduling is still not thread-safe without the GIL. Those changes will come in later PRs.

A few tests, like "test_sneaky_frame_object" rely on prompt scheduling of the GC. For now, to keep that test passing, we disable the scaled threshold after calls like gc.set_threshold(1, 0, 0).

The free-threaded build's GC implementation is non-generational, but was
scheduled as if it were collecting a young generation leading to
quadratic behavior. This increases the minimum threshold and scales it
to the number of live objects as we do for the old generation in the
default build.

Note that the scheduling is still not thread-safe without the GIL. Those
changes will come in later PRs.

A few tests, like "test_sneaky_frame_object" rely on prompt scheduling
of the GC. For now, to keep that test passing, we disable the scaled
threshold after calls like `gc.set_threshold(1, 0, 0)`.
@colesbury colesbury requested review from encukou and DinoV January 31, 2024 18:48
@colesbury
Copy link
Contributor Author

!buildbot nogil

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 66959ca 🤖

The command will test the builders whose names match following regular expression: nogil

The builders matched are:

  • x86-64 MacOS Intel NoGIL PR
  • x86-64 MacOS Intel ASAN NoGIL PR
  • AMD64 Windows Server 2022 NoGIL PR
  • AMD64 Ubuntu NoGIL Refleaks PR
  • AMD64 Ubuntu NoGIL PR
  • ARM64 MacOS M1 Refleaks NoGIL PR
  • ARM64 MacOS M1 NoGIL PR

@colesbury
Copy link
Contributor Author

@itamaro - I think this fixes the nogil Windows build bot timeouts.

The "Ubuntu NoGIL Refleaks" buildbot still seems quite slow, but I think that was the case before the GC changes.

@encukou
Copy link
Member

encukou commented Feb 1, 2024

Ubuntu refleaks failed with a transient issue, which looks unrelated:

======================================================================
ERROR: test_lockf (__main__.FNTLEINTRTest.test_lockf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/buildarea/pull_request.itamaro-ubuntu-aws.refleak.nogil/build/Lib/test/_test_eintr.py", line 532, in test_lockf
    self._lock(fcntl.lockf, "lockf")
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/buildarea/pull_request.itamaro-ubuntu-aws.refleak.nogil/build/Lib/test/_test_eintr.py", line 517, in _lock
    raise Exception("failed to sync child in %.1f sec" % dt)
Exception: failed to sync child in 300.7 sec

A re-run passed.

But I'm sure the flock issue will come up again, especially when I get around to monitoring re-ran Buildbot tests.
This PR fixes a red buildbot so I'll merge.

@encukou encukou merged commit e6d6d5d into python:main Feb 1, 2024
@encukou
Copy link
Member

encukou commented Feb 1, 2024

Thank you for the quick fix!

@colesbury colesbury deleted the gh-114746-gc branch February 1, 2024 16:36
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…GH-114817)

The free-threaded build's GC implementation is non-generational, but was
scheduled as if it were collecting a young generation leading to
quadratic behavior. This increases the minimum threshold and scales it
to the number of live objects as we do for the old generation in the
default build.

Note that the scheduling is still not thread-safe without the GIL. Those
changes will come in later PRs.

A few tests, like "test_sneaky_frame_object" rely on prompt scheduling
of the GC. For now, to keep that test passing, we disable the scaled
threshold after calls like `gc.set_threshold(1, 0, 0)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants