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; if (slabclass[src].slabs < 2) return REASSIGN_NOSPARE; slab_rebal.s_clsid = src; slab_rebal.d_clsid = dst; slab_rebalance_signal = 1; pthread_cond_signal(&slab_rebalance_cond); return REASSIGN_OK; }
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) {//客户端命令要求随机选出一个源slab class //选出一个页数大于1的slab class,并且该slab class不能是dst //指定的那个。如果不存在这样的slab class,那么返回-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; //源slab class没有或者只有一个内存页,那么就不能分给别的slab class if (slabclass[src].slabs < 2) return REASSIGN_NOSPARE; //全局变量slab_rebal slab_rebal.s_clsid = src;//保存源slab class slab_rebal.d_clsid = dst;//保存目标slab class slab_rebalance_signal = 1; //唤醒slab_rebalance_thread函数的线程 //在slabs_reassign函数中已经锁上了slabs_rebalance_lock pthread_cond_signal(&slab_rebalance_cond); return REASSIGN_OK; }