Changeset b0c2075 in mainline for kernel/generic/src/mm/slab.c


Ignore:
Timestamp:
2013-09-10T17:48:57Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
85147f3
Parents:
86733f3
Message:

new physical memory allocator supporting physical address constrains
the buddy allocator framework is retired and replaced by a two-level bitmap
the allocator can allocate an arbitrary number of frames, not only a power-of-two count

Caution: Change of semantics
The physical memory allocator no longer allocates naturally aligned blocks. If you require an aligned block, specify it as the constraint.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/slab.c

    r86733f3 rb0c2075  
    183183       
    184184        void *data = (void *)
    185             PA2KA(frame_alloc_generic(cache->order, flags, 0, &zone));
     185            PA2KA(frame_alloc_generic(cache->frames, flags, 0, &zone));
    186186        if (!data)
    187187                return NULL;
     
    197197                }
    198198        } else {
    199                 fsize = (PAGE_SIZE << cache->order);
     199                fsize = FRAMES2SIZE(cache->frames);
    200200                slab = data + fsize - sizeof(*slab);
    201201        }
     
    203203        /* Fill in slab structures */
    204204        size_t i;
    205         for (i = 0; i < ((size_t) 1 << cache->order); i++)
     205        for (i = 0; i < cache->frames; i++)
    206206                frame_set_parent(ADDR2PFN(KA2PA(data)) + i, slab, zone);
    207207       
     
    231231        atomic_dec(&cache->allocated_slabs);
    232232       
    233         return (1 << cache->order);
     233        return cache->frames;
    234234}
    235235
     
    558558{
    559559        if (cache->flags & SLAB_CACHE_SLINSIDE)
    560                 return ((PAGE_SIZE << cache->order)
    561                     - sizeof(slab_t)) / cache->size;
     560                return (FRAMES2SIZE(cache->frames) - sizeof(slab_t)) /
     561                    cache->size;
    562562        else
    563                 return (PAGE_SIZE << cache->order) / cache->size;
     563                return FRAMES2SIZE(cache->frames) / cache->size;
    564564}
    565565
     
    570570{
    571571        size_t objects = comp_objects(cache);
    572         size_t ssize = PAGE_SIZE << cache->order;
     572        size_t ssize = FRAMES2SIZE(cache->frames);
    573573       
    574574        if (cache->flags & SLAB_CACHE_SLINSIDE)
     
    634634                cache->flags |= SLAB_CACHE_SLINSIDE;
    635635       
    636         /* Minimum slab order */
    637         size_t pages = SIZE2FRAMES(cache->size);
    638        
    639         /* We need the 2^order >= pages */
    640         if (pages == 1)
    641                 cache->order = 0;
    642         else
    643                 cache->order = fnzb(pages - 1) + 1;
     636        /* Minimum slab frames */
     637        cache->frames = SIZE2FRAMES(cache->size);
    644638       
    645639        while (badness(cache) > SLAB_MAX_BADNESS(cache))
    646                 cache->order += 1;
     640                cache->frames <<= 1;
    647641       
    648642        cache->objects = comp_objects(cache);
     
    870864               
    871865                const char *name = cache->name;
    872                 uint8_t order = cache->order;
     866                size_t frames = cache->frames;
    873867                size_t size = cache->size;
    874868                size_t objects = cache->objects;
     
    880874                irq_spinlock_unlock(&slab_cache_lock, true);
    881875               
    882                 printf("%-18s %8zu %8u %8zu %8ld %8ld %8ld %-5s\n",
    883                     name, size, (1 << order), objects, allocated_slabs,
     876                printf("%-18s %8zu %8zu %8zu %8ld %8ld %8ld %-5s\n",
     877                    name, size, frames, objects, allocated_slabs,
    884878                    cached_objs, allocated_objs,
    885879                    flags & SLAB_CACHE_SLINSIDE ? "in" : "out");
Note: See TracChangeset for help on using the changeset viewer.