python / python/cpython

Allocate JIT memory in large chunks near the executable

Đang mở
#148,822 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

interpreter-core topic-JIT type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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:

  1. We need to create DWARF debug info and register it for each trace
  2. We need to make a syscall to get memory for each trace
  3. 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách lần theo đường dẫn cấp phát JIT qua _PyObject_VirtualAlloc và jit_alloc, sau đó xem xét hành vi cấp phát bộ nhớ ảo hiện có. Công việc hoàn tất khi bộ nhớ JIT được lấy từ các chunk lớn, căn chỉnh theo trang ở gần tệp thực thi, với đăng ký DWARF cho từng chunk và API jit_alloc không thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, python
Lĩnh vực
compilers, performance
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.