Show
Ignore:
Timestamp:
03/03/08 07:51:02 (21 months ago)
Author:
dsallings
Message:

Merged commit 'trunk' into lbinary as of r744

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/binary/server/items.c

    r642 r745  
    2828 
    2929#define LARGEST_ID 255 
     30typedef struct { 
     31    unsigned int evicted; 
     32    unsigned int outofmemory; 
     33} itemstats_t; 
     34 
    3035static item *heads[LARGEST_ID]; 
    3136static item *tails[LARGEST_ID]; 
     37static itemstats_t itemstats[LARGEST_ID]; 
    3238static unsigned int sizes[LARGEST_ID]; 
    3339 
    3440void item_init(void) { 
    3541    int i; 
     42    memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID); 
    3643    for(i = 0; i < LARGEST_ID; i++) { 
    3744        heads[i] = NULL; 
     
    8996        return 0; 
    9097 
    91     it = slabs_alloc(ntotal); 
     98    it = slabs_alloc(ntotal, id); 
    9299    if (it == 0) { 
    93100        int tries = 50; 
     
    98105         */ 
    99106 
    100         if (settings.evict_to_free == 0) return NULL; 
     107        if (settings.evict_to_free == 0) { 
     108            itemstats[id].outofmemory++; 
     109            return NULL; 
     110        } 
    101111 
    102112        /* 
     
    107117         */ 
    108118 
    109         if (id > LARGEST_ID) return NULL; 
    110         if (tails[id] == 0) return NULL; 
     119        if (tails[id] == 0) { 
     120            itemstats[id].outofmemory++; 
     121            return NULL; 
     122        } 
    111123 
    112124        for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) { 
    113125            if (search->refcount == 0) { 
    114                if (search->exptime == 0 || search->exptime > current_time) { 
    115                        STATS_LOCK(); 
    116                        stats.evictions++; 
    117                        STATS_UNLOCK(); 
     126                if (search->exptime == 0 || search->exptime > current_time) { 
     127                    itemstats[id].evicted++; 
     128                    STATS_LOCK(); 
     129                    stats.evictions++; 
     130                    STATS_UNLOCK(); 
    118131                } 
    119132                do_item_unlink(search); 
     
    121134            } 
    122135        } 
    123         it = slabs_alloc(ntotal); 
    124         if (it == 0) return NULL; 
     136        it = slabs_alloc(ntotal, id); 
     137        if (it == 0) { 
     138            itemstats[id].outofmemory++; 
     139            return NULL; 
     140        } 
    125141    } 
    126142 
     
    146162void item_free(item *it) { 
    147163    size_t ntotal = ITEM_ntotal(it); 
     164    unsigned int clsid; 
    148165    assert((it->it_flags & ITEM_LINKED) == 0); 
    149166    assert(it != heads[it->slabs_clsid]); 
     
    152169 
    153170    /* so slab size changer can tell later if item is already free or not */ 
     171    clsid = it->slabs_clsid; 
    154172    it->slabs_clsid = 0; 
    155173    it->it_flags |= ITEM_SLABBED; 
    156174    DEBUG_REFCNT(it, 'F'); 
    157     slabs_free(it, ntotal); 
     175    slabs_free(it, ntotal, clsid); 
    158176} 
    159177 
     
    311329 
    312330char *do_item_stats(int *bytes) { 
    313     size_t bufleft = (size_t) LARGEST_ID * 80; 
     331    size_t bufleft = (size_t) LARGEST_ID * 160; 
    314332    char *buffer = malloc(bufleft); 
    315333    char *bufcurr = buffer; 
     
    324342    for (i = 0; i < LARGEST_ID; i++) { 
    325343        if (tails[i] != NULL) { 
    326             linelen = snprintf(bufcurr, bufleft, "STAT items:%d:number %u\r\nSTAT items:%d:age %u\r\n", 
    327                                i, sizes[i], i, now - tails[i]->time); 
     344            linelen = snprintf(bufcurr, bufleft, 
     345                "STAT items:%d:number %u\r\n" 
     346                "STAT items:%d:age %u\r\n" 
     347                "STAT items:%d:evicted %u\r\n" 
     348                "STAT items:%d:outofmemory %u\r\n", 
     349                    i, sizes[i], i, now - tails[i]->time, i, 
     350                    itemstats[i].evicted, i, itemstats[i].outofmemory); 
    328351            if (linelen + sizeof("END\r\n") < bufleft) { 
    329352                bufcurr += linelen;