@@ -26,7 +26,7 @@ for threads to report this state.
2626While CPython's memory management is dominated by reference counting and a
2727tracing garbage collector, these mechanisms are not suitable for all data
2828structures. For example, the backing array of a list object is not individually
29- reference-counted but may have a shorter lifetime than the PyListObject that
29+ reference-counted but may have a shorter lifetime than the ` PyListObject `  that
3030contains it. We could delay reclamation until the next GC run, but we want
3131reclamation to be prompt and to run the GC less frequently in the free-threaded
3232build, as it requires pausing all threads.
@@ -39,7 +39,7 @@ mechanism to determine when it is safe to free the list's old backing array.
3939
4040Specific use cases for QSBR include:
4141
42- *  Dictionary keys (PyDictKeysObject) and list arrays (` _PyListArray ` ): When a
42+ *  Dictionary keys (` PyDictKeysObject ` ) and list arrays (` _PyListArray ` ): When a
4343dictionary or list that may be shared between threads is resized, we use QSBR
4444to delay freeing the old keys or array until it's safe. For dicts and lists
4545that are not shared, their storage can be freed immediately upon resize.
@@ -58,12 +58,13 @@ page or return its memory to the OS.
5858
5959### Core Implementation  
6060
61- The proposal to add QSBR to Python is contained in Github issue 115103 [ ^ 1 ] .
61+ The proposal to add QSBR to Python is contained in [ Github issue 115103] 
62+ (https://github.com/python/cpython/issues/115103 ).
6263Many details of that proposal have been copied here, so they can be kept
6364up-to-date with the actual implementation.
6465
6566Python's QSBR implementation is based on FreeBSD's "Global Unbounded
66- Sequences." [ 2, 3, 4 ] .  It relies on a few key counters:
67+ Sequences." [ ^1, ^2, ^3 ] .  It relies on a few key counters:
6768
6869*  Global Write Sequence (` wr_seq ` ): A per-interpreter counter, ` wr_seq ` , is started
6970at 1 and incremented by 2 each time it is advanced. This ensures its value is
@@ -92,7 +93,7 @@ Periodically, a polling mechanism processes this deferred-free list:
9293   stored as the global ` rd_seq ` .
9394
94952 .  For each item on the deferred-free list, if its qsbr_goal is less than or
95-    equal to the new ` rd_seq ` , its memory is freed, and it is removed from the
96+    equal to the new ` rd_seq ` , its memory is freed, and it is removed from the: 
9697   list. Otherwise, it remains on the list for a future attempt.
9798
9899
@@ -123,7 +124,6 @@ multi-threaded benchmarks reveal performance issues.
123124
124125## References  
125126
126- [ ^ 1 ] : https://github.com/python/cpython/issues/115103 
127- 2 .  https://youtu.be/ZXUIFj4nRjk?t=694 
128- 3 .  https://people.kernel.org/joelfernandes/gus-vs-rcu 
129- 4 .  http://bxr.su/FreeBSD/sys/kern/subr_smr.c#44 
127+ [ ^ 1 ] : https://youtu.be/ZXUIFj4nRjk?t=694 
128+ [ ^ 2 ] : https://people.kernel.org/joelfernandes/gus-vs-rcu 
129+ [ ^ 3 ] : http://bxr.su/FreeBSD/sys/kern/subr_smr.c#44 
0 commit comments