Code Monkey home page Code Monkey logo

Comments (4)

daanx avatar daanx commented on June 2, 2024

Hi @Zoxc -- thanks for bringing this up; I think it is not a bug but nevertheless I agree the naming and use is inconsistent. In particular, the name MI_HUGE_BLOCK_SIZE is confusing as it is just a large value used in xblock_size to signify that we need to calculate the block size from the segment size (for very large allocations). But it is orthogonal to the block actually being huge as > MI_LARGE_OBJ_SIZE_MAX. And as you saw, the MI_BIN_HUGE can contain either huge or large blocks. This really need to be fixed/clarified.

I will go through and rename some of these and add further comments, and check for possible bugs in particular for blocksizes around MI_LARGE_OBJ_SIZE_MAX (on first glance it looks actually ok though)
Thanks!

from mimalloc.

Zoxc avatar Zoxc commented on June 2, 2024

The specific case I'm worried about is when creating a huge page for an allocation with small size and high alignment.

When allocating it will use unconditionally use MI_HUGE_OBJ_SIZE_MAX to pick the queue to use, but when freeing using mi_page_queue_of it will instead use page->xblock_size which will result in a different queue.

I'm also kind of wondering why MI_HUGE_OBJ_SIZE_MAX isn't 0 or -1 if it just represents an unknown block size?

from mimalloc.

daanx avatar daanx commented on June 2, 2024

Ah I see. Just to clarify, you mean MI_HUGE_BLOCK_SIZE instead of MI_HUGE_OBJ_SIZE_MAX. (since dev-slice uses a different value for MI_HUGE_BLOCK_SIZE (I should make this consistent as well)).

Hmm, I think you are right but I need to look into it in more detail. I consider it a bug but I think it actually works as it is because such special huge allocation with a small size but large alignment will always consist of a single block in a single page and thus it will be in the BIN_FULL queue when it is freed which is checked for in mi_page_queue_of. So, I think it actually works, but still, it would be better to maintain a stronger invariant. I need to think about this a bit more.

There is no special reason I think to not use ~0 (as it is unsigned) -- maybe 0 is used already for uninitialized pages.

btw. nice you try to rewrite this in Rust !

from mimalloc.

daanx avatar daanx commented on June 2, 2024

Thanks for the feedback; I made various improvements including an is_huge field in the page to ensure the correct page queue is used.

from mimalloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.