Skip to content

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

Merged
corona10 merged 5 commits into
python:mainfrom
corona10:gh-115103-refleak
Mar 2, 2024
Merged

corona10 merged 5 commits into
python:mainfrom
corona10:gh-115103-refleak

Conversation

@corona10

@corona10 corona10 commented Mar 2, 2024 •

Copy link
Copy Markdown
Member
@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

!buildbot nogil

@bedevere-bot

Copy link
Copy Markdown

🤖 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
Comment thread Lib/test/support/__init__.py Resolved
@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

!buildbot nogil

@bedevere-bot

Copy link
Copy Markdown

🤖 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

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author
Comment thread Modules/gcmodule.c Resolved
Comment thread Modules/gcmodule.c Resolved
Comment thread Modules/clinic/gcmodule.c.h Resolved
@corona10
corona10 requested a review from pablogsal March 2, 2024 13:24

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

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).

Comment thread Python/gc_free_threading.c Resolved
Comment thread Python/gc_free_threading.c Resolved
@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

Yeah more better!

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

@pablogsal Do you have any comments?

_PyEval_StopTheWorld(interp);
// merge refcounts for all queued objects
merge_all_queued_objects(interp, state);
process_delayed_frees(interp);

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@corona10
corona10 deleted the gh-115103-refleak branch March 2, 2024 21:44
@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

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 Mar 2, 2024
@corona10

corona10 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

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

corona10 commented Mar 2, 2024 •

Copy link
Copy Markdown
Member Author

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

4 participants