Skip to content

Commit

Permalink
slab rebalancing from random class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dormando committed Jul 27, 2012
1 parent 57a9856 commit c2e0023
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions slabs.c
Expand Up @@ -786,13 +786,39 @@ 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;

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;
Expand Down

0 comments on commit c2e0023

Please sign in to comment.