Skip to content

Commit

Permalink
Merge pull request ceph#9778 from ifed01/wip-bluestore-blob-reduce
Browse files Browse the repository at this point in the history
os/bluestore: reduce bluestore blob

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored Jun 18, 2016
2 parents f29473b + 6a71e01 commit ee5c9f6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 89 deletions.
37 changes: 17 additions & 20 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3153,7 +3153,6 @@ int BlueStore::_do_read(
unsigned l_off = pos - lp->first;
unsigned b_off = l_off + lp->second.offset;
unsigned b_len = std::min(left, lp->second.length - l_off);
assert(b_len <= bptr->blob.length - b_off);

ready_regions_t cache_res;
interval_set<uint64_t> cache_interval;
Expand Down Expand Up @@ -5327,7 +5326,7 @@ void BlueStore::_do_write_small(
if (ep != o->onode.extent_map.begin()) {
--ep;
b = c->get_blob(o, ep->second.blob);
if (ep->first + b->blob.get_max_length() <= offset) {
if (ep->first + b->blob.get_ondisk_length() <= offset) {
++ep;
}
}
Expand All @@ -5337,7 +5336,7 @@ void BlueStore::_do_write_small(
}
int64_t blob = ep->second.blob;
b = c->get_blob(o, ep->second.blob);
if (!b->blob.is_mutable()) {
if (!b->blob.is_mutable() || b->blob.is_compressed()) {
dout(20) << __func__ << " ignoring immutable " << blob << ": " << *b
<< dendl;
++ep;
Expand Down Expand Up @@ -5494,15 +5493,15 @@ void BlueStore::_do_write_small(

// new blob.
b = o->blob_map.new_blob(c->cache);
b->blob.length = min_alloc_size;
uint64_t b_off = offset % min_alloc_size;
unsigned alloc_len = min_alloc_size;
uint64_t b_off = offset % alloc_len;
uint64_t b_len = length;
b->bc.write(txc->seq, b_off, bl, wctx->buffered ? 0 : Buffer::FLAG_NOCACHE);
_pad_zeros(&bl, &b_off, &b_len, block_size);
if (b_off)
b->blob.add_unused(0, b_off);
if (b_off + b_len < b->blob.length)
b->blob.add_unused(b_off + b_len, b->blob.length - (b_off + b_len));
if (b_off + b_len < alloc_len)
b->blob.add_unused(b_off + b_len, alloc_len - (b_off + b_len));
o->onode.punch_hole(offset, length, &wctx->lex_old);
bluestore_lextent_t& lex = o->onode.extent_map[offset] =
bluestore_lextent_t(b->id, offset % min_alloc_size, length);
Expand All @@ -5511,7 +5510,7 @@ void BlueStore::_do_write_small(
dout(20) << __func__ << " lex 0x" << std::hex << offset << std::dec
<< ": " << lex << dendl;
dout(20) << __func__ << " new " << b->id << ": " << *b << dendl;
wctx->write(b, b_off, bl);
wctx->write(b, alloc_len, b_off, bl);
return;
}

Expand All @@ -5533,11 +5532,11 @@ void BlueStore::_do_write_big(
<< std::dec << dendl;
while (length > 0) {
Blob *b = o->blob_map.new_blob(c->cache);
auto l = b->blob.length = MIN(max_blob_len, length);
auto l = MIN(max_blob_len, length);
bufferlist t;
blp.copy(l, t);
b->bc.write(txc->seq, 0, t, wctx->buffered ? 0 : Buffer::FLAG_NOCACHE);
wctx->write(b, 0, t);
wctx->write(b, l, 0, t);
o->onode.punch_hole(offset, l, &wctx->lex_old);
o->onode.extent_map[offset] = bluestore_lextent_t(b->id, 0, l);
b->blob.ref_map.get(0, l);
Expand All @@ -5560,7 +5559,7 @@ int BlueStore::_do_alloc_write(

uint64_t need = 0;
for (auto &wi : wctx->writes) {
need += wi.b->blob.length;
need += wi.blob_length;
}
int r = alloc->reserve(need);
if (r < 0) {
Expand All @@ -5574,18 +5573,18 @@ int BlueStore::_do_alloc_write(
Blob *b = wi.b;
uint64_t b_off = wi.b_off;
bufferlist *l = &wi.bl;
uint64_t final_length = b->blob.length;
uint64_t csum_length = b->blob.length;
uint64_t final_length = wi.blob_length;
uint64_t csum_length = wi.blob_length;
unsigned csum_order;
bufferlist compressed_bl;
CompressorRef c;
bool compressed = false;
if (wctx->compress &&
b->blob.length > min_alloc_size &&
wi.blob_length > min_alloc_size &&
(c = compressor) != nullptr) {
// compress
assert(b_off == 0);
assert(b->blob.length == l->length());
assert(wi.blob_length == l->length());
bluestore_compression_header_t chdr;
chdr.type = c->get_type();
// FIXME: memory alignment here is bad
Expand All @@ -5600,7 +5599,7 @@ int BlueStore::_do_alloc_write(
// pad out to min_alloc_size
compressed_bl.append_zero(newlen - rawlen);
logger->inc(l_bluestore_write_pad_bytes, newlen - rawlen);
dout(20) << __func__ << hex << " compressed 0x" << b->blob.length
dout(20) << __func__ << hex << " compressed 0x" << wi.blob_length
<< " -> 0x" << rawlen << " => 0x" << newlen
<< " with " << chdr.type
<< dec << dendl;
Expand All @@ -5622,7 +5621,7 @@ int BlueStore::_do_alloc_write(
}
if (!compressed) {
b->blob.set_flag(bluestore_blob_t::FLAG_MUTABLE);
if (l->length() != b->blob.length) {
if (l->length() != wi.blob_length) {
// hrm, maybe we could do better here, but let's not bother.
dout(20) << __func__ << " forcing csum_order to block_size_order "
<< block_size_order << dendl;
Expand Down Expand Up @@ -5697,9 +5696,7 @@ void BlueStore::_wctx_finish(
}
if (b->blob.ref_map.empty()) {
dout(20) << __func__ << " rm blob " << *b << dendl;
if (compressed) {
txc->statfs_delta.compressed() -= b->blob.get_payload_length();
}
txc->statfs_delta.compressed() -= b->blob.get_compressed_payload_length();
if (l.blob >= 0) {
o->blob_map.erase(b);
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/os/bluestore/BlueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -1346,16 +1346,17 @@ class BlueStore : public ObjectStore,

struct write_item {
Blob *b;
uint64_t blob_length;
uint64_t b_off;
bufferlist bl;

write_item(Blob *b, uint64_t o, bufferlist& bl)
: b(b), b_off(o), bl(bl) {}
write_item(Blob *b, uint64_t blob_len, uint64_t o, bufferlist& bl)
: b(b), blob_length(blob_len), b_off(o), bl(bl) {}
};
vector<write_item> writes; ///< blobs we're writing

void write(Blob *b, uint64_t o, bufferlist& bl) {
writes.emplace_back(write_item(b, o, bl));
void write(Blob *b, uint64_t blob_len, uint64_t o, bufferlist& bl) {
writes.emplace_back(write_item(b, blob_len, o, bl));
}
};

Expand Down
44 changes: 20 additions & 24 deletions src/os/bluestore/bluestore_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void bluestore_extent_ref_map_t::_check() const
}
}

void bluestore_extent_ref_map_t::_maybe_merge_left(map<uint64_t,record_t>::iterator& p)
void bluestore_extent_ref_map_t::_maybe_merge_left(map<uint32_t,record_t>::iterator& p)
{
if (p == ref_map.begin())
return;
Expand All @@ -128,9 +128,9 @@ void bluestore_extent_ref_map_t::_maybe_merge_left(map<uint64_t,record_t>::itera
}
}

void bluestore_extent_ref_map_t::get(uint64_t offset, uint32_t length)
void bluestore_extent_ref_map_t::get(uint32_t offset, uint32_t length)
{
map<uint64_t,record_t>::iterator p = ref_map.lower_bound(offset);
map<uint32_t,record_t>::iterator p = ref_map.lower_bound(offset);
if (p != ref_map.begin()) {
--p;
if (p->first + p->second.length <= offset) {
Expand All @@ -146,9 +146,9 @@ void bluestore_extent_ref_map_t::get(uint64_t offset, uint32_t length)
}
if (p->first > offset) {
// gap
uint64_t newlen = MIN(p->first - offset, length);
uint32_t newlen = MIN(p->first - offset, length);
p = ref_map.insert(
map<uint64_t,record_t>::value_type(offset,
map<uint32_t,record_t>::value_type(offset,
record_t(newlen, 1))).first;
offset += newlen;
length -= newlen;
Expand All @@ -159,9 +159,9 @@ void bluestore_extent_ref_map_t::get(uint64_t offset, uint32_t length)
if (p->first < offset) {
// split off the portion before offset
assert(p->first + p->second.length > offset);
uint64_t left = p->first + p->second.length - offset;
uint32_t left = p->first + p->second.length - offset;
p->second.length = offset - p->first;
p = ref_map.insert(map<uint64_t,record_t>::value_type(
p = ref_map.insert(map<uint32_t,record_t>::value_type(
offset, record_t(left, p->second.refs))).first;
// continue below
}
Expand All @@ -186,10 +186,10 @@ void bluestore_extent_ref_map_t::get(uint64_t offset, uint32_t length)
}

void bluestore_extent_ref_map_t::put(
uint64_t offset, uint32_t length,
uint32_t offset, uint32_t length,
vector<bluestore_pextent_t> *release)
{
map<uint64_t,record_t>::iterator p = ref_map.lower_bound(offset);
map<uint32_t,record_t>::iterator p = ref_map.lower_bound(offset);
if (p == ref_map.end() || p->first > offset) {
if (p == ref_map.begin()) {
assert(0 == "put on missing extent (nothing before)");
Expand All @@ -200,9 +200,9 @@ void bluestore_extent_ref_map_t::put(
}
}
if (p->first < offset) {
uint64_t left = p->first + p->second.length - offset;
uint32_t left = p->first + p->second.length - offset;
p->second.length = offset - p->first;
p = ref_map.insert(map<uint64_t,record_t>::value_type(
p = ref_map.insert(map<uint32_t,record_t>::value_type(
offset, record_t(left, p->second.refs))).first;
}
while (length > 0) {
Expand Down Expand Up @@ -239,9 +239,9 @@ void bluestore_extent_ref_map_t::put(
_check();
}

bool bluestore_extent_ref_map_t::contains(uint64_t offset, uint32_t length) const
bool bluestore_extent_ref_map_t::contains(uint32_t offset, uint32_t length) const
{
map<uint64_t,record_t>::const_iterator p = ref_map.lower_bound(offset);
map<uint32_t,record_t>::const_iterator p = ref_map.lower_bound(offset);
if (p == ref_map.end() || p->first > offset) {
if (p == ref_map.begin()) {
return false; // nothing before
Expand All @@ -258,7 +258,7 @@ bool bluestore_extent_ref_map_t::contains(uint64_t offset, uint32_t length) cons
return false;
if (p->first + p->second.length >= offset + length)
return true;
uint64_t overlap = p->first + p->second.length - offset;
uint32_t overlap = p->first + p->second.length - offset;
offset += overlap;
length -= overlap;
++p;
Expand All @@ -267,10 +267,10 @@ bool bluestore_extent_ref_map_t::contains(uint64_t offset, uint32_t length) cons
}

bool bluestore_extent_ref_map_t::intersects(
uint64_t offset,
uint32_t offset,
uint32_t length) const
{
map<uint64_t,record_t>::const_iterator p = ref_map.lower_bound(offset);
map<uint32_t,record_t>::const_iterator p = ref_map.lower_bound(offset);
if (p != ref_map.begin()) {
--p;
if (p->first + p->second.length <= offset) {
Expand Down Expand Up @@ -376,7 +376,6 @@ void bluestore_blob_t::encode(bufferlist& bl) const
{
ENCODE_START(1, 1, bl);
::encode(extents, bl);
::encode(length, bl);
::encode(compressed_length, bl);
::encode(flags, bl);
::encode(csum_type, bl);
Expand All @@ -391,7 +390,6 @@ void bluestore_blob_t::decode(bufferlist::iterator& p)
{
DECODE_START(1, p);
::decode(extents, p);
::decode(length, p);
::decode(compressed_length, p);
::decode(flags, p);
::decode(csum_type, p);
Expand All @@ -409,7 +407,6 @@ void bluestore_blob_t::dump(Formatter *f) const
f->dump_object("extent", p);
}
f->close_section();
f->dump_unsigned("length", length);
f->dump_unsigned("compressed_length", compressed_length);
f->dump_unsigned("flags", flags);
f->dump_unsigned("csum_type", csum_type);
Expand All @@ -433,9 +430,9 @@ void bluestore_blob_t::dump(Formatter *f) const
void bluestore_blob_t::generate_test_instances(list<bluestore_blob_t*>& ls)
{
ls.push_back(new bluestore_blob_t);
ls.push_back(new bluestore_blob_t(4096, 0));
ls.push_back(new bluestore_blob_t(4096, bluestore_pextent_t(111, 222), 12));
ls.push_back(new bluestore_blob_t(4096, bluestore_pextent_t(111, 222), 12));
ls.push_back(new bluestore_blob_t(0));
ls.push_back(new bluestore_blob_t(bluestore_pextent_t(111, 222), 12));
ls.push_back(new bluestore_blob_t(bluestore_pextent_t(111, 222), 12));
ls.back()->csum_type = CSUM_XXHASH32;
ls.back()->csum_chunk_order = 16;
ls.back()->csum_data = buffer::claim_malloc(4, strdup("abcd"));
Expand All @@ -447,7 +444,6 @@ void bluestore_blob_t::generate_test_instances(list<bluestore_blob_t*>& ls)
ostream& operator<<(ostream& out, const bluestore_blob_t& o)
{
out << "blob(" << o.extents
<< " len 0x" << std::hex << o.length << std::dec
<< " clen 0x" << std::hex << o.compressed_length << std::dec;
if (o.flags) {
out << " " << o.get_flags_string();
Expand Down Expand Up @@ -514,7 +510,7 @@ void bluestore_blob_t::put_ref(
}
uint64_t end;
if (p == ref_map.ref_map.end()) {
end = this->length;
end = this->get_ondisk_length();
} else {
end = p->first;
}
Expand Down
Loading

0 comments on commit ee5c9f6

Please sign in to comment.