diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 0b3055b6abb48f..94672f841d0ec8 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -607,7 +607,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.read(); + unsigned prob = promote_probability_millis; 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; @@ -664,9 +664,9 @@ void OSDService::promote_throttle_recalibrate() dout(10) << __func__ << " actual " << actual << ", actual/prob ratio " << ratio << ", adjusted new_prob " << new_prob - << ", prob " << promote_probability_millis.read() << " -> " << prob + << ", prob " << promote_probability_millis << " -> " << prob << dendl; - promote_probability_millis.set(prob); + promote_probability_millis = prob; // set hard limits for this interval to mitigate stampedes promote_max_objects = target_obj_sec * OSD::OSD_TICK_INTERVAL * 2; @@ -2738,9 +2738,9 @@ int OSD::shutdown() ++p) { dout(20) << " kicking pg " << p->first << dendl; p->second->lock(); - if (p->second->ref.read() != 1) { + if (p->second->ref != 1) { derr << "pgid " << p->first << " has ref count of " - << p->second->ref.read() << dendl; + << p->second->ref << dendl; #ifdef PG_DEBUG_REFS p->second->dump_live_ids(); #endif diff --git a/src/osd/OSD.h b/src/osd/OSD.h index b657fb46e9a7c7..8755840a3c9210 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -796,7 +796,7 @@ class OSDService { private: /// throttle promotion attempts - atomic_t promote_probability_millis; ///< probability thousands. one word. + atomic_uint promote_probability_millis; ///< probability thousands. one word. PromoteCounter promote_counter; utime_t last_recalibrate; unsigned long promote_max_objects, promote_max_bytes; @@ -805,13 +805,13 @@ class OSDService { bool promote_throttle() { // NOTE: lockless! we rely on the probability being a single word. promote_counter.attempt(); - if ((unsigned)rand() % 1000 > promote_probability_millis.read()) + if ((unsigned)rand() % 1000 > promote_probability_millis) return true; // yes throttle (no promote) if (promote_max_objects && - promote_counter.objects.read() > promote_max_objects) + promote_counter.objects > promote_max_objects) return true; // yes throttle if (promote_max_bytes && - promote_counter.bytes.read() > promote_max_bytes) + promote_counter.bytes > promote_max_bytes) return true; // yes throttle return false; // no throttle (promote) } @@ -840,9 +840,9 @@ class OSDService { // -- tids -- // for ops i issue - atomic_t last_tid; + atomic_uint last_tid; ceph_tid_t get_tid() { - return (ceph_tid_t)last_tid.inc(); + return (ceph_tid_t)last_tid++; } // -- backfill_reservation -- @@ -1024,18 +1024,18 @@ class OSDService { NOT_STOPPING, PREPARING_TO_STOP, STOPPING }; - atomic_t state; + atomic_int state; int get_state() { - return state.read(); + return state; } void set_state(int s) { - state.set(s); + state = s; } bool is_stopping() { - return get_state() == STOPPING; + return state == STOPPING; } bool is_preparing_to_stop() { - return get_state() == PREPARING_TO_STOP; + return state == PREPARING_TO_STOP; } bool prepare_to_stop(); void got_stop_ack(); @@ -1241,32 +1241,32 @@ class OSD : public Dispatcher, } private: - atomic_t state; + atomic_int state; public: int get_state() { - return state.read(); + return state; } void set_state(int s) { - state.set(s); + state = s; } bool is_initializing() { - return get_state() == STATE_INITIALIZING; + return state == STATE_INITIALIZING; } bool is_preboot() { - return get_state() == STATE_PREBOOT; + return state == STATE_PREBOOT; } bool is_booting() { - return get_state() == STATE_BOOTING; + return state == STATE_BOOTING; } bool is_active() { - return get_state() == STATE_ACTIVE; + return state == STATE_ACTIVE; } bool is_stopping() { - return get_state() == STATE_STOPPING; + return state == STATE_STOPPING; } bool is_waiting_for_healthy() { - return get_state() == STATE_WAITING_FOR_HEALTHY; + return state == STATE_WAITING_FOR_HEALTHY; } private: diff --git a/src/osd/PG.cc b/src/osd/PG.cc index c2dfabd66a8be1..9f6fed458430c1 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -79,7 +79,7 @@ static ostream& _prefix(std::ostream *_dout, T *t) void PG::get(const char* tag) { - ref.inc(); + ref++; #ifdef PG_DEBUG_REFS Mutex::Locker l(_ref_id_lock); if (!_tag_counts.count(tag)) { @@ -101,14 +101,14 @@ void PG::put(const char* tag) } } #endif - if (ref.dec() == 0) + if (--ref== 0) delete this; } #ifdef PG_DEBUG_REFS uint64_t PG::get_with_id() { - ref.inc(); + ref++; Mutex::Locker l(_ref_id_lock); uint64_t id = ++_ref_id; BackTrace bt(0); @@ -128,7 +128,7 @@ void PG::put_with_id(uint64_t id) assert(_live_ids.count(id)); _live_ids.erase(id); } - if (ref.dec() == 0) + if (--ref == 0) delete this; } diff --git a/src/osd/PG.h b/src/osd/PG.h index efcd99d63348d8..b47ade5dec2308 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -33,7 +33,7 @@ #include "osd_types.h" #include "include/buffer_fwd.h" #include "include/xlist.h" -#include "include/atomic.h" +// #include "include/atomic.h" #include "SnapMapper.h" #include "PGLog.h" @@ -50,6 +50,7 @@ #include "include/str_list.h" #include "PGBackend.h" +#include #include #include #include @@ -245,7 +246,7 @@ class PG : DoutPrefixProvider { * put_unlock() when done with the current pointer (_most common_). */ mutable Mutex _lock; - atomic_t ref; + atomic_uint ref; #ifdef PG_DEBUG_REFS Mutex _ref_id_lock; diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 619a5e659f0db7..940f962c5a290d 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -43,6 +43,7 @@ #include "OpRequest.h" #include "include/cmp.h" #include "librados/ListObjectImpl.h" +#include #define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026" @@ -4280,24 +4281,24 @@ enum scrub_error_type { // PromoteCounter struct PromoteCounter { - atomic64_t attempts, objects, bytes; + std::atomic_uint_fast64_t attempts, objects, bytes; void attempt() { - attempts.inc(); + attempts++; } void finish(uint64_t size) { - objects.inc(); - bytes.add(size); + objects++; + bytes += size; } void sample_and_attenuate(uint64_t *a, uint64_t *o, uint64_t *b) { - *a = attempts.read(); - *o = objects.read(); - *b = bytes.read(); - attempts.set(*a / 2); - objects.set(*o / 2); - bytes.set(*b / 2); + *a = attempts; + *o = objects; + *b = bytes; + attempts = *a / 2; + objects = *o / 2; + bytes = *b / 2; } };