summaryrefslogtreecommitdiffstats
path: root/Python/qsbr.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] Fix typos in comments (GH-120481) (#120774)Miss Islington (bot)2024-06-201-2/+2
| | | | | (cherry picked from commit 656a1c81083b76b9d998c983f4329348a65985d3) Co-authored-by: Xie Yanbo <xieyanbo@gmail.com>
* [3.13] gh-117657: Fix TSAN race in QSBR assertion (GH-119887) (#119904)Miss Islington (bot)2024-06-011-1/+2
| | | | | | | Due to a limitation in TSAN, all reads from `PyThreadState.state` must be atomic to avoid reported races. (cherry picked from commit 90ec19fd33e2452902b9788d4821f1fbf6542304) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-119369: Fix deadlock during thread exit in free-threaded build ↵Miss Islington (bot)2024-05-311-0/+5
| | | | | | | | | | | | (GH-119528) (#119868) Release the GIL before calling `_Py_qsbr_unregister`. The deadlock could occur when the GIL was enabled at runtime. The `_Py_qsbr_unregister` call might block while holding the GIL because the thread state was not active, but the GIL was still held. (cherry picked from commit 078b8c8cf2bf68f7484cc4d2e3dd74b6fab55664) Co-authored-by: Sam Gross <colesbury@gmail.com>
* [3.13] gh-117657: Fix QSBR race condition (GH-118843) (#118905)Miss Islington (bot)2024-05-101-5/+6
| | | | | | | | | `_Py_qsbr_unregister` is called when the PyThreadState is already detached, so the access to `tstate->qsbr` isn't safe without locking the shared mutex. Grab the `struct _qsbr_shared` from the interpreter instead. (cherry picked from commit 33d20199af65c741bdc908a968edd8dc179b6974) Co-authored-by: Alex Turner <alexturner@meta.com>
* gh-115103: Fix unregistering of QSBR state (#116480)Sam Gross2024-03-081-3/+7
| | | | | If a thread blocks while waiting on the `shared->mutex` lock, the array of QSBR states may be reallocated. The `tstate->qsbr` values before the lock is acquired may not be the same as the value after the lock is acquired.
* gh-115103: Delay reuse of mimalloc pages that store PyObjects (#115435)Sam Gross2024-03-061-10/+2
| | | | | | | | | | | | | | | | | | 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.
* gh-115103: Implement delayed memory reclamation (QSBR) (#115180)Sam Gross2024-02-161-0/+286
This adds a safe memory reclamation scheme based on FreeBSD's "GUS" and quiescent state based reclamation (QSBR). The API provides a mechanism for callers to detect when it is safe to free memory that may be concurrently accessed by readers.