Code Monkey home page Code Monkey logo

Comments (6)

romange avatar romange commented on June 2, 2024

In fact, mi_heap_malloc_zero_aligned_at always goes through the same route:

  1. tries to allocate 160 bytes page, reaches _mi_page_empty
  2. checks that it's empty and goes through the flow that allocates a 192 block in 192 bytes page.
  3. The next 160 byte allocation will again hit an empty page and will follow the same route.

If we would allocate a 160 bytes page before calling mi_heap_malloc_aligned, it would allocate all these allocations through the existing 160 bytes page.

from mimalloc.

daanx avatar daanx commented on June 2, 2024

Thanks! Looking into this now.

from mimalloc.

daanx avatar daanx commented on June 2, 2024

Ah, I think you see these results because you build in debug mode, with padding enabled. If you build with -DMI_NO_PADDING=ON you will see it allocates correctly. This is due to the test:

(offset == 0 && alignment <= padsize && padsize <= MI_MEDIUM_OBJ_SIZE_MAX && (padsize & align_mask) == 0)

in mi_heap_malloc_zero_aligned_at_fallback.

from mimalloc.

daanx avatar daanx commented on June 2, 2024

I just pushed a refactoring of the aligned allocation code that simplifies things and makes this more apparent. Thanks!

from mimalloc.

romange avatar romange commented on June 2, 2024

Hi @daanx , we already compile mimalloc without padding and I agree padding is one of the reasons but it's not the only one.

I am pretty sure the behavior of mimalloc changes if the page with required size already existed or if it's a new one. I will double check everything tomorrow and will send you the reproducing example.

from mimalloc.

romange avatar romange commented on June 2, 2024

@daanx we used 2.1.4 where the condition was if (offset==0 && alignment<=padsize && padsize<=MI_MAX_ALIGN_GUARANTEE && (padsize&align_mask)==0)
note MI_MAX_ALIGN_GUARANTEE and not MI_MEDIUM_OBJ_SIZE_MAX

so for allocations of 160 bytes, this condition does not hold.

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.