summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2012-07-15 20:19:42 -0700
committerdormando <dormando@rydia.net>2012-07-27 12:47:16 -0700
commitc2e0023d0235a055e6fe025f560cf388abfeab98 (patch)
tree29070a98dc1a2a288df2542817d05021db2797af
parent57a9856a2fecc8b3d10c46d459b628c2a8ce269a (diff)
downloadmemcached-c2e0023d0235a055e6fe025f560cf388abfeab98.tar.gz
slab rebalancing from random class
specifying -1 as the src class for a slabs reassign will pick the first available, rolling through the list on each request (so as to not bias against the smaller classes). So if you're in a hurry and have to move memory into class 5, you may now mash it without thinking.
-rw-r--r--slabs.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/slabs.c b/slabs.c
index 9478719..cf8dd0c 100644
--- a/slabs.c
+++ b/slabs.c
@@ -786,6 +786,26 @@ static void *slab_rebalance_thread(void *arg) {
return NULL;
}
+/* Iterate at most once through the slab classes and pick a "random" source.
+ * I like this better than calling rand() since rand() is slow enough that we
+ * can just check all of the classes once instead.
+ */
+static int slabs_reassign_pick_any(int dst) {
+ static int cur = POWER_SMALLEST - 1;
+ int tries = power_largest - POWER_SMALLEST + 1;
+ for (; tries > 0; tries--) {
+ cur++;
+ if (cur > power_largest)
+ cur = POWER_SMALLEST;
+ if (cur == dst)
+ continue;
+ if (slabclass[cur].slabs > 1) {
+ return cur;
+ }
+ }
+ return -1;
+}
+
static enum reassign_result_type do_slabs_reassign(int src, int dst) {
if (slab_rebalance_signal != 0)
return REASSIGN_RUNNING;
@@ -793,6 +813,12 @@ static enum reassign_result_type do_slabs_reassign(int src, int dst) {
if (src == dst)
return REASSIGN_SRC_DST_SAME;
+ /* Special indicator to choose ourselves. */
+ if (src == -1) {
+ src = slabs_reassign_pick_any(dst);
+ /* TODO: If we end up back at -1, return a new error type */
+ }
+
if (src < POWER_SMALLEST || src > power_largest ||
dst < POWER_SMALLEST || dst > power_largest)
return REASSIGN_BADCLASS;