Changeset bc504ef2 in mainline


Ignore:
Timestamp:
2006-02-02T16:14:19Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
086d4fd
Parents:
2d43f3e
Message:

Tested basic non-cached slab allocation.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • arch/mips32/src/mm/tlb.c

    r2d43f3e rbc504ef2  
    367367         */
    368368        if (!pte) {
    369                 printf("No such mapping.\n");
     369                printf("No such mapping: %P.\n", badvaddr);
    370370                return NULL;
    371371        }
  • generic/include/mm/slab.h

    r2d43f3e rbc504ef2  
    3232#include <list.h>
    3333#include <synch/spinlock.h>
     34#include <arch/atomic.h>
    3435
    3536/** Initial Magazine size (TODO: dynamically growing magazines) */
     
    7374
    7475        /* Statistics */
     76        atomic_t allocated_slabs;
     77        atomic_t allocated_objs;
    7578
    7679        /* Slabs */
  • generic/src/mm/frame.c

    r2d43f3e rbc504ef2  
    185185                v = PA2KA(v);
    186186       
    187         if (flags & FRAME_ATOMIC) {
    188                 ASSERT(status != NULL);
     187        if (status)
    189188                *status = FRAME_OK;
    190         }
     189
    191190        if (pzone)
    192191                *pzone = zone;
  • generic/src/mm/slab.c

    r2d43f3e rbc504ef2  
    7070        zone_t *zone = NULL;
    7171        int status;
     72        frame_t *frame;
    7273
    7374        data = (void *)frame_alloc(FRAME_KA | flags, cache->order, &status, &zone);
    74         if (status != FRAME_OK)
     75        if (status != FRAME_OK) {
    7576                return NULL;
    76 
     77        }
    7778        if (! cache->flags & SLAB_CACHE_SLINSIDE) {
    7879                slab = malloc(sizeof(*slab)); // , flags);
     
    8586                slab = data + fsize - sizeof(*slab);
    8687        }
    87 
     88               
    8889        /* Fill in slab structures */
    8990        /* TODO: some better way of accessing the frame */
    9091        for (i=0; i< (1<<cache->order); i++) {
    91                 ADDR2FRAME(zone, (__address)(data+i*PAGE_SIZE))->parent = slab;
     92                frame = ADDR2FRAME(zone, KA2PA((__address)(data+i*PAGE_SIZE)));
     93                frame->parent = slab;
    9294        }
    9395
     
    98100        for (i=0; i<cache->objects;i++)
    99101                *((int *) (slab->start + i*cache->size)) = i+1;
     102
     103        atomic_inc(&cache->allocated_slabs);
     104
    100105        return slab;
    101106}
     
    111116        if (! cache->flags & SLAB_CACHE_SLINSIDE)
    112117                free(slab);
     118
     119        atomic_dec(&cache->allocated_slabs);
     120       
    113121        return 1 << cache->order;
    114122}
     
    154162                /* It was in full, move to partial */
    155163                list_remove(&slab->link);
    156                 list_prepend(&cache->partial_slabs, &slab->link);
     164                list_prepend(&slab->link, &cache->partial_slabs);
    157165        }
    158166        if (slab->available == cache->objects) {
     
    192200                slab = slab_space_alloc(cache, flags);
    193201                spinlock_lock(&cache->lock);
    194                 if (!slab)
     202                if (!slab) {
    195203                        return NULL;
     204                }
    196205        } else {
    197206                slab = list_get_instance(cache->partial_slabs.next,
     
    204213        slab->available--;
    205214        if (! slab->available)
    206                 list_prepend(&cache->full_slabs, &slab->link);
     215                list_prepend(&slab->link, &cache->full_slabs);
    207216        else
    208                 list_prepend(&cache->partial_slabs, &slab->link);
     217                list_prepend(&slab->link, &cache->partial_slabs);
    209218        return obj;
    210219}
     
    316325                if (!mag || mag->size == mag->busy) {
    317326                        if (mag)
    318                                 list_prepend(&cache->magazines, &mag->link);
     327                                list_prepend(&mag->link, &cache->magazines);
    319328
    320329                        mag = slab_alloc(&mag_cache, FRAME_ATOMIC | FRAME_NO_RECLAIM);
     
    534543        }
    535544
     545        if (result)
     546                atomic_inc(&cache->allocated_objs);
     547
    536548        interrupts_restore(ipl);
     549
    537550
    538551        return result;
     
    553566                spinlock_unlock(&cache->lock);
    554567        }
     568        atomic_dec(&cache->allocated_objs);
    555569        interrupts_restore(ipl);
    556570}
     
    583597
    584598        spinlock_lock(&slab_cache_lock);
    585         printf("SLAB name\tOsize\tOrder\n");
     599        printf("SLAB name\tOsize\tOrder\tOcnt\tSlabs\tAllocobjs\n");
    586600        for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) {
    587601                cache = list_get_instance(cur, slab_cache_t, link);
    588                 printf("%s\t%d\t%d\n", cache->name, cache->size, cache->order);
     602                printf("%s\t%d\t%d\t%d\t%d\t%d\n", cache->name, cache->size,
     603                       cache->order, cache->objects,
     604                       atomic_get(&cache->allocated_slabs),
     605                       atomic_get(&cache->allocated_objs));
    589606        }
    590607        spinlock_unlock(&slab_cache_lock);
  • test/mm/slab1/test.c

    r2d43f3e rbc504ef2  
    4444        printf("Creating cache.\n");
    4545        cache = slab_cache_create("test_cache", VAL_SIZE, 0, NULL, NULL, SLAB_CACHE_NOMAGAZINE);
    46         slab_print_list();
    4746        printf("Destroying cache.\n");
    4847        slab_cache_destroy(cache);
     
    6261        }
    6362        printf("done.\n");
     63
     64        printf("Allocating %d items...", VAL_COUNT);
     65        for (i=0; i < VAL_COUNT; i++) {
     66                data[i] = slab_alloc(cache, 0);
     67        }
     68        printf("done.\n");
     69
     70        slab_print_list();
     71        printf("Freeing %d items...", VAL_COUNT/2);
     72        for (i=VAL_COUNT-1; i >= VAL_COUNT/2; i--) {
     73                slab_free(cache, data[i]);
     74        }
     75        printf("done.\n");     
     76
     77        printf("Allocating %d items...", VAL_COUNT/2);
     78        for (i=VAL_COUNT/2; i < VAL_COUNT; i++) {
     79                data[i] = slab_alloc(cache, 0);
     80        }
     81        printf("done.\n");
     82        printf("Freeing %d items...", VAL_COUNT);
     83        for (i=0; i < VAL_COUNT; i++) {
     84                slab_free(cache, data[i]);
     85        }
     86        printf("done.\n");     
     87        slab_print_list();
     88        slab_cache_destroy(cache);
     89
     90        printf("Test complete.\n");
    6491}
Note: See TracChangeset for help on using the changeset viewer.