Skip to content
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

gh-115103: Update gc.collect to process delayed objects #116238

Merged
merged 5 commits into from
Mar 2, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Mar 2, 2024

@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

!buildbot nogil

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @corona10 for commit c28c79f 🤖

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

The builders matched are:

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

Lib/test/support/__init__.py Outdated Show resolved Hide resolved
@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

!buildbot nogil

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @corona10 for commit 81f333a 🤖

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

The builders matched are:

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

@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

See #115875 (comment)

Modules/gcmodule.c Outdated Show resolved Hide resolved
Modules/gcmodule.c Outdated Show resolved Hide resolved
Modules/clinic/gcmodule.c.h Outdated Show resolved Hide resolved
@corona10 corona10 requested a review from pablogsal March 2, 2024 13:24
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this as part of the normal gc.collect() instead of adding a separate call. We want gc.collect() to be the go-to way to ensuring that things that should be freed are freed -- we already empty freelists and merge refcounts and will probably have a few more similar tasks in the near future (like collecting shared dictionary keys).

Python/gc_free_threading.c Outdated Show resolved Hide resolved
Python/gc_free_threading.c Outdated Show resolved Hide resolved
@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

Yeah more better!

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

@pablogsal Do you have any comments?

@@ -1006,6 +1023,7 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state)
_PyEval_StopTheWorld(interp);
// merge refcounts for all queued objects
merge_all_queued_objects(interp, state);
process_delayed_frees(interp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit/question: _PyEval_StopTheWorld also locks _PyRuntime. Maybe is worth moving the lock up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_PyEval_StopTheWorld locks _PyRuntime temporarily to loop over threads, but does not hold the lock

We want process_delayed_frees after the stop-the-world call because it guarantees that we can free all the "delayed free" pointers. If we moved it up before the _PyEval_StopTheWorld there might be some memory blocks we don't free.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for clarifying

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we moved it up before the _PyEval_StopTheWorld there might be some memory blocks we don't free.

With "moving the lock up" i meant to have a unique locking for both functions, not to move this call before the other. But your comment still applies

@corona10 corona10 merged commit 2e91578 into python:main Mar 2, 2024
34 checks passed
@corona10 corona10 deleted the gh-115103-refleak branch March 2, 2024 21:44
@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

Nah I forgot the change the PR title :( anyway, I merged.

@corona10 corona10 changed the title gh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed gh-115103: Update gc.collect to process delayed objects Mar 2, 2024
@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

I left the comment about commit title for the future tracker: #115103 (comment)

corona10 added a commit to corona10/cpython that referenced this pull request Mar 2, 2024
corona10 added a commit that referenced this pull request Mar 2, 2024
* Revert "gh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed (gh-116238)"

This reverts commit 2e91578.

* gh-115103: Update gc.collect to process delayed objects
@corona10
Copy link
Member Author

corona10 commented Mar 2, 2024

I tried to fix the commit title for tracking with the double revert technique but it doesn't work for git blame: d1fd060

Let's forget about it :(

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
…gh-116251)

* Revert "pythongh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed (pythongh-116238)"

This reverts commit 2e91578.

* pythongh-115103: Update gc.collect to process delayed objects
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…gh-116251)

* Revert "pythongh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed (pythongh-116238)"

This reverts commit 2e91578.

* pythongh-115103: Update gc.collect to process delayed objects
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…gh-116251)

* Revert "pythongh-115103: Update refleak checker to trigger _PyMem_ProcessDelayed (pythongh-116238)"

This reverts commit 2e91578.

* pythongh-115103: Update gc.collect to process delayed objects
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.

4 participants