Skip to content
  • Ben Gamari's avatar
    085bfdeb
    rts/m32: Refactor handling of allocator seeding · 085bfdeb
    Ben Gamari authored
    Previously, in an attempt to reduce fragmentation, each new allocator
    would map a region of M32_MAX_PAGES fresh pages to seed itself. However,
    this ends up being extremely wasteful since it turns out that we often
    use fewer than this.  Consequently, these pages end up getting freed
    which, ends up fragmenting our address space more than than we would
    have if we had naively allocated pages on-demand.
    
    Here we refactor m32 to avoid this waste while achieving the
    fragmentation mitigation previously desired. In particular, we move all
    page allocation into the global m32_alloc_page, which will pull a page
    from the free page pool. If the free page pool is empty we then refill
    it by allocating a region of M32_MAP_PAGES and adding them to the pool.
    
    Furthermore, we do away with the initial seeding entirely. That is, the
    allocator starts with no active pages: pages are rather allocated on an
    as-needed basis.
    
    On the whole this ends up being a pleasingly simple change,
    simultaneously making m32 more efficient, more robust, and simpler.
    
    Fixes #18980.
    085bfdeb
    rts/m32: Refactor handling of allocator seeding
    Ben Gamari authored
    Previously, in an attempt to reduce fragmentation, each new allocator
    would map a region of M32_MAX_PAGES fresh pages to seed itself. However,
    this ends up being extremely wasteful since it turns out that we often
    use fewer than this.  Consequently, these pages end up getting freed
    which, ends up fragmenting our address space more than than we would
    have if we had naively allocated pages on-demand.
    
    Here we refactor m32 to avoid this waste while achieving the
    fragmentation mitigation previously desired. In particular, we move all
    page allocation into the global m32_alloc_page, which will pull a page
    from the free page pool. If the free page pool is empty we then refill
    it by allocating a region of M32_MAP_PAGES and adding them to the pool.
    
    Furthermore, we do away with the initial seeding entirely. That is, the
    allocator starts with no active pages: pages are rather allocated on an
    as-needed basis.
    
    On the whole this ends up being a pleasingly simple change,
    simultaneously making m32 more efficient, more robust, and simpler.
    
    Fixes #18980.
Loading