From 73f5d2b73f576deabab9baa65e176d8d5bda2600 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 24 Jan 2017 09:42:24 -0500 Subject: [PATCH] os/bluestore: only use aio for read if there are >1 blobs If we have a single blob to read it is not worth the context switch. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 956a3813edd6a..268eab39d6b45 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5244,6 +5244,7 @@ int BlueStore::_do_read( blobs2read_t blobs2read; unsigned left = length; uint64_t pos = offset; + unsigned num_regions = 0; auto lp = o->extent_map.seek_lextent(offset); while (left > 0 && lp != o->extent_map.extent_map.end()) { if (pos < lp->logical_offset) { @@ -5289,6 +5290,7 @@ int BlueStore::_do_read( dout(30) << __func__ << " will read 0x" << std::hex << pos << ": 0x" << b_off << "~" << l << std::dec << dendl; blobs2read[bptr].emplace_back(region_t(pos, b_off, l)); + ++num_regions; } pos += l; b_off += l; @@ -5298,7 +5300,7 @@ int BlueStore::_do_read( ++lp; } - // read raw blob data + // read raw blob data. use aio if we have >1 blobs to read. vector compressed_blob_bls; IOContext ioc(cct, NULL); for (auto& p : blobs2read) { @@ -5316,7 +5318,13 @@ int BlueStore::_do_read( r = bptr->get_blob().map( 0, bptr->get_blob().get_ondisk_length(), [&](uint64_t offset, uint64_t length) { - int r = bdev->aio_read(offset, length, &bl, &ioc); + int r; + // use aio if there are more regions to read than those in this blob + if (num_regions > p.second.size()) { + r = bdev->aio_read(offset, length, &bl, &ioc); + } else { + r = bdev->read(offset, length, &bl, &ioc, false); + } if (r < 0) return r; return 0; @@ -5347,18 +5355,28 @@ int BlueStore::_do_read( r = bptr->get_blob().map( reg.r_off, r_len, [&](uint64_t offset, uint64_t length) { - int r = bdev->aio_read(offset, length, ®.bl, &ioc); + int r; + // use aio if there is more than one region to read + if (num_regions > 1) { + r = bdev->aio_read(offset, length, ®.bl, &ioc); + } else { + r = bdev->read(offset, length, ®.bl, &ioc, false); + } if (r < 0) return r; return 0; }); if (r < 0) return r; + assert(reg.bl.length() == r_len); } } } - bdev->aio_submit(&ioc); - ioc.aio_wait(); + if (ioc.has_pending_aios()) { + bdev->aio_submit(&ioc); + dout(20) << __func__ << " waiting for aio" << dendl; + ioc.aio_wait(); + } // enumerate and decompress desired blobs auto p = compressed_blob_bls.begin(); -- 2.39.5