Skip to content

suggestion: improve runtime complexity of mi_heap_collect_ex #1220

@romange

Description

@romange

Context

mimalloc v2.2.4+ added automatic collection of freed pages every generic_collect operations which is great.
Unfortunately, it greatly affects p99.9/max latency of allocations even for a stable workload.

Detailed analysis

mi_heap_collect_ex calls mi_heap_visit_pages(heap, &mi_heap_page_collect, &collect, NULL); which goes over ALL page queues including MI_BIN_FULL. Consider a "happy" situation where we allocated 30GB of memory on a heap and most of its pages are full. MI_BIN_FULL will consists of dozens of thousands of pages that will be traversed upon each invocation of mi_heap_visit_pages and to my mind absolutely for nothing - by definition of MI_BIN_FULL queue.

Suggestion

Add max_queue_id argument to mi_heap_visit_pages that will limit the traversal of page queues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions