From ad9168f39697da9ebb2cf019dea6924df1068efc Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 24 Mar 2018 20:26:37 -0500 Subject: [PATCH] osdc/Striper: rewrite assemble_result without push_front or claim_prepend Make a single forward pass across the map while still avoiding tailing zeroes in the !zero_tail case. Signed-off-by: Sage Weil --- src/osdc/Striper.cc | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/osdc/Striper.cc b/src/osdc/Striper.cc index 8ca4825ec470b..66a4e44e35074 100644 --- a/src/osdc/Striper.cc +++ b/src/osdc/Striper.cc @@ -354,36 +354,21 @@ void Striper::StripedReadResult::assemble_result(CephContext *cct, { ldout(cct, 10) << "assemble_result(" << this << ") zero_tail=" << zero_tail << dendl; - - // go backwards, so that we can efficiently discard zeros - map >::reverse_iterator p - = partial.rbegin(); - if (p == partial.rend()) - return; - - uint64_t end = p->first + p->second.second; - while (p != partial.rend()) { - // sanity check - ldout(cct, 20) << "assemble_result(" << this << ") " << p->first << "~" - << p->second.second << " " << p->second.first.length() - << " bytes" << dendl; - assert(p->first == end - p->second.second); - end = p->first; - - size_t len = p->second.first.length(); - if (len < p->second.second) { - if (zero_tail || bl.length()) { - bufferptr bp(p->second.second - len); - bp.zero(); - bl.push_front(std::move(bp)); - bl.claim_prepend(p->second.first); - } else { - bl.claim_prepend(p->second.first); + size_t zeros = 0; // zeros preceding current position + for (auto& p : partial) { + size_t got = p.second.first.length(); + size_t expect = p.second.second; + if (got) { + if (zeros) { + bl.append_zero(zeros); + zeros = 0; } - } else { - bl.claim_prepend(p->second.first); + bl.claim_append(p.second.first); } - ++p; + zeros += expect - got; + } + if (zero_tail && zeros) { + bl.append_zero(zeros); } partial.clear(); } -- 2.39.5