GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-115103: Delay reuse of mimalloc pages that store PyObjects by colesbury · Pull Request #115435 · python/cpython Conversation
|
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 99bd660 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a few nits really...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| mi_page_t *page = llist_data(node, mi_page_t, qsbr_node); | ||
| if (!mi_page_all_free(page)) { | ||
| // We allocated from this page some point after the delayed free | ||
| page->qsbr_goal = 0; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: Seems like we could consistently use _PyMem_mi_page_clear_qsbr?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return; | ||
| } | ||
|
|
||
| page->qsbr_goal = 0; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_PyMem_mi_page_clear_qsbr?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (!_Py_qbsr_goal_reached(tstate->qsbr, page->qsbr_goal)) { | ||
| return false; | ||
| } | ||
| _PyMem_mi_page_clear_qsbr(page); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This side effect seems surprising given the name of the function... It seems like it'd be better to call _PyMem_mi_page_clear_qsbr explicitly in mi_segment_page_clear and _PyMem_mi_page_maybe_free
Sorry, something went wrong.
There was an error while loading. Please reload this page.
99bd660 to
1645d3a
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've rebased now that #116343 landed.
mi_segment_reclaim). Large pages only contain a single block. Prior to this PR, they were either empty and freed immediately on reclamation or full and so didn't set right_page_reclaimed. The right_page_reclaimed logic doesn't handle large pages properly because large pages use a different allocation code path than small and medium pages. This means we have slightly worse re-use than we'd like when reclaiming large pages, but at least it's correct now._PyMem_mi_page_is_safe_to_free to only handle reclaimed pages, instead of also _PyMem_mi_page_maybe_free case. The qsbr_goal == 0 has different implications in the two cases. When reclaiming an abandoned page, qsbr_goal == 0 means that we can free it immediately, while in mi_heap_page_collect it means that we haven't started the QSBR process._mi_page_retire should clear the previous QSBR goal, if one exists (since we just freed a block).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 1645d3a 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 3453eb9 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The failed buildbot looks unrelated to this PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
CC @daanx |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ython#115435) This implements the delayed reuse of mimalloc pages that contain Python objects in the free-threaded build. Allocations of the same size class are grouped in data structures called pages. These are different from operating system pages. For thread-safety, we want to ensure that memory used to store PyObjects remains valid as long as there may be concurrent lock-free readers; we want to delay using it for other size classes, in other heaps, or returning it to the operating system. When a mimalloc page becomes empty, instead of immediately freeing it, we tag it with a QSBR goal and insert it into a per-thread state linked list of pages to be freed. When mimalloc needs a fresh page, we process the queue and free any still empty pages that are now deemed safe to be freed. Pages waiting to be freed are still available for allocations of the same size class and allocating from a page prevent it from being freed. There is additional logic to handle abandoned pages when threads exit.
…ython#115435) This implements the delayed reuse of mimalloc pages that contain Python objects in the free-threaded build. Allocations of the same size class are grouped in data structures called pages. These are different from operating system pages. For thread-safety, we want to ensure that memory used to store PyObjects remains valid as long as there may be concurrent lock-free readers; we want to delay using it for other size classes, in other heaps, or returning it to the operating system. When a mimalloc page becomes empty, instead of immediately freeing it, we tag it with a QSBR goal and insert it into a per-thread state linked list of pages to be freed. When mimalloc needs a fresh page, we process the queue and free any still empty pages that are now deemed safe to be freed. Pages waiting to be freed are still available for allocations of the same size class and allocating from a page prevent it from being freed. There is additional logic to handle abandoned pages when threads exit.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.