python / python/cpython

Allocate JIT memory in large chunks near the executable

Aberta
#148,822 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core topic-JIT type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece rastreando o caminho de alocação do JIT por _PyObject_VirtualAlloc e jit_alloc; em seguida, revise o comportamento existente de alocação de memória virtual. O trabalho estará concluído quando a memória do JIT for obtida de grandes blocos alinhados a páginas próximos ao executável, com registro DWARF por bloco e a API jit_alloc inalterada.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
c, python
Domínio
compilers, performance
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.