Changeset 745 for branches/binary/server/items.c
- Timestamp:
- 03/03/08 07:51:02 (21 months ago)
- Files:
-
- 1 modified
-
branches/binary/server/items.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/binary/server/items.c
r642 r745 28 28 29 29 #define LARGEST_ID 255 30 typedef struct { 31 unsigned int evicted; 32 unsigned int outofmemory; 33 } itemstats_t; 34 30 35 static item *heads[LARGEST_ID]; 31 36 static item *tails[LARGEST_ID]; 37 static itemstats_t itemstats[LARGEST_ID]; 32 38 static unsigned int sizes[LARGEST_ID]; 33 39 34 40 void item_init(void) { 35 41 int i; 42 memset(itemstats, 0, sizeof(itemstats_t) * LARGEST_ID); 36 43 for(i = 0; i < LARGEST_ID; i++) { 37 44 heads[i] = NULL; … … 89 96 return 0; 90 97 91 it = slabs_alloc(ntotal );98 it = slabs_alloc(ntotal, id); 92 99 if (it == 0) { 93 100 int tries = 50; … … 98 105 */ 99 106 100 if (settings.evict_to_free == 0) return NULL; 107 if (settings.evict_to_free == 0) { 108 itemstats[id].outofmemory++; 109 return NULL; 110 } 101 111 102 112 /* … … 107 117 */ 108 118 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 } 111 123 112 124 for (search = tails[id]; tries > 0 && search != NULL; tries--, search=search->prev) { 113 125 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(); 118 131 } 119 132 do_item_unlink(search); … … 121 134 } 122 135 } 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 } 125 141 } 126 142 … … 146 162 void item_free(item *it) { 147 163 size_t ntotal = ITEM_ntotal(it); 164 unsigned int clsid; 148 165 assert((it->it_flags & ITEM_LINKED) == 0); 149 166 assert(it != heads[it->slabs_clsid]); … … 152 169 153 170 /* so slab size changer can tell later if item is already free or not */ 171 clsid = it->slabs_clsid; 154 172 it->slabs_clsid = 0; 155 173 it->it_flags |= ITEM_SLABBED; 156 174 DEBUG_REFCNT(it, 'F'); 157 slabs_free(it, ntotal );175 slabs_free(it, ntotal, clsid); 158 176 } 159 177 … … 311 329 312 330 char *do_item_stats(int *bytes) { 313 size_t bufleft = (size_t) LARGEST_ID * 80;331 size_t bufleft = (size_t) LARGEST_ID * 160; 314 332 char *buffer = malloc(bufleft); 315 333 char *bufcurr = buffer; … … 324 342 for (i = 0; i < LARGEST_ID; i++) { 325 343 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); 328 351 if (linelen + sizeof("END\r\n") < bufleft) { 329 352 bufcurr += linelen;
