microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.44k stars 842 forks source link

Multiple large pages per segment cause `mi_segment_insert_in_free_queue` to fail #870

Closed Zoxc closed 6 months ago

Zoxc commented 6 months ago

There seems to be an unspoken assumption that a large page fills an entire segment like huge pages, otherwise mi_segment_insert_in_free_queue could end up being called which doesn't handle large pages.

daanx commented 6 months ago

Yes, in dev (1.x versions), a large page always is the only page in a segment. (Huge pages are also a single page in a segment but the segment size can be different than MI_SEGMENT_SIZE. ). As such, mi_segment_insert_in_free_queue won't be called for large pages. I will push soon a commit that adds an extra runtime check beyond the assertion in segment.c:748.

As an aside, if you plan to rewrite in Rust, I would encourage you to look at dev-slice instead (2.x versions) which has a different segment layout where large, medium, and small pages can be mixed inside a segment. This also has fine-grained purging of OS pages inside segments which is good for long running services.