Commit d76df75
authored
Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:
1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
when relying on QSBR to defer freeing the page. Pages in the full
queue are never searched by mi_page_queue_find_free_ex(), so a page
left there is unusable for allocations.
2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
_mi_page_thread_free_collect() where it only fires when all blocks
on the page are free (used == 0). The previous placement was too
broad: it cleared QSBR state whenever local_free was non-NULL, but
_mi_page_free_collect() is called from non-allocation paths (e.g.,
page visiting in mi_heap_visit_blocks) where the page is not being
reused.
3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
correct thread state for QSBR list insertion instead of
PyThreadState_GET(). During stop-the-world pauses, the function may
process pages belonging to other threads, so the current thread
state is not necessarily the owner of the page.
1 parent 171133a commit d76df75
File tree
5 files changed
+40
-10
lines changed- Misc/NEWS.d/next/Core_and_Builtins
- Objects
- mimalloc
5 files changed
+40
-10
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
| |||
225 | 232 | | |
226 | 233 | | |
227 | 234 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1286 | 1286 | | |
1287 | 1287 | | |
1288 | 1288 | | |
| 1289 | + | |
1289 | 1290 | | |
1290 | 1291 | | |
1291 | 1292 | | |
| |||
1361 | 1362 | | |
1362 | 1363 | | |
1363 | 1364 | | |
| 1365 | + | |
1364 | 1366 | | |
1365 | 1367 | | |
1366 | 1368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
| |||
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
162 | | - | |
163 | | - | |
| 168 | + | |
| 169 | + | |
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
169 | 184 | | |
170 | 185 | | |
171 | 186 | | |
172 | | - | |
173 | | - | |
| 187 | + | |
| 188 | + | |
174 | 189 | | |
175 | 190 | | |
176 | | - | |
| 191 | + | |
177 | 192 | | |
178 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
179 | 197 | | |
180 | 198 | | |
181 | 199 | | |
| |||
192 | 210 | | |
193 | 211 | | |
194 | 212 | | |
195 | | - | |
| 213 | + | |
| 214 | + | |
196 | 215 | | |
197 | 216 | | |
198 | 217 | | |
| |||
0 commit comments