From: Sage Weil Date: Mon, 16 May 2016 00:30:44 +0000 (-0400) Subject: os/bluestore: make tail cache a bit smarter X-Git-Tag: v11.0.0~359^2~73 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f0414b60cfd0dff0872e61b1a63eaa4f590d3c0;p=ceph.git os/bluestore: make tail cache a bit smarter This is really a stop-gap. Since we are doing reads in the pre-commit write path, we need to have some sort of buffer cache so that a sequence of writes in the same transaction can remain coherent (the second write must "read" the first write in order to fill out the chunk). Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 4ca926f0996b..8ae9697b786d 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5267,22 +5267,35 @@ void BlueStore::_do_write_small( bufferlist bl; blp.copy(length, bl); - // use tail cache? only worry about a perfect append for now. - // (fixme: we could also handle near-appends that fall within the - // same block or read_block or whatever.) - if (offset == o->onode.size && + // use tail cache? + if (offset >= o->onode.size && o->tail_bl.length() && - offset == o->tail_offset + o->tail_bl.length()) { - // use tail? - bufferlist t = o->tail_bl; - t.claim_append(bl); - bl.swap(t); - offset -= o->tail_bl.length(); - length += o->tail_bl.length(); - dout(10) << __func__ << " using tail_bl 0x" << std::hex - << o->tail_offset << "~0x" << o->tail_bl.length() - << ", write is now 0x" << offset << "~0x" << length - << std::dec << dendl; + offset > o->tail_offset) { + uint64_t tend = o->tail_offset + o->tail_bl.length(); + uint64_t tlen = 0, zlen = 0; + if (offset <= tend) { + tlen = offset - o->tail_offset; + zlen = 0; + } else if (offset < ROUND_UP_TO(tend, min_alloc_size)) { + tlen = o->tail_bl.length(); + zlen = offset - tend; + } + if (tlen || zlen) { + bufferlist t; + t.substr_of(o->tail_bl, 0, tlen); + if (zlen) { + t.append_zero(zlen); + } + t.claim_append(bl); + bl.swap(t); + offset -= tlen + zlen; + length += tlen + zlen; + dout(10) << __func__ << " using tail_bl 0x" << std::hex + << o->tail_offset << "~0x" << tlen + << ", 0x" << zlen + << " zeros, write is now 0x" << offset << "~0x" << length + << std::dec << dendl; + } } // look for an existing mutable blob we can use