Support custom initialization hook in `mi_process_init`

Aberta
#1,508 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

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

Direção de pesquisa

Start by reading mi_process_init_once and the existing process initialization and OS memory management paths in mimalloc. The issue proposes a compile-time hook but leaves its placement and interaction with memory allocation options open, so first evaluate those constraints and discuss the design with maintainers. Done would mean an agreed hook design with a working example and tests showing initialization can use a caller-provided pool without fetching additional OS memory.

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

Descrição

This question is similar to #1218 and #1228 (thank you for the fixes!!) in that we want to preallocate a fixed pool for mimalloc to use (and never ask the OS for more). Since our process can potentially malloc() before main (dynamic libs, etc) we need to set up our pool when that first allocation happens. It looks like the right place to do this would be towards the end of mi_process_init_once instead of fetching OS memory.

Since application code doesn't call mi_process_init directly, I think this would have to be a compile/link time thing, something like

static void mi_process_init_once(void) {
    ...

#ifdef MI_PROCESS_INIT_HOOK
    extern void MI_PROCESS_INIT_HOOK(void);
    MI_PROCESS_INIT_HOOK();
#endif
}

We compile the mimalloc staticlib with MI_PROCESS_INIT_HOOK=our_pool_setup and link it to the real function that mmap()s the pool, calls mi_manage_os_memory_ex(), and mi_option_set(). (Maybe the hook goes before the function tries to fetch OS memory?)

Is mimalloc open to upstreaming an idea like this? I can submit a PR once we have it working but I wanted to see if there's any alternative I'm missing or reasons that this wouldn't work.

Linguagem predominante
C
Estrelas
13.6k
Forks
1.2k
Merge médio
18h 12min
PRs com merge (30d)
20

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

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.

Mais de microsoft/mimalloc

Todas as issues de microsoft/mimalloc

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

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