From c2e0023d0235a055e6fe025f560cf388abfeab98 Mon Sep 17 00:00:00 2001 From: dormando Date: Sun, 15 Jul 2012 20:19:42 -0700 Subject: 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. --- slabs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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; -- cgit v1.2.1