Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dormando committed Jul 27, 2012
1 parent c2e0023 commit 63bf748
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
10 changes: 10 additions & 0 deletions items.c
Expand Up @@ -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);
}
Expand Down
20 changes: 14 additions & 6 deletions memcached.c
Expand Up @@ -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;
}

/*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion memcached.h
Expand Up @@ -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 */
};

Expand Down
13 changes: 8 additions & 5 deletions slabs.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 63bf748

Please sign in to comment.