]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: only use aio for read if there are >1 blobs 13066/head
authorSage Weil <sage@redhat.com>
Tue, 24 Jan 2017 14:42:24 +0000 (09:42 -0500)
committerSage Weil <sage@redhat.com>
Fri, 27 Jan 2017 15:27:04 +0000 (10:27 -0500)
If we have a single blob to read it is not worth the context switch.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc

index 956a3813edd6a77063e8a9892d002b1012b90092..268eab39d6b45ddb568142b39341da76391f9775 100644 (file)
@@ -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<bufferlist> 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, &reg.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, &reg.bl, &ioc);
+           } else {
+             r = bdev->read(offset, length, &reg.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();