slabs.c
/**
 * Determines the chunk sizes and initializes the slab class descriptors
 * accordingly.
 */
Determines the chunk sizes and initializes the slab class descriptors
accordingly.
Determines the chunk sizes and initializes the slab class descriptors accordingly .
void slabs_init(const size_t limit, const double factor, const bool prealloc) {
    int i = POWER_SMALLEST - 1;
    unsigned int size = sizeof(item) + settings.chunk_size;
    mem_limit = limit;
    if (prealloc) {
        mem_base = malloc(mem_limit);
        if (mem_base != NULL) {
            mem_current = mem_base;
            mem_avail = mem_limit;
        } else {
            fprintf(stderr, "Warning: Failed to allocate requested memory in"
                    " one large chunk.\nWill allocate in smaller chunks\n");
        }
    }
    memset(slabclass, 0, sizeof(slabclass));
    while (++i < POWER_LARGEST && size <= settings.item_size_max / factor) {
        if (size % CHUNK_ALIGN_BYTES)
            size += CHUNK_ALIGN_BYTES - (size % CHUNK_ALIGN_BYTES);
        slabclass[i].size = size;
        slabclass[i].perslab = settings.item_size_max / slabclass[i].size;
        size *= factor;
        if (settings.verbose > 1) {
            fprintf(stderr, "slab class %3d: chunk size %9u perslab %7u\n",
                    i, slabclass[i].size, slabclass[i].perslab);
        }
    }
    power_largest = i;
    slabclass[power_largest].size = settings.item_size_max;
    slabclass[power_largest].perslab = 1;
    if (settings.verbose > 1) {
        fprintf(stderr, "slab class %3d: chunk size %9u perslab %7u\n",
                i, slabclass[i].size, slabclass[i].perslab);
    }
    {
        char *t_initial_malloc = getenv("T_MEMD_INITIAL_MALLOC");
        if (t_initial_malloc) {
            mem_malloced = (size_t)atol(t_initial_malloc);
        }
    }
#ifndef DONT_PREALLOC_SLABS
    {
        char *pre_alloc = getenv("T_MEMD_SLABS_ALLOC");
        if (pre_alloc == NULL || atoi(pre_alloc) != 0) {
            slabs_preallocate(power_largest);
        }
    }
#endif
}
void slabs_init ( const size_t limit , const double factor , const bool prealloc ) { int i = POWER_SMALLEST - 1 ; unsigned int size = sizeof ( item ) + settings . chunk_size ; mem_limit = limit ; if ( prealloc ) { mem_base = malloc ( mem_limit ) ; if ( mem_base != NULL ) { mem_current = mem_base ; mem_avail = mem_limit ; } else { fprintf ( stderr , " " " \n \n " ) ; } } memset ( slabclass , 0 , sizeof ( slabclass ) ) ; while ( ++ i < POWER_LARGEST && size <= settings . item_size_max / factor ) { if ( size % CHUNK_ALIGN_BYTES ) size += CHUNK_ALIGN_BYTES - ( size % CHUNK_ALIGN_BYTES ) ; slabclass [ i ] . size = size ; slabclass [ i ] . perslab = settings . item_size_max / slabclass [ i ] . size ; size *= factor ; if ( settings . verbose > 1 ) { fprintf ( stderr , " \n " , i , slabclass [ i ] . size , slabclass [ i ] . perslab ) ; } } power_largest = i ; slabclass [ power_largest ] . size = settings . item_size_max ; slabclass [ power_largest ] . perslab = 1 ; if ( settings . verbose > 1 ) { fprintf ( stderr , " \n " , i , slabclass [ i ] . size , slabclass [ i ] . perslab ) ; } { char * t_initial_malloc = getenv ( " " ) ; if ( t_initial_malloc ) { mem_malloced = ( size_t ) atol ( t_initial_malloc ) ; } } #ifndef DONT_PREALLOC_SLABS { char * pre_alloc = getenv ( " " ) ; if ( pre_alloc == NULL || atoi ( pre_alloc ) != 0 ) { slabs_preallocate ( power_largest ) ; } } #endif }
Determines the chunk sizes and initializes the slab class descriptors
 accordingly.
Determines the chunk sizes and initializes the slab class descriptors accordingly .
/* Allocate everything in a big chunk with malloc */ /* Make sure items are always n-byte aligned */ /* for the test suite:  faking of how much we've already malloc'd */