Exemplo n.º 1
0
static rstatus_t
slab_init_ctable(void)
{
    struct slabclass *c;
    uint8_t cid;
    size_t *profile;

    ASSERT(settings.profile_last_id <= SLABCLASS_MAX_ID);

    profile = settings.profile;
    nctable = settings.profile_last_id + 1;
    ctable = fc_alloc(sizeof(*ctable) * nctable);
    if (ctable == NULL) {
        return FC_ENOMEM;
    }

    for (cid = SLABCLASS_MIN_ID; cid < nctable; cid++) {
        c = &ctable[cid];
        c->nitem = slab_data_size() / profile[cid];
        c->size = profile[cid];
        c->slack = slab_data_size() - (c->nitem * c->size);
        TAILQ_INIT(&c->partial_msinfoq);
    }

    return FC_OK;
}
Exemplo n.º 2
0
static rstatus_t
slab_init_stable(void)
{
    struct slabinfo *sinfo;
    uint32_t i, j;

    nstable = nmslab + ndslab;
    stable = fc_alloc(sizeof(*stable) * nstable);
    if (stable == NULL) {
        return FC_ENOMEM;
    }

    /* init memory slabinfo q  */
    for (i = 0; i < nmslab; i++) {
        sinfo = &stable[i];

        sinfo->sid = i;
        sinfo->addr = i;
        sinfo->nalloc = 0;
        sinfo->nfree = 0;
        sinfo->cid = SLABCLASS_INVALID_ID;
        sinfo->mem = 1;

        nfree_msinfoq++;
        TAILQ_INSERT_TAIL(&free_msinfoq, sinfo, tqe);
    }

    /* init disk slabinfo q */
    for (j = 0; j < ndslab && i < nstable; i++, j++) {
        sinfo = &stable[i];

        sinfo->sid = i;
        sinfo->addr = j;
        sinfo->nalloc = 0;
        sinfo->nfree = 0;
        sinfo->cid = SLABCLASS_INVALID_ID;
        sinfo->mem = 0;

        nfree_dsinfoq++;
        TAILQ_INSERT_TAIL(&free_dsinfoq, sinfo, tqe);
    }

    return FC_OK;
}
Exemplo n.º 3
0
static void *fc_palloc_large(fc_pool_t *pool, size_t size)
{
    void *p;
    int   n;
    u_char found = 0;
    struct fc_large_data_s *l = NULL;

    n = 0;
    for(l = pool->large; l; l = l->next) {
        if (l->data == NULL) {
            found = 1;
            break;
        }

        if (n++ >= 4) {
            break;
        }
    }
    if (!found) {
        l = fc_palloc(pool, sizeof(struct fc_large_data_s));
    }
    if (l == NULL) {
        return NULL;
    }

    // allocate for requested `size` memory
    p = fc_alloc(size, pool->log);
    if (p == NULL) {
        return NULL;
    }
    l->data = p;
    if (!found) {
        l->next     = pool->large;
        pool->large = l;
    }

    return p;
}