Title: Allocate JIT memory in large chunks near the executable · Issue #148822 · python/cpython · GitHub
Open Graph Title: Allocate JIT memory in large chunks near the executable · Issue #148822 · python/cpython
X Title: Allocate JIT memory in large chunks near the executable · Issue #148822 · python/cpython
Description: By allocating JIT memory in large chunks we can reduce the overhead of compilation and possibly speed up the compiled code a bit. Currently, when we need to allocate memory for the JIT, we ask the OS for a sufficiently large chunk of vir...
Open Graph Description: By allocating JIT memory in large chunks we can reduce the overhead of compilation and possibly speed up the compiled code a bit. Currently, when we need to allocate memory for the JIT, we ask the ...
X Description: By allocating JIT memory in large chunks we can reduce the overhead of compilation and possibly speed up the compiled code a bit. Currently, when we need to allocate memory for the JIT, we ask the ...
Opengraph URL: https://github.com/python/cpython/issues/148822
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allocate JIT memory in large chunks near the executable","articleBody":"By allocating JIT memory in large chunks we can reduce the overhead of compilation and possibly speed up the compiled code a bit.\n\nCurrently, when we need to allocate memory for the JIT, we ask the OS for a sufficiently large chunk of virtual memory. This is simple and reasonably efficient. It does have a few flaws:\n1. We need to create DWARF debug info and register it for each trace\n2. We need to make a syscall to get memory for each trace\n3. We have no control over the location of the jitted code, meaning that calls in the executable may need trampolines\n\nBy allocating large chunks we can reduce the overhead of (1) and (2) to once per-chunk, not per trace.\nBy allocating large chunks we can also afford the additional overhead of requesting memory near to the executable.\n\n\nHow it would work:\n\n* When we need memory for jitted code, we request it from our special allocator.\n* When the allocator needs memory, it requests it from the OS, making several requests for it near the executable before accepting an location\n* The allocator itself will be a standard obmalloc/jemalloc style block allocator\n\n### Size classes and fragmentation:\n\nAll jitted code will need to page aligned, so blocks will need to a multiple of the page size.\nWith 4 size classes per power of 2 increase in size (like jemalloc) and assuming 2M chunks we get relatively little internal fragmentation, but potential quite a lot of external fragmentation as there would be around 20 size classes.\nThe external fragmentation can be mitigated by allowing the OS to lazily allocate the pages on demand.\n\n### API\n\nThe _PyObject_VirtualAlloc function will need extending (or a new function added) to allow the desired address to be passed, so the allocator can get blocks near the executable.\n\nThe jit_alloc function's API will be unchanged.\n\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2026-04-21T09:57:39Z","url":"https://github.com/python/cpython/issues/148822"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:2d48ff38-223a-f8a6-672e-f1a411b94a59 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E20E:2AF0D8:38A49B:469FA6:6B01FA70 |
| html-safe-nonce | fc9ca9361c0dad4d155e0ed0c8d91f0ed894c0c0a1c3299f1c8fd8ed2bcdfd7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjBFOjJBRjBEODozOEE0OUI6NDY5RkE2OjZCMDFGQTcwIiwidmlzaXRvcl9pZCI6IjI0NjA0NjA3NTk5MjMxNjE3MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3b1d148baa67991669a343a4a9e9fba150dc12bc58520a2d56d1cb0ff38fe9bd |
| hovercard-subject-tag | issue:4301791138 |
| 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/148822/issue_layout |
| twitter:image | https://opengraph.githubassets.com/21dae614847833e30ac94b0db286633a219c0d16e1be9a679f94c255fa0852d4/python/cpython/issues/148822 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/21dae614847833e30ac94b0db286633a219c0d16e1be9a679f94c255fa0852d4/python/cpython/issues/148822 |
| og:image:alt | By allocating JIT memory in large chunks we can reduce the overhead of compilation and possibly speed up the compiled code a bit. Currently, when we need to allocate memory for the JIT, we ask the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width