From 6393565f4e92631699a67bd188308bed6e71af58 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Mar 2016 17:00:53 -0500 Subject: [PATCH] osd: make promote_probability_millis atomic_t This is almost always read, so it should be cheap. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 6 +++--- src/osd/OSD.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 9c7c636f31d97..d73bee9da8792 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -604,7 +604,7 @@ void OSDService::promote_throttle_recalibrate() utime_t now = ceph_clock_now(NULL); double dur = now - last_recalibrate; last_recalibrate = now; - unsigned prob = promote_probability_millis; + unsigned prob = promote_probability_millis.read(); uint64_t target_obj_sec = g_conf->osd_tier_promote_max_objects_sec; uint64_t target_bytes_sec = g_conf->osd_tier_promote_max_bytes_sec; @@ -660,9 +660,9 @@ void OSDService::promote_throttle_recalibrate() dout(10) << __func__ << " actual " << actual << ", actual/prob ratio " << ratio << ", adjusted new_prob " << new_prob - << ", prob " << promote_probability_millis << " -> " << prob + << ", prob " << promote_probability_millis.read() << " -> " << prob << dendl; - promote_probability_millis = prob; + promote_probability_millis.set(prob); // set hard limits for this interval to mitigate stampedes promote_max_objects = target_obj_sec * OSD::OSD_TICK_INTERVAL * 2; diff --git a/src/osd/OSD.h b/src/osd/OSD.h index cf6370aeaca60..ea2552ed533f7 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -782,7 +782,7 @@ public: } /// throttle promotion attempts - unsigned promote_probability_millis; ///< probability thousands. one word. + atomic_t promote_probability_millis; ///< probability thousands. one word. PromoteCounter promote_counter; utime_t last_recalibrate; unsigned long promote_max_objects, promote_max_bytes; @@ -790,7 +790,7 @@ public: bool promote_throttle() { // NOTE: lockless! we rely on the probability being a single word. promote_counter.attempt(); - if ((unsigned)rand() % 1000 > promote_probability_millis) + if ((unsigned)rand() % 1000 > promote_probability_millis.read()) return true; // yes throttle (no promote) if (promote_max_objects && promote_counter.objects.read() > promote_max_objects) -- 2.39.5