Title: mimalloc: additional integration and changes for `--disable-gil` builds · Issue #112532 · python/cpython · GitHub
Open Graph Title: mimalloc: additional integration and changes for `--disable-gil` builds · Issue #112532 · python/cpython
X Title: mimalloc: additional integration and changes for `--disable-gil` builds · Issue #112532 · python/cpython
Description: Feature or enhancement Mimalloc was added as an allocator in #90815. The --disable-gil builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-safe garbage collection in --disable-gil bu...
Open Graph Description: Feature or enhancement Mimalloc was added as an allocator in #90815. The --disable-gil builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-saf...
X Description: Feature or enhancement Mimalloc was added as an allocator in #90815. The --disable-gil builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-saf...
Opengraph URL: https://github.com/python/cpython/issues/112532
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mimalloc: additional integration and changes for `--disable-gil` builds","articleBody":"# Feature or enhancement\r\n\r\nMimalloc was added as an allocator in https://github.com/python/cpython/issues/90815. The `--disable-gil` builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-safe garbage collection in `--disable-gil` builds and the dictionary accesses that mostly avoid locking.\r\n\r\nThese changes can be split up across multiple PRs.\r\n\r\n* Currently, when mimalloc is enabled, all allocations go to the default heap. This is fine for `PyMem_Malloc` calls, but we need separate heaps for `PyObject_Malloc` and `PyObject_GC_New`. We should associate some `mi_heap_t`s with each `PyThreadState`. Every PyThreadState needs four heaps: one for PyMem_Malloc, one for non-GC objects (via PyObject_Malloc), one for GC objects with managed dicts (extra pre-header) and one for GC objects without a managed dict. We need some way to know which heap to use in `_PyObject_MiMalloc`. There's not a great way to do this, but I suggest adding something like a [\"current pyobject heap\"](https://github.com/colesbury/nogil-3.12/blob/cedde4f5ec3759ad723c89d44738776f362df564/Include/cpython/pystate.h#L127) variable to PyThreadState. It should generally point to the `PyObject_Malloc` heap, but `PyObject_GC_New` should temporarily override it to point to the correct GC heap when called\r\n* `--disable-gil` should imply `--with-mimalloc` and require mimalloc (i.e., disallow changing the allocator with `PYTHONMALLOC`).\r\n* We should tag each mi_heap_t and mi_page_t with a number identifying which type of allocation it's associated with. This is important for when pages are abandoned (i.e., when a thread exits with live blocks remaining) and the page is no longer associated with a heap. The GC still needs to identify which of those pages store GC-enabled objects. (see https://github.com/colesbury/nogil-3.12/commit/d447b6980856df7e0050ecaba4fd6cf21747d4f2)\r\n* When claiming a page from an abandoned segment, mimalloc should associate it with the correct heap from the current thread. In other words, pages that store GC-enabled objects should only be put back in the correct GC heap.\r\n\r\ncc @DinoV \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-112883\n* gh-113263\n* gh-113492\n* gh-113717\n* gh-113742\n* gh-113995\n* gh-114133\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2023-11-29T18:22:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/112532/cpython/issues/112532"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4450e34e-26ec-c360-ad83-5b0db3acf11a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 90F6:B17C5:A7709A:E739A4:6965006A |
| html-safe-nonce | 8466418dfdf14956e7beb9568f6c2622b8c67a6294970c4075556fd0d61c3be9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEY2OkIxN0M1OkE3NzA5QTpFNzM5QTQ6Njk2NTAwNkEiLCJ2aXNpdG9yX2lkIjoiNTg2MjYyMjgxMDI1NTcyMDU1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c0f18a07162a51fb4d956df6d044a19168f792addf9109000ce333e4e43a8cd4 |
| hovercard-subject-tag | issue:2017172559 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/112532/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aedaea918383d25e45d54fbdaa3dbe2830eb0034b8c494806a826624163e5c2d/python/cpython/issues/112532 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aedaea918383d25e45d54fbdaa3dbe2830eb0034b8c494806a826624163e5c2d/python/cpython/issues/112532 |
| og:image:alt | Feature or enhancement Mimalloc was added as an allocator in #90815. The --disable-gil builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-saf... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | colesbury |
| hostname | github.com |
| expected-hostname | github.com |
| None | 409eef8307c7b2774ef22b51d9c9bea7aae00b7c42378f10825b0de95e35b3d8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0f2726e2829a4524ee45b32f55dabe51189d33b0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width