From: Zhiqiang Wang Date: Mon, 27 Apr 2015 08:15:26 +0000 (+0800) Subject: os/NewStore: combine contiguous overlays when writing all the overlays X-Git-Tag: v9.1.0~242^2~41 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=793dcc396c055bbe4ce396cdef911c7a5583a3b1;p=ceph.git os/NewStore: combine contiguous overlays when writing all the overlays Combine contiguous overlay writes to reduce the numbers of WAL writes and fs writes. Signed-off-by: Zhiqiang Wang --- diff --git a/src/os/newstore/NewStore.cc b/src/os/newstore/NewStore.cc index 44bdbe0882ae..21407aa20d7d 100644 --- a/src/os/newstore/NewStore.cc +++ b/src/os/newstore/NewStore.cc @@ -3140,8 +3140,7 @@ int NewStore::_do_write_all_overlays(TransContext *txc, assert(f.length == o->onode.size); for (map::iterator p = o->onode.overlay_map.begin(); - p != o->onode.overlay_map.end(); - ++p) { + p != o->onode.overlay_map.end(); ) { dout(10) << __func__ << " overlay " << p->first << "~" << p->second << dendl; string key; @@ -3157,6 +3156,31 @@ int NewStore::_do_write_all_overlays(TransContext *txc, op->data.substr_of(bl, p->second.value_offset, p->second.length); txc->t->rmkey(PREFIX_OVERLAY, key); + + // Combine with later overlays if contiguous + map::iterator prev = p, next = p; + ++next; + while (next != o->onode.overlay_map.end()) { + if (prev->first + prev->second.length == next->first) { + dout(10) << __func__ << " combining overlay " << next->first + << "~" << next->second << dendl; + string key_next; + get_overlay_key(o->onode.nid, next->second.key, &key_next); + bufferlist bl_next, bl_next_data; + db->get(PREFIX_OVERLAY, key_next, &bl_next); + + bl_next_data.substr_of(bl_next, next->second.value_offset, + next->second.length); + bl.claim_append(bl_next_data); + txc->t->rmkey(PREFIX_OVERLAY, key_next); + + ++prev; + ++next; + } else { + break; + } + } + p = next; } // this may double delete something we did above, but that's less