From 2df9aa8e793d2450771e7ca509baa53bc92f9202 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 6 Sep 2016 16:50:46 -0400 Subject: [PATCH] os/bluestore: make blob_t unused helpers use logical length These were taking min_alloc_size, but this can change across mounts; better to use the logical blob length instead (that's what we want anyway!). Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 17 +++++++++-------- src/os/bluestore/bluestore_types.cc | 4 ++-- src/os/bluestore/bluestore_types.h | 27 +++++++++++++++------------ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a9274cd8b4944..d1890b5c7fdba 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -6969,7 +6969,7 @@ void BlueStore::_do_write_small( uint64_t b_len = length + head_pad + tail_pad; if ((b_off % chunk_size == 0 && b_len % chunk_size == 0) && b->get_blob().get_ondisk_length() >= b_off + b_len && - b->get_blob().is_unused(b_off, b_len, min_alloc_size) && + b->get_blob().is_unused(b_off, b_len) && b->get_blob().is_allocated(b_off, b_len)) { dout(20) << __func__ << " write to unused 0x" << std::hex << b_off << "~" << b_len @@ -6989,7 +6989,7 @@ void BlueStore::_do_write_small( dout(20) << __func__ << " lex old " << *ep << dendl; Extent *le = o->extent_map.set_lextent(offset, b_off + head_pad, length, b, &wctx->old_extents); - b->dirty_blob().mark_used(le->blob_offset, le->length, min_alloc_size); + b->dirty_blob().mark_used(le->blob_offset, le->length); txc->statfs_delta.stored() += le->length; dout(20) << __func__ << " lex " << *le << dendl; return; @@ -7061,7 +7061,7 @@ void BlueStore::_do_write_small( << " at " << op->extents << dendl; Extent *le = o->extent_map.set_lextent(offset, offset - bstart, length, b, &wctx->old_extents); - b->dirty_blob().mark_used(le->blob_offset, le->length, min_alloc_size); + b->dirty_blob().mark_used(le->blob_offset, le->length); txc->statfs_delta.stored() += le->length; dout(20) << __func__ << " lex " << *le << dendl; return; @@ -7242,12 +7242,13 @@ int BlueStore::_do_alloc_write( if (wi.mark_unused) { auto b_off = wi.b_off; auto b_len = wi.bl.length(); - if (b_off) - b->dirty_blob().add_unused(0, b_off, min_alloc_size); - if (b_off + b_len < wi.blob_length) + if (b_off) { + b->dirty_blob().add_unused(0, b_off); + } + if (b_off + b_len < wi.blob_length) { b->dirty_blob().add_unused(b_off + b_len, - wi.blob_length - (b_off + b_len), - min_alloc_size); + wi.blob_length - (b_off + b_len)); + } } // queue io diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index e38ff30ab03a6..a484ea20667b0 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -541,8 +541,8 @@ void bluestore_blob_t::generate_test_instances(list& ls) ls.push_back(new bluestore_blob_t); ls.back()->init_csum(CSUM_XXHASH32, 16, 65536); ls.back()->csum_data = buffer::claim_malloc(4, strdup("abcd")); - ls.back()->add_unused(0, 3, 4096); - ls.back()->add_unused(8, 8, 4096); + ls.back()->add_unused(0, 3); + ls.back()->add_unused(8, 8); ls.back()->extents.emplace_back(bluestore_pextent_t(0x40100000, 0x10000)); ls.back()->extents.emplace_back( bluestore_pextent_t(bluestore_pextent_t::INVALID_OFFSET, 0x1000)); diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 52c9eab9e3081..5da333d17a784 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -394,13 +394,14 @@ struct bluestore_blob_t { } /// return true if the logical range has never been used - bool is_unused(uint64_t offset, uint64_t length, uint64_t min_alloc_size) const { + bool is_unused(uint64_t offset, uint64_t length) const { if (!has_unused()) { return false; } - assert((min_alloc_size % unused.size()) == 0); - assert(offset + length <= min_alloc_size); - uint64_t chunk_size = min_alloc_size / unused.size(); + uint64_t blob_len = get_logical_length(); + assert((blob_len % unused.size()) == 0); + assert(offset + length <= blob_len); + uint64_t chunk_size = blob_len / unused.size(); uint64_t start = offset / chunk_size; uint64_t end = ROUND_UP_TO(offset + length, chunk_size) / chunk_size; assert(end <= unused.size()); @@ -412,10 +413,11 @@ struct bluestore_blob_t { } /// mark a range that has never been used - void add_unused(uint64_t offset, uint64_t length, uint64_t min_alloc_size) { - assert((min_alloc_size % unused.size()) == 0); - assert(offset + length <= min_alloc_size); - uint64_t chunk_size = min_alloc_size / unused.size(); + void add_unused(uint64_t offset, uint64_t length) { + uint64_t blob_len = get_logical_length(); + assert((blob_len % unused.size()) == 0); + assert(offset + length <= blob_len); + uint64_t chunk_size = blob_len / unused.size(); uint64_t start = ROUND_UP_TO(offset, chunk_size) / chunk_size; uint64_t end = (offset + length) / chunk_size; assert(end <= unused.size()); @@ -428,11 +430,12 @@ struct bluestore_blob_t { } /// indicate that a range has (now) been used. - void mark_used(uint64_t offset, uint64_t length, uint64_t min_alloc_size) { + void mark_used(uint64_t offset, uint64_t length) { if (has_unused()) { - assert((min_alloc_size % unused.size()) == 0); - assert(offset + length <= min_alloc_size); - uint64_t chunk_size = min_alloc_size / unused.size(); + uint64_t blob_len = get_logical_length(); + assert((blob_len % unused.size()) == 0); + assert(offset + length <= blob_len); + uint64_t chunk_size = blob_len / unused.size(); uint64_t start = offset / chunk_size; uint64_t end = ROUND_UP_TO(offset + length, chunk_size) / chunk_size; assert(end <= unused.size()); -- 2.39.5