]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ObjectCacher: don't loop the extents of OSDRead in map_read
authorZhiqiang Wang <zhiqiang@xsky.com>
Wed, 24 Feb 2016 13:54:34 +0000 (21:54 +0800)
committerJason Dillaman <dillaman@redhat.com>
Thu, 9 Jun 2016 18:06:07 +0000 (14:06 -0400)
Looping the extents of OSDRead is done in _readx. The looping in
map_read is not needed.

Signed-off-by: Zhiqiang Wang <zhiqiang@xsky.com>
(cherry picked from commit fae912c3856cab6d03183411eecab90c6e6732d2)

src/osdc/ObjectCacher.cc
src/osdc/ObjectCacher.h

index bb592c1c20a3061cb451b4a9ca761ab35c8f74c2..6fc815d617cf29f4e423b456f3c7924be30bf83a 100644 (file)
@@ -213,99 +213,89 @@ bool ObjectCacher::Object::include_all_cached_data(loff_t off, loff_t len)
  * map a range of bytes into buffer_heads.
  * - create missing buffer_heads as necessary.
  */
-int ObjectCacher::Object::map_read(OSDRead *rd,
-                                  map<loff_t, BufferHead*>& hits,
-                                  map<loff_t, BufferHead*>& missing,
-                                  map<loff_t, BufferHead*>& rx,
+int ObjectCacher::Object::map_read(ObjectExtent &ex,
+                                   map<loff_t, BufferHead*>& hits,
+                                   map<loff_t, BufferHead*>& missing,
+                                   map<loff_t, BufferHead*>& rx,
                                   map<loff_t, BufferHead*>& errors)
 {
   assert(oc->lock.is_locked());
-  for (vector<ObjectExtent>::iterator ex_it = rd->extents.begin();
-       ex_it != rd->extents.end();
-       ++ex_it) {
-
-    if (ex_it->oid != oid.oid)
-      continue;
-
-    ldout(oc->cct, 10) << "map_read " << ex_it->oid
-                      << " " << ex_it->offset << "~" << ex_it->length
-                      << dendl;
+  ldout(oc->cct, 10) << "map_read " << ex.oid 
+              << " " << ex.offset << "~" << ex.length
+              << dendl;
+  
+  loff_t cur = ex.offset;
+  loff_t left = ex.length;
 
-    loff_t cur = ex_it->offset;
-    loff_t left = ex_it->length;
-
-    map<loff_t, BufferHead*>::iterator p = data_lower_bound(ex_it->offset);
-    while (left > 0) {
-      // at end?
-      if (p == data.end()) {
-       // rest is a miss.
-       BufferHead *n = new BufferHead(this);
-       n->set_start(cur);
-       n->set_length(left);
-       oc->bh_add(this, n);
-       if (complete) {
-         oc->mark_zero(n);
-         hits[cur] = n;
-         ldout(oc->cct, 20) << "map_read miss+complete+zero " << left
-                            << " left, " << *n << dendl;
-       } else {
-         missing[cur] = n;
-         ldout(oc->cct, 20) << "map_read miss " << left << " left, " << *n
-                            << dendl;
-       }
-       cur += left;
-       assert(cur == (loff_t)ex_it->offset + (loff_t)ex_it->length);
-       break;  // no more.
+  map<loff_t, BufferHead*>::iterator p = data_lower_bound(ex.offset);
+  while (left > 0) {
+    // at end?
+    if (p == data.end()) {
+      // rest is a miss.
+      BufferHead *n = new BufferHead(this);
+      n->set_start(cur);
+      n->set_length(left);
+      oc->bh_add(this, n);
+      if (complete) {
+        oc->mark_zero(n);
+        hits[cur] = n;
+        ldout(oc->cct, 20) << "map_read miss+complete+zero " << left << " left, " << *n << dendl;
+      } else {
+        missing[cur] = n;
+        ldout(oc->cct, 20) << "map_read miss " << left << " left, " << *n << dendl;
       }
-
-      if (p->first <= cur) {
-       // have it (or part of it)
-       BufferHead *e = p->second;
-
-       if (e->is_clean() ||
-           e->is_dirty() ||
-           e->is_tx() ||
-           e->is_zero()) {
-         hits[cur] = e;     // readable!
-         ldout(oc->cct, 20) << "map_read hit " << *e << dendl;
-       } else if (e->is_rx()) {
-         rx[cur] = e;       // missing, not readable.
-         ldout(oc->cct, 20) << "map_read rx " << *e << dendl;
-       } else if (e->is_error()) {
-         errors[cur] = e;
-         ldout(oc->cct, 20) << "map_read error " << *e << dendl;
-       } else {
-         assert(0);
-       }
-
-       loff_t lenfromcur = MIN(e->end() - cur, left);
-       cur += lenfromcur;
-       left -= lenfromcur;
-       ++p;
-       continue;  // more?
-
-      } else if (p->first > cur) {
-       // gap.. miss
-       loff_t next = p->first;
-       BufferHead *n = new BufferHead(this);
-       loff_t len = MIN(next - cur, left);
-       n->set_start(cur);
-       n->set_length(len);
-       oc->bh_add(this,n);
-       if (complete) {
-         oc->mark_zero(n);
-         hits[cur] = n;
-         ldout(oc->cct, 20) << "map_read gap+complete+zero " << *n << dendl;
-       } else {
-         missing[cur] = n;
-         ldout(oc->cct, 20) << "map_read gap " << *n << dendl;
-       }
-       cur += MIN(left, n->length());
-       left -= MIN(left, n->length());
-       continue;    // more?
+      cur += left;
+      assert(cur == (loff_t)ex.offset + (loff_t)ex.length);
+      break;  // no more.
+    }
+    
+    if (p->first <= cur) {
+      // have it (or part of it)
+      BufferHead *e = p->second;
+
+      if (e->is_clean() ||
+          e->is_dirty() ||
+          e->is_tx() ||
+          e->is_zero()) {
+        hits[cur] = e;     // readable!
+        ldout(oc->cct, 20) << "map_read hit " << *e << dendl;
+      } else if (e->is_rx()) {
+        rx[cur] = e;       // missing, not readable.
+        ldout(oc->cct, 20) << "map_read rx " << *e << dendl;
+      } else if (e->is_error()) {
+        errors[cur] = e;
+        ldout(oc->cct, 20) << "map_read error " << *e << dendl;
+      } else {
+        assert(0);
+      }
+      
+      loff_t lenfromcur = MIN(e->end() - cur, left);
+      cur += lenfromcur;
+      left -= lenfromcur;
+      ++p;
+      continue;  // more?
+      
+    } else if (p->first > cur) {
+      // gap.. miss
+      loff_t next = p->first;
+      BufferHead *n = new BufferHead(this);
+      loff_t len = MIN(next - cur, left);
+      n->set_start(cur);
+      n->set_length(len);
+      oc->bh_add(this,n);
+      if (complete) {
+        oc->mark_zero(n);
+        hits[cur] = n;
+        ldout(oc->cct, 20) << "map_read gap+complete+zero " << *n << dendl;
       } else {
-       assert(0);
+        missing[cur] = n;
+        ldout(oc->cct, 20) << "map_read gap " << *n << dendl;
       }
+      cur += MIN(left, n->length());
+      left -= MIN(left, n->length());
+      continue;    // more?
+    } else {
+      assert(0);
     }
   }
   return 0;
@@ -1323,7 +1313,7 @@ int ObjectCacher::_readx(OSDRead *rd, ObjectSet *oset, Context *onfinish,
 
     // map extent into bufferheads
     map<loff_t, BufferHead*> hits, missing, rx, errors;
-    o->map_read(rd, hits, missing, rx, errors);
+    o->map_read(*ex_it, hits, missing, rx, errors);
     if (external_call) {
       // retry reading error buffers
       missing.insert(errors.begin(), errors.end());
index baff748de1bcce5a894dd4aecaa2d8cd62894486..0d93942c1f6752874ada4357591ba4353d0ac8a9 100644 (file)
@@ -344,10 +344,10 @@ class ObjectCacher {
 
     bool is_cached(loff_t off, loff_t len);
     bool include_all_cached_data(loff_t off, loff_t len);
-    int map_read(OSDRead *rd,
-                map<loff_t, BufferHead*>& hits,
-                map<loff_t, BufferHead*>& missing,
-                map<loff_t, BufferHead*>& rx,
+    int map_read(ObjectExtent &ex,
+                 map<loff_t, BufferHead*>& hits,
+                 map<loff_t, BufferHead*>& missing,
+                 map<loff_t, BufferHead*>& rx,
                 map<loff_t, BufferHead*>& errors);
     BufferHead *map_write(ObjectExtent &ex, ceph_tid_t tid);