From: Jianpeng Ma Date: Fri, 26 May 2017 10:13:15 +0000 (+0800) Subject: os/bluestore/BlueStore: avoid iterating to get ios/cost in _kv_sync_thread. X-Git-Tag: v12.1.0~57^2~21^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=45113968b8e63551e08f37e3f5022fd2ef2c504f;p=ceph.git os/bluestore/BlueStore: avoid iterating to get ios/cost in _kv_sync_thread. Signed-off-by: Jianpeng Ma --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 68f6a277d1ca..72016d2317a9 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7516,6 +7516,9 @@ void BlueStore::_txc_state_proc(TransContext *txc) kv_queue_unsubmitted.push_back(txc); ++txc->osr->kv_committing_serially; } + if (txc->had_ios) + kv_ios++; + kv_throttle_costs += txc->cost; } return; case TransContext::STATE_KV_SUBMITTED: @@ -7962,6 +7965,8 @@ void BlueStore::_kv_sync_thread() } else { deque kv_submitting; deque deferred_done, deferred_stable; + uint64_t aios = 0, costs = 0; + dout(20) << __func__ << " committing " << kv_queue.size() << " submitting " << kv_queue_unsubmitted.size() << " deferred done " << deferred_done_queue.size() @@ -7971,6 +7976,10 @@ void BlueStore::_kv_sync_thread() kv_submitting.swap(kv_queue_unsubmitted); deferred_done.swap(deferred_done_queue); deferred_stable.swap(deferred_stable_queue); + aios = kv_ios; + costs = kv_throttle_costs; + kv_ios = 0; + kv_throttle_costs = 0; utime_t start = ceph_clock_now(); l.unlock(); @@ -7979,22 +7988,13 @@ void BlueStore::_kv_sync_thread() dout(30) << __func__ << " deferred_done " << deferred_done << dendl; dout(30) << __func__ << " deferred_stable " << deferred_stable << dendl; - int num_aios = 0; - uint64_t total_cost = 0; - for (auto txc : kv_committing) { - if (txc->had_ios) { - ++num_aios; - } - total_cost += txc->cost; - } - bool force_flush = false; // if bluefs is sharing the same device as data (only), then we // can rely on the bluefs commit to flush the device and make // deferred aios stable. that means that if we do have done deferred // txcs AND we are not on a single device, we need to force a flush. if (bluefs_single_shared_device && bluefs) { - if (num_aios) { + if (aios) { force_flush = true; } else if (kv_committing.empty() && kv_submitting.empty() && deferred_stable.empty()) { @@ -8006,7 +8006,7 @@ void BlueStore::_kv_sync_thread() force_flush = true; if (force_flush) { - dout(20) << __func__ << " num_aios=" << num_aios + dout(20) << __func__ << " num_aios=" << aios << " force_flush=" << (int)force_flush << ", flushing, deferred done->stable" << dendl; // flush/barrier on block device @@ -8073,7 +8073,7 @@ void BlueStore::_kv_sync_thread() // iteration there will already be ops awake. otherwise, we // end up going to sleep, and then wake up when the very first // transaction is ready for commit. - throttle_bytes.put(total_cost); + throttle_bytes.put(costs); PExtentVector bluefs_gift_extents; if (bluefs && diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index b2cc7996fd56..f37c0b1a6756 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1863,6 +1863,9 @@ private: std::atomic max_blob_size = {0}; ///< maximum blob size + uint64_t kv_ios = 0; + uint64_t kv_throttle_costs = 0; + // cache trim control // note that these update in a racy way, but we don't *really* care if