Subversion Repositories HelenOS

Rev

Rev 4348 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4348 Rev 4691
Line 154... Line 154...
154
/** Slab descriptor */
154
/** Slab descriptor */
155
typedef struct {
155
typedef struct {
156
    slab_cache_t *cache;    /**< Pointer to parent cache. */
156
    slab_cache_t *cache;    /**< Pointer to parent cache. */
157
    link_t link;        /**< List of full/partial slabs. */
157
    link_t link;        /**< List of full/partial slabs. */
158
    void *start;        /**< Start address of first available item. */
158
    void *start;        /**< Start address of first available item. */
159
    count_t available;  /**< Count of available items in this slab. */
159
    size_t available;   /**< Count of available items in this slab. */
160
    index_t nextavail;  /**< The index of next available item. */
160
    size_t nextavail;   /**< The index of next available item. */
161
} slab_t;
161
} slab_t;
162
 
162
 
163
#ifdef CONFIG_DEBUG
163
#ifdef CONFIG_DEBUG
164
static int _slab_initialized = 0;
164
static int _slab_initialized = 0;
165
#endif
165
#endif
Line 175... Line 175...
175
{
175
{
176
    void *data;
176
    void *data;
177
    slab_t *slab;
177
    slab_t *slab;
178
    size_t fsize;
178
    size_t fsize;
179
    unsigned int i;
179
    unsigned int i;
180
    count_t zone = 0;
180
    size_t zone = 0;
181
   
181
   
182
    data = frame_alloc_generic(cache->order, FRAME_KA | flags, &zone);
182
    data = frame_alloc_generic(cache->order, FRAME_KA | flags, &zone);
183
    if (!data) {
183
    if (!data) {
184
        return NULL;
184
        return NULL;
185
    }
185
    }
Line 213... Line 213...
213
/**
213
/**
214
 * Deallocate space associated with slab
214
 * Deallocate space associated with slab
215
 *
215
 *
216
 * @return number of freed frames
216
 * @return number of freed frames
217
 */
217
 */
218
static count_t slab_space_free(slab_cache_t *cache, slab_t *slab)
218
static size_t slab_space_free(slab_cache_t *cache, slab_t *slab)
219
{
219
{
220
    frame_free(KA2PA(slab->start));
220
    frame_free(KA2PA(slab->start));
221
    if (! (cache->flags & SLAB_CACHE_SLINSIDE))
221
    if (! (cache->flags & SLAB_CACHE_SLINSIDE))
222
        slab_free(slab_extern_cache, slab);
222
        slab_free(slab_extern_cache, slab);
223
 
223
 
Line 241... Line 241...
241
 *
241
 *
242
 * @param slab If the caller knows directly slab of the object, otherwise NULL
242
 * @param slab If the caller knows directly slab of the object, otherwise NULL
243
 *
243
 *
244
 * @return Number of freed pages
244
 * @return Number of freed pages
245
 */
245
 */
246
static count_t slab_obj_destroy(slab_cache_t *cache, void *obj, slab_t *slab)
246
static size_t slab_obj_destroy(slab_cache_t *cache, void *obj, slab_t *slab)
247
{
247
{
248
    int freed = 0;
248
    int freed = 0;
249
 
249
 
250
    if (!slab)
250
    if (!slab)
251
        slab = obj2slab(obj);
251
        slab = obj2slab(obj);
Line 369... Line 369...
369
/**
369
/**
370
 * Free all objects in magazine and free memory associated with magazine
370
 * Free all objects in magazine and free memory associated with magazine
371
 *
371
 *
372
 * @return Number of freed pages
372
 * @return Number of freed pages
373
 */
373
 */
374
static count_t magazine_destroy(slab_cache_t *cache, slab_magazine_t *mag)
374
static size_t magazine_destroy(slab_cache_t *cache, slab_magazine_t *mag)
375
{
375
{
376
    unsigned int i;
376
    unsigned int i;
377
    count_t frames = 0;
377
    size_t frames = 0;
378
 
378
 
379
    for (i = 0; i < mag->busy; i++) {
379
    for (i = 0; i < mag->busy; i++) {
380
        frames += slab_obj_destroy(cache, mag->objs[i], NULL);
380
        frames += slab_obj_destroy(cache, mag->objs[i], NULL);
381
        atomic_dec(&cache->cached_objs);
381
        atomic_dec(&cache->cached_objs);
382
    }
382
    }
Line 647... Line 647...
647
 * Reclaim space occupied by objects that are already free
647
 * Reclaim space occupied by objects that are already free
648
 *
648
 *
649
 * @param flags If contains SLAB_RECLAIM_ALL, do aggressive freeing
649
 * @param flags If contains SLAB_RECLAIM_ALL, do aggressive freeing
650
 * @return Number of freed pages
650
 * @return Number of freed pages
651
 */
651
 */
652
static count_t _slab_reclaim(slab_cache_t *cache, int flags)
652
static size_t _slab_reclaim(slab_cache_t *cache, int flags)
653
{
653
{
654
    unsigned int i;
654
    unsigned int i;
655
    slab_magazine_t *mag;
655
    slab_magazine_t *mag;
656
    count_t frames = 0;
656
    size_t frames = 0;
657
    int magcount;
657
    int magcount;
658
   
658
   
659
    if (cache->flags & SLAB_CACHE_NOMAGAZINE)
659
    if (cache->flags & SLAB_CACHE_NOMAGAZINE)
660
        return 0; /* Nothing to do */
660
        return 0; /* Nothing to do */
661
 
661
 
Line 769... Line 769...
769
{
769
{
770
    _slab_free(cache, obj, NULL);
770
    _slab_free(cache, obj, NULL);
771
}
771
}
772
 
772
 
773
/* Go through all caches and reclaim what is possible */
773
/* Go through all caches and reclaim what is possible */
774
count_t slab_reclaim(int flags)
774
size_t slab_reclaim(int flags)
775
{
775
{
776
    slab_cache_t *cache;
776
    slab_cache_t *cache;
777
    link_t *cur;
777
    link_t *cur;
778
    count_t frames = 0;
778
    size_t frames = 0;
779
 
779
 
780
    spinlock_lock(&slab_cache_lock);
780
    spinlock_lock(&slab_cache_lock);
781
 
781
 
782
    /* TODO: Add assert, that interrupts are disabled, otherwise
782
    /* TODO: Add assert, that interrupts are disabled, otherwise
783
     * memory allocation from interrupts can deadlock.
783
     * memory allocation from interrupts can deadlock.