From 63bf748a10d1e55c67783a517d2d4d28d2a14303 Mon Sep 17 00:00:00 2001 From: dormando Date: Sun, 15 Jul 2012 21:03:12 -0700 Subject: automove levels are an int instead of bool now also fix a bug causing slab rebalance thread to spin instead of waiting on the condition... duhr. --- items.c | 10 ++++++++++ memcached.c | 20 ++++++++++++++------ memcached.h | 2 +- slabs.c | 13 ++++++++----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/items.c b/items.c index ab588db..6546f88 100644 --- a/items.c +++ b/items.c @@ -146,6 +146,16 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim do_item_unlink_nolock(it, hash(ITEM_key(it), it->nkey, 0)); /* Initialize the item block: */ it->slabs_clsid = 0; + + /* If we've just evicted an item, and the automover is set to + * angry bird mode, attempt to rip memory into this slab class. + * TODO: Move valid object detection into a function, and on a + * "successful" memory pull, look behind and see if the next alloc + * would be an eviction. Then kick off the slab mover before the + * eviction happens. + */ + if (settings.slab_automove == 2) + slabs_reassign(-1, id); } else { refcount_decr(&search->refcount); } diff --git a/memcached.c b/memcached.c index e1ea9cd..cd7abbb 100644 --- a/memcached.c +++ b/memcached.c @@ -224,7 +224,7 @@ static void settings_init(void) { settings.maxconns_fast = false; settings.hashpower_init = 0; settings.slab_reassign = false; - settings.slab_automove = false; + settings.slab_automove = 0; } /* @@ -2624,7 +2624,7 @@ static void process_stat_settings(ADD_STAT add_stats, void *c) { APPEND_STAT("maxconns_fast", "%s", settings.maxconns_fast ? "yes" : "no"); APPEND_STAT("hashpower_init", "%d", settings.hashpower_init); APPEND_STAT("slab_reassign", "%s", settings.slab_reassign ? "yes" : "no"); - APPEND_STAT("slab_automove", "%s", settings.slab_automove ? "yes" : "no"); + APPEND_STAT("slab_automove", "%d", settings.slab_automove); } static void process_stat(conn *c, token_t *tokens, const size_t ntokens) { @@ -3206,9 +3206,9 @@ static void process_slabs_automove_command(conn *c, token_t *tokens, const size_ level = strtoul(tokens[2].value, NULL, 10); if (level == 0) { - settings.slab_automove = false; - } else if (level == 1) { - settings.slab_automove = true; + settings.slab_automove = 0; + } else if (level == 1 || level == 2) { + settings.slab_automove = level; } else { out_string(c, "ERROR"); return; @@ -4980,7 +4980,15 @@ int main (int argc, char **argv) { settings.slab_reassign = true; break; case SLAB_AUTOMOVE: - settings.slab_automove = true; + if (subopts_value == NULL) { + settings.slab_automove = 1; + break; + } + settings.slab_automove = atoi(subopts_value); + if (settings.slab_automove < 0 || settings.slab_automove > 2) { + fprintf(stderr, "slab_automove must be between 0 and 2\n"); + return 1; + } break; default: printf("Illegal suboption \"%s\"\n", subopts_value); diff --git a/memcached.h b/memcached.h index 97a79d0..17bfd71 100644 --- a/memcached.h +++ b/memcached.h @@ -301,7 +301,7 @@ struct settings { bool sasl; /* SASL on/off */ bool maxconns_fast; /* Whether or not to early close connections */ bool slab_reassign; /* Whether or not slab reassignment is allowed */ - bool slab_automove; /* Whether or not to automatically move slabs */ + int slab_automove; /* Whether or not to automatically move slabs */ int hashpower_init; /* Starting hash power level */ }; diff --git a/slabs.c b/slabs.c index cf8dd0c..2503381 100644 --- a/slabs.c +++ b/slabs.c @@ -734,7 +734,7 @@ static void *slab_maintenance_thread(void *arg) { int src, dest; while (do_run_slab_thread) { - if (settings.slab_automove) { + if (settings.slab_automove == 1) { if (slab_automove_decision(&src, &dest) == 1) { /* Blind to the return codes. It will retry on its own */ slabs_reassign(src, dest); @@ -769,6 +769,13 @@ static void *slab_rebalance_thread(void *arg) { if (slab_rebal.done) { slab_rebalance_finish(); + } else if (was_busy) { + /* Stuck waiting for some items to unlock, so slow down a bit + * to give them a chance to free up */ + usleep(50); + } + + if (slab_rebalance_signal == 0) { /* Wrap the conditional with slabs_lock so we can't accidentally miss * a signal */ /* FIXME: Technically there's a race between @@ -777,10 +784,6 @@ static void *slab_rebalance_thread(void *arg) { mutex_lock(&slabs_lock); pthread_cond_wait(&slab_rebalance_cond, &slabs_lock); pthread_mutex_unlock(&slabs_lock); - } else if (was_busy) { - /* Stuck waiting for some items to unlock, so slow down a bit - * to give them a chance to free up */ - usleep(50); } } return NULL; -- cgit v1.2.1