Subversion Repositories HelenOS-historic

Rev

Rev 765 | Rev 767 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 765 Rev 766
Line 86... Line 86...
86
        slab = data + fsize - sizeof(*slab);
86
        slab = data + fsize - sizeof(*slab);
87
    }
87
    }
88
       
88
       
89
    /* Fill in slab structures */
89
    /* Fill in slab structures */
90
    /* TODO: some better way of accessing the frame */
90
    /* TODO: some better way of accessing the frame */
91
    for (i=0; i< (1<<cache->order); i++) {
91
    for (i=0; i < (1 << cache->order); i++) {
92
        frame = ADDR2FRAME(zone, KA2PA((__address)(data+i*PAGE_SIZE)));
92
        frame = ADDR2FRAME(zone, KA2PA((__address)(data+i*PAGE_SIZE)));
93
        frame->parent = slab;
93
        frame->parent = slab;
94
    }
94
    }
95
 
95
 
96
    slab->start = data;
96
    slab->start = data;
Line 104... Line 104...
104
 
104
 
105
    return slab;
105
    return slab;
106
}
106
}
107
 
107
 
108
/**
108
/**
109
 * Free space associated with SLAB
109
 * Deallocate space associated with SLAB
110
 *
110
 *
111
 * @return number of freed frames
111
 * @return number of freed frames
112
 */
112
 */
113
static count_t slab_space_free(slab_cache_t *cache, slab_t *slab)
113
static count_t slab_space_free(slab_cache_t *cache, slab_t *slab)
114
{
114
{
Line 149... Line 149...
149
    count_t frames = 0;
149
    count_t frames = 0;
150
 
150
 
151
    if (!slab)
151
    if (!slab)
152
        slab = obj2slab(obj);
152
        slab = obj2slab(obj);
153
 
153
 
154
    spinlock_lock(&cache->lock);
-
 
155
 
-
 
156
    *((int *)obj) = slab->nextavail;
154
    *((int *)obj) = slab->nextavail;
157
    slab->nextavail = (obj - slab->start)/cache->size;
155
    slab->nextavail = (obj - slab->start)/cache->size;
158
    slab->available++;
156
    slab->available++;
159
 
157
 
160
    /* Move it to correct list */
158
    /* Move it to correct list */
Line 170... Line 168...
170
        spinlock_unlock(&cache->lock);
168
        spinlock_unlock(&cache->lock);
171
        frames = slab_space_free(cache, slab);
169
        frames = slab_space_free(cache, slab);
172
        spinlock_lock(&cache->lock);
170
        spinlock_lock(&cache->lock);
173
    }
171
    }
174
 
172
 
175
    spinlock_unlock(&cache->lock);
-
 
176
 
-
 
177
    return frames;
173
    return frames;
178
}
174
}
179
 
175
 
180
/**
176
/**
181
 * Take new object from slab or create new if needed
177
 * Take new object from slab or create new if needed
Line 386... Line 382...
386
    int i;
382
    int i;
387
 
383
 
388
    memsetb((__address)cache, sizeof(*cache), 0);
384
    memsetb((__address)cache, sizeof(*cache), 0);
389
    cache->name = name;
385
    cache->name = name;
390
 
386
 
391
    if (align)
387
    if (align < sizeof(__native))
-
 
388
        align = sizeof(__native);
392
        size = ALIGN_UP(size, align);
389
    size = ALIGN_UP(size, align);
-
 
390
       
393
    cache->size = size;
391
    cache->size = size;
394
 
392
 
395
    cache->constructor = constructor;
393
    cache->constructor = constructor;
396
    cache->destructor = destructor;
394
    cache->destructor = destructor;
397
    cache->flags = flags;
395
    cache->flags = flags;
Line 409... Line 407...
409
    /* Compute slab sizes, object counts in slabs etc. */
407
    /* Compute slab sizes, object counts in slabs etc. */
410
    if (cache->size < SLAB_INSIDE_SIZE)
408
    if (cache->size < SLAB_INSIDE_SIZE)
411
        cache->flags |= SLAB_CACHE_SLINSIDE;
409
        cache->flags |= SLAB_CACHE_SLINSIDE;
412
 
410
 
413
    /* Minimum slab order */
411
    /* Minimum slab order */
414
    cache->order = (cache->size >> PAGE_WIDTH) + 1;
412
    cache->order = (cache->size-1) >> PAGE_WIDTH;
415
       
413
 
416
    while (badness(cache) > SLAB_MAX_BADNESS(cache)) {
414
    while (badness(cache) > SLAB_MAX_BADNESS(cache)) {
417
        cache->order += 1;
415
        cache->order += 1;
418
    }
416
    }
419
 
-
 
420
    cache->objects = comp_objects(cache);
417
    cache->objects = comp_objects(cache);
-
 
418
    /* If info fits in, put it inside */
-
 
419
    if (badness(cache) > sizeof(slab_t))
-
 
420
        cache->flags |= SLAB_CACHE_SLINSIDE;
421
 
421
 
422
    spinlock_lock(&slab_cache_lock);
422
    spinlock_lock(&slab_cache_lock);
423
 
423
 
424
    list_append(&cache->link, &slab_cache_list);
424
    list_append(&cache->link, &slab_cache_list);
425
 
425
 
Line 594... Line 594...
594
{
594
{
595
    slab_cache_t *cache;
595
    slab_cache_t *cache;
596
    link_t *cur;
596
    link_t *cur;
597
 
597
 
598
    spinlock_lock(&slab_cache_lock);
598
    spinlock_lock(&slab_cache_lock);
599
    printf("SLAB name\tOsize\tOrder\tOcnt\tSlabs\tAllocobjs\n");
599
    printf("SLAB name\tOsize\tPages\tOcnt\tSlabs\tAllocobjs\tCtl\n");
600
    for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) {
600
    for (cur = slab_cache_list.next;cur!=&slab_cache_list; cur=cur->next) {
601
        cache = list_get_instance(cur, slab_cache_t, link);
601
        cache = list_get_instance(cur, slab_cache_t, link);
602
        printf("%s\t%d\t%d\t%d\t%d\t%d\n", cache->name, cache->size,
602
        printf("%s\t%d\t%d\t%d\t%d\t%d\t\t%s\n", cache->name, cache->size,
603
               cache->order, cache->objects,
603
               (1 << cache->order), cache->objects,
604
               atomic_get(&cache->allocated_slabs),
604
               atomic_get(&cache->allocated_slabs),
605
               atomic_get(&cache->allocated_objs));
605
               atomic_get(&cache->allocated_objs),
-
 
606
               cache->flags & SLAB_CACHE_SLINSIDE ? "In" : "Out");
606
    }
607
    }
607
    spinlock_unlock(&slab_cache_lock);
608
    spinlock_unlock(&slab_cache_lock);
608
}
609
}
609
 
610
 
610
void slab_cache_init(void)
611
void slab_cache_init(void)