예제 #1
0
파일: slab.c 프로젝트: softirq/common
void * kmem_get_obj(struct kmem_cache_t *cachep)
{
    struct slab *slabp = NULL;
    void *obj = NULL;

repeat:
    slabp = kmem_get_slab(cachep);
    /*printf("slabp = %x.", slabp);*/
    obj = slab_get_obj(cachep, slabp);

    if(obj == NULL)
    {
        if(cachep->nr_pages >= pow(2,MAX_SLAB_PAGES))
        {
            return NULL;
        }
        else
        {
            cache_grow(cachep);
            goto repeat;
        }
    }

    return obj;
}
예제 #2
0
void kmem_cache_free(struct kmem_cache *cache, void *ptr)
{
	struct kmem_slab *slab = kmem_get_slab(ptr);
	const bool enabled = spin_lock_irqsave(&cache->lock);

	slab->ops->free(cache, slab, ptr);
	++slab->free;

	if (slab->free == slab->total) {
		list_del(&slab->link);
		list_add(&slab->link, &cache->free_list);
		spin_unlock_irqrestore(&cache->lock, enabled);
		return;
	}

	if (slab->free == 1) {
		list_del(&slab->link);
		list_add(&slab->link, &cache->part_list);
	}
	spin_unlock_irqrestore(&cache->lock, enabled);
}
예제 #3
0
파일: slab.c 프로젝트: smushroom/libmm
void * kmem_get_obj(kmem_cache_t *cachep)
{
    struct slab *slabp = NULL;
    void *obj = NULL;

repeat:
    slabp = kmem_get_slab(cachep);
    obj = slab_get_obj(cachep, slabp);
    if(obj)
    {
        return obj;
    }

    /* get obj is NULL but this kmem_cache_t has free objs */
    else
    {
        if(obj == NULL && cachep->nr_frees > 0)
        {
            return NULL;
        }
        else
        {
            if(cachep->nr_pages >= pow(2,MAX_SLAB_PAGES))
            {
                return NULL;
            }
            else
            {
                cache_grow(cachep);
                goto repeat;
            }
        }
    }

    return obj;
}