Permalink
Browse files

remove global stats lock from item allocation

This doesn't reduce mutex contention much, if at all, for the global stats
lock, but it does remove a handful of instructions from the alloc hot path,
which is always worth doing.

Previous commits possibly added a handful of instructions for the loop and for
the bucket readlock trylock, but this is still faster than .14 for writes
overall.
  • Loading branch information...
dormando committed Sep 1, 2012
1 parent 1c94e12 commit 67d7cfc1355a0f4550263f3d24758840668017f8
Showing with 29 additions and 18 deletions.
  1. +20 −12 items.c
  2. +1 −0 items.h
  3. +0 −2 memcached.c
  4. +1 −0 memcached.h
  5. +1 −4 slabs.c
  6. +6 −0 thread.c
View
32 items.c
@@ -138,14 +138,8 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags,
/* Expired or flushed */
if ((search->exptime != 0 && search->exptime < current_time)
|| (search->time <= oldest_live && oldest_live <= current_time)) {
- STATS_LOCK();
- stats.reclaimed++;
- STATS_UNLOCK();
itemstats[id].reclaimed++;
if ((search->it_flags & ITEM_FETCHED) == 0) {
- STATS_LOCK();
- stats.expired_unfetched++;
- STATS_UNLOCK();
itemstats[id].expired_unfetched++;
}
it = search;
@@ -163,14 +157,8 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags,
if (search->exptime != 0)
itemstats[id].evicted_nonzero++;
if ((search->it_flags & ITEM_FETCHED) == 0) {
- STATS_LOCK();
- stats.evicted_unfetched++;
- STATS_UNLOCK();
itemstats[id].evicted_unfetched++;
}
- STATS_LOCK();
- stats.evictions++;
- STATS_UNLOCK();
it = search;
slabs_adjust_mem_requested(it->slabs_clsid, ITEM_ntotal(it), ntotal);
do_item_unlink_nolock(it, hv);
@@ -436,6 +424,26 @@ void item_stats_evictions(uint64_t *evicted) {
mutex_unlock(&cache_lock);
}
+void do_item_stats_totals(ADD_STAT add_stats, void *c) {
+ itemstats_t totals;
+ memset(&totals, 0, sizeof(itemstats_t));
+ int i;
+ for (i = 0; i < LARGEST_ID; i++) {
+ totals.expired_unfetched += itemstats[i].expired_unfetched;
+ totals.evicted_unfetched += itemstats[i].evicted_unfetched;
+ totals.evicted += itemstats[i].evicted;
+ totals.reclaimed += itemstats[i].reclaimed;
+ }
+ APPEND_STAT("expired_unfetched", "%llu",
+ (unsigned long long)totals.expired_unfetched);
+ APPEND_STAT("evicted_unfetched", "%llu",
+ (unsigned long long)totals.evicted_unfetched);
+ APPEND_STAT("evictions", "%llu",
+ (unsigned long long)totals.evicted);
+ APPEND_STAT("reclaimed", "%llu",
+ (unsigned long long)totals.reclaimed);
+}
+
void do_item_stats(ADD_STAT add_stats, void *c) {
int i;
for (i = 0; i < LARGEST_ID; i++) {
View
@@ -16,6 +16,7 @@ int do_item_replace(item *it, item *new_it, const uint32_t hv);
/*@null@*/
char *do_item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
void do_item_stats(ADD_STAT add_stats, void *c);
+void do_item_stats_totals(ADD_STAT add_stats, void *c);
/*@null@*/
void do_item_stats_sizes(ADD_STAT add_stats, void *c);
void do_item_flush_expired(void);
View
@@ -2585,8 +2585,6 @@ static void server_stats(ADD_STAT add_stats, conn *c) {
APPEND_STAT("hash_power_level", "%u", stats.hash_power_level);
APPEND_STAT("hash_bytes", "%llu", (unsigned long long)stats.hash_bytes);
APPEND_STAT("hash_is_expanding", "%u", stats.hash_is_expanding);
- APPEND_STAT("expired_unfetched", "%llu", stats.expired_unfetched);
- APPEND_STAT("evicted_unfetched", "%llu", stats.evicted_unfetched);
if (settings.slab_reassign) {
APPEND_STAT("slab_reassign_running", "%u", stats.slab_reassign_running);
APPEND_STAT("slabs_moved", "%llu", stats.slabs_moved);
View
@@ -533,6 +533,7 @@ int item_link(item *it);
void item_remove(item *it);
int item_replace(item *it, item *new_it, const uint32_t hv);
void item_stats(ADD_STAT add_stats, void *c);
+void item_stats_totals(ADD_STAT add_stats, void *c);
void item_stats_sizes(ADD_STAT add_stats, void *c);
void item_unlink(item *it);
void item_update(item *it);
View
@@ -293,11 +293,8 @@ bool get_stats(const char *stat_type, int nkey, ADD_STAT add_stats, void *c) {
APPEND_STAT("bytes", "%llu", (unsigned long long)stats.curr_bytes);
APPEND_STAT("curr_items", "%u", stats.curr_items);
APPEND_STAT("total_items", "%u", stats.total_items);
- APPEND_STAT("evictions", "%llu",
- (unsigned long long)stats.evictions);
- APPEND_STAT("reclaimed", "%llu",
- (unsigned long long)stats.reclaimed);
STATS_UNLOCK();
+ item_stats_totals(add_stats, c);
} else if (nz_strcmp(nkey, stat_type, "items") == 0) {
item_stats(add_stats, c);
} else if (nz_strcmp(nkey, stat_type, "slabs") == 0) {
View
@@ -631,6 +631,12 @@ void item_stats(ADD_STAT add_stats, void *c) {
mutex_unlock(&cache_lock);
}
+void item_stats_totals(ADD_STAT add_stats, void *c) {
+ mutex_lock(&cache_lock);
+ do_item_stats_totals(add_stats, c);
+ mutex_unlock(&cache_lock);
+}
+
/*
* Dumps a list of objects of each size in 32-byte increments
*/

0 comments on commit 67d7cfc

Please sign in to comment.