From: Kefu Chai Date: Mon, 20 Nov 2017 04:21:49 +0000 (+0800) Subject: bluestore: extract IOContext logic out of BlueStore X-Git-Tag: v13.0.1~130^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ca7e91d1470153579353c219621e02f886c43b9f;p=ceph-ci.git bluestore: extract IOContext logic out of BlueStore to avoid HAVE_LIBAIO appearing in BlueStore.cc Signed-off-by: Kefu Chai --- diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index d82139f031f..004976e8a6b 100644 --- a/src/os/bluestore/BlockDevice.cc +++ b/src/os/bluestore/BlockDevice.cc @@ -55,6 +55,33 @@ void IOContext::aio_wait() dout(20) << __func__ << " " << this << " done" << dendl; } +uint64_t IOContext::get_num_ios() const +{ + // this is about the simplest model for transaction cost you can + // imagine. there is some fixed overhead cost by saying there is a + // minimum of one "io". and then we have some cost per "io" that is + // a configurable (with different hdd and ssd defaults), and add + // that to the bytes value. + uint64_t ios = 0; +#ifdef HAVE_LIBAIO + for (auto& p : pending_aios) { + ios += p.iov.size(); + } +#endif +#ifdef HAVE_SPDK + ios += total_nseg; +#endif + return ios; +} + +void IOContext::release_running_aios() +{ +#ifdef HAVE_LIBAIO + // release aio contexts (including pinned buffers). + running_aios.clear(); +#endif +} + BlockDevice *BlockDevice::create(CephContext* cct, const string& path, aio_callback_t cb, void *cbpriv) { diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 89b76becb60..012b31d7e9c 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -72,8 +72,9 @@ public: bool has_pending_aios() { return num_pending.load(); } - + void release_running_aios(); void aio_wait(); + uint64_t get_num_ios() const; void try_aio_wake() { if (num_running == 1) { diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index fc9c3031740..12c464b89ed 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7877,21 +7877,8 @@ BlueStore::TransContext *BlueStore::_txc_create(OpSequencer *osr) void BlueStore::_txc_calc_cost(TransContext *txc) { - // this is about the simplest model for transaction cost you can - // imagine. there is some fixed overhead cost by saying there is a - // minimum of one "io". and then we have some cost per "io" that is - // a configurable (with different hdd and ssd defaults), and add - // that to the bytes value. - int ios = 1; // one "io" for the kv commit -#ifdef HAVE_LIBAIO - for (auto& p : txc->ioc.pending_aios) { - ios += p.iov.size(); - } -#endif -#ifdef HAVE_SPDK - ios += txc->ioc.total_nseg; -#endif - + // one "io" for the kv commit + auto ios = 1 + txc->ioc.get_num_ios(); auto cost = throttle_cost_per_io.load(); txc->cost = ios * cost + txc->bytes; dout(10) << __func__ << " " << txc << " cost " << txc->cost << " (" @@ -8038,10 +8025,7 @@ void BlueStore::_txc_finish_io(TransContext *txc) OpSequencer *osr = txc->osr.get(); std::lock_guard l(osr->qlock); txc->state = TransContext::STATE_IO_DONE; -#ifdef HAVE_LIBAIO - // release aio contexts (including pinned buffers). - txc->ioc.running_aios.clear(); -#endif + txc->ioc.release_running_aios(); OpSequencer::q_list_t::iterator p = osr->q.iterator_to(*txc); while (p != osr->q.begin()) { --p;