python / python/cpython

Allocate JIT memory in large chunks near the executable

Abierto
#148,822 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core topic-JIT type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza rastreando la ruta de asignación de JIT a través de _PyObject_VirtualAlloc y jit_alloc; después, revisa el comportamiento existente de asignación de memoria virtual. El trabajo estará completo cuando la memoria de JIT se obtenga de fragmentos grandes alineados con páginas cerca del ejecutable, con un registro DWARF por fragmento y la API de jit_alloc sin cambios.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, python
Área
compilers, performance
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.