From 6e645985e77bd0597eab6755b6e4071b79967584 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Wed, 24 Feb 2016 21:54:34 +0800 Subject: [PATCH] ObjectCacher: don't loop the extents of OSDRead in map_read Looping the extents of OSDRead is done in _readx. The looping in map_read is not needed. Signed-off-by: Zhiqiang Wang (cherry picked from commit fae912c3856cab6d03183411eecab90c6e6732d2) --- src/osdc/ObjectCacher.cc | 164 ++++++++++++++++++--------------------- src/osdc/ObjectCacher.h | 8 +- 2 files changed, 81 insertions(+), 91 deletions(-) diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc index bb592c1c20a30..6fc815d617cf2 100644 --- a/src/osdc/ObjectCacher.cc +++ b/src/osdc/ObjectCacher.cc @@ -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& hits, - map& missing, - map& rx, +int ObjectCacher::Object::map_read(ObjectExtent &ex, + map& hits, + map& missing, + map& rx, map& errors) { assert(oc->lock.is_locked()); - for (vector::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::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::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 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()); diff --git a/src/osdc/ObjectCacher.h b/src/osdc/ObjectCacher.h index baff748de1bcc..0d93942c1f675 100644 --- a/src/osdc/ObjectCacher.h +++ b/src/osdc/ObjectCacher.h @@ -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& hits, - map& missing, - map& rx, + int map_read(ObjectExtent &ex, + map& hits, + map& missing, + map& rx, map& errors); BufferHead *map_write(ObjectExtent &ex, ceph_tid_t tid); -- 2.39.5