Allocate JIT memory in large chunks near the executable
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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 virtual memory. This is simple and reasonably efficient. It does have a few flaws:
- We need to create DWARF debug info and register it for each trace
- We need to make a syscall to get memory for each trace
- We have no control over the location of the jitted code, meaning that calls in the executable may need trampolines
By allocating large chunks we can reduce the overhead of (1) and (2) to once per-chunk, not per trace.
By allocating large chunks we can also afford the additional overhead of requesting memory near to the executable.
How it would work:
- When we need memory for jitted code, we request it from our special allocator.
- When the allocator needs memory, it requests it from the OS, making several requests for it near the executable before accepting an location
- The allocator itself will be a standard obmalloc/jemalloc style block allocator
Size classes and fragmentation:
All jitted code will need to page aligned, so blocks will need to a multiple of the page size.
With 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.
The external fragmentation can be mitigated by allowing the OS to lazily allocate the pages on demand.
API
The _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.
The jit_alloc function's API will be unchanged.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪通过 _PyObject_VirtualAlloc 和 jit_alloc 的 JIT 分配路径,然后检查现有的虚拟内存分配行为。当 JIT 内存从可执行文件附近的大型页对齐块中获取、每个块都进行 DWARF 注册且 jit_alloc API 保持不变时,这项工作就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- compilers, performance
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100