Skip to content

Linux (maybe macOS) self-deadlock in v3.3.0 with MI_SECURE>=4 on large aligned allocation #1272

Description

@chirizxc

On Linuxx86_64 and it seems on macOS, mimalloc v3.3.0 hangs with MI_SECURE=4 and MI_SECURE=5 on a large aligned allocation.

MRE:

#include <stdio.h>
#include "mimalloc.h"

int main(void) {
  void* p = mi_malloc_aligned(1 << 20, 32);
  if (p == NULL) return 1;
  mi_free(p);
  return 0;
}
cc -Iinclude -DMI_SECURE=4 -o repro repro.c src/static.c -lpthread ./repro
# or cc -Iinclude -DMI_SECURE=5 -o repro repro.c src/static.c -lpthread ./repro

GDB shows a self-deadlock:

  • mi_arenas_try_alloc holds subproc->arena_reserve_lock
  • secure path in _mi_os_get_aligned_hint calls mi_theap_get_default()
  • this re-enters mi_thread_init()
  • thread init allocates metadata
  • allocation re-enters mi_arenas_try_alloc
  • same thread blocks again on arena_reserve_lock

Relevant frames:

  • mi_lock_acquire in include/mimalloc/atomic.h
  • mi_arenas_try_alloc in src/arena.c
  • _mi_os_get_aligned_hint in src/os.c
  • _mi_thread_init_theap_default / mi_thread_init in src/init.c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions