From 815c3d56638eccf9c586555dba3b273e0c745192 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 10 Nov 2010 15:28:39 -0800 Subject: [PATCH] osd: fix sched_scrub Insert whoami into reserved set on primary, not 0! Also more cleanup of sched state helpers. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 35 +++++++++++++++++++++++++++++++++-- src/osd/OSD.h | 1 + src/osd/PG.cc | 6 ++---- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 04f54b89855c7..866978a8e0836 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2233,8 +2233,25 @@ bool OSD::scrub_should_schedule() return false; } + if (loadavgs[0] >= g_conf.osd_scrub_load_threshold) { + dout(20) << "scrub_should_schedule loadavg " << loadavgs[0] + << " >= max " << g_conf.osd_scrub_load_threshold + << " = no, load too high" << dendl; + return false; + } + + bool coin_flip = (rand() % 3) == whoami % 3; + if (!coin_flip) { + dout(20) << "scrub_should_schedule loadavg " << loadavgs[0] + << " < max " << g_conf.osd_scrub_load_threshold + << " = no, randomly backing off" + << dendl; + return false; + } + dout(20) << "scrub_should_schedule loadavg " << loadavgs[0] - << " max " << g_conf.osd_scrub_load_threshold << dendl; + << " < max " << g_conf.osd_scrub_load_threshold + << " = yes" << dendl; return loadavgs[0] < g_conf.osd_scrub_load_threshold; } @@ -2283,10 +2300,13 @@ bool OSD::inc_scrubs_pending() bool result = false; sched_scrub_lock.Lock(); - dout(20) << "attempting to add a pending scrub with " << scrubs_pending << " scrubs_pending and " << scrubs_active << " scrubs_active and " << g_conf.osd_max_scrubs << " max scrubs " << dendl; if (scrubs_pending + scrubs_active < g_conf.osd_max_scrubs) { + dout(20) << "inc_scrubs_pending " << scrubs_pending << " -> " << (scrubs_pending+1) + << " (max " << g_conf.osd_max_scrubs << ", active " << scrubs_active << ")" << dendl; result = true; ++scrubs_pending; + } else { + dout(20) << "inc_scrubs_pending " << scrubs_pending << " + " << scrubs_active << " active >= max " << g_conf.osd_max_scrubs << dendl; } sched_scrub_lock.Unlock(); @@ -2296,11 +2316,22 @@ bool OSD::inc_scrubs_pending() void OSD::dec_scrubs_pending() { sched_scrub_lock.Lock(); + dout(20) << "dec_scrubs_pending " << scrubs_pending << " -> " << (scrubs_pending-1) + << " (max " << g_conf.osd_max_scrubs << ", active " << scrubs_active << ")" << dendl; --scrubs_pending; assert(scrubs_pending >= 0); sched_scrub_lock.Unlock(); } +void OSD::dec_scrubs_active() +{ + sched_scrub_lock.Lock(); + dout(20) << "dec_scrubs_active " << scrubs_active << " -> " << (scrubs_active-1) + << " (max " << g_conf.osd_max_scrubs << ", pending " << scrubs_pending << ")" << dendl; + --scrubs_active; + sched_scrub_lock.Unlock(); +} + // ===================================================== // MAP diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 4f1fb3ad67243..8e267f229a042 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -813,6 +813,7 @@ protected: bool inc_scrubs_pending(); void dec_scrubs_pending(); + void dec_scrubs_active(); // -- scrubbing -- xlist scrub_queue; diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 25f8d17375ea5..737e81bc00701 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -2579,7 +2579,7 @@ bool PG::sched_scrub() if (osd->inc_scrubs_pending()) { dout(20) << "sched_scrub: reserved locally, reserving replicas" << dendl; scrub_reserved = true; - scrub_reserved_peers.insert(0); + scrub_reserved_peers.insert(osd->whoami); scrub_reserve_replicas(); } else { dout(20) << "sched_scrub: failed to reserve locally" << dendl; @@ -3189,9 +3189,7 @@ void PG::scrub() update_stats(); // active -> nothing. - osd->sched_scrub_lock.Lock(); - --(osd->scrubs_active); - osd->sched_scrub_lock.Unlock(); + osd->dec_scrubs_active(); scrub_unreserve_replicas(); -- 2.39.5