/* Slab rebalancer thread. * Does not use spinlocks since it is not timing sensitive. Burn less CPU and * go to sleep if locks are contended */ static void *slab_maintenance_thread(void *arg) { int was_busy = 0; int src, dest; while (do_run_slab_thread) { if (slab_rebalance_signal == 1) { if (slab_rebalance_start() < 0) { /* Handle errors with more specifity as required. */ slab_rebalance_signal = 0; } } else if (slab_rebalance_signal && slab_rebal.slab_start != NULL) { /* If we have a decision to continue, continue it */ was_busy = slab_rebalance_move(); } else if (settings.slab_automove && slab_automove_decision(&src, &dest) == 1) { /* Blind to the return codes. It will retry on its own */ slabs_reassign(src, dest); } if (slab_rebal.done) { slab_rebalance_finish(); } /* Sleep a bit if no work to do, or waiting on busy objects */ if (was_busy || !slab_rebalance_signal) sleep(1); } return NULL; }
/* Slab rebalancer thread. * Does not use spinlocks since it is not timing sensitive. Burn less CPU and * go to sleep if locks are contended */ static void *slab_maintenance_thread(void *arg) { int src, dest; while (do_run_slab_thread) { 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); } sleep(1); } else { /* Don't wake as often if we're not enabled. * This is lazier than setting up a condition right now. */ sleep(5); } } return NULL; }
/* Slab rebalancer thread. * Does not use spinlocks since it is not timing sensitive. Burn less CPU and * go to sleep if locks are contended */ static void *slab_maintenance_thread(void *arg) { int src, dest; //src是失败次数很少,或者很平均的那个slab-class id,dest是那些分配失败次数骤增的slab-class id while (do_run_slab_thread) { if (settings.slab_automove == 1)//如果是前面的激烈模式,slab_automove=2,就不用该线程去选择移动的slab,每次失败主动会去移动那些slab { if (slab_automove_decision(&src, &dest) == 1)//这里是具体的选择src和dest的处理函数 { /* Blind to the return codes. It will retry on its own */ slabs_reassign(src, dest); } sleep(1); } else { /* Don't wake as often if we're not enabled. * This is lazier than setting up a condition right now. */ sleep(5); } } return NULL; }