Support custom initialization hook in `mi_process_init`

Offen
#1,508 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
c
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
C
Sterne
13.6k
Forks
1.2k
Ø Merge
18 Std. 12 Min.
Gemergte PRs (30 T.)
20

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoft/mimalloc

Alle Issues in microsoft/mimalloc

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.