From: Sage Weil Date: Tue, 17 Jan 2017 15:56:13 +0000 (-0500) Subject: os/bluestore: manage vector from ExtentList X-Git-Tag: v12.0.0~139^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5297858938e91ff54d5e57c4c3129647e47e3492;p=ceph-ci.git os/bluestore: manage vector from ExtentList ExtentList was previous relying the caller to preallocate/size the vector to be large enough for the worst case allocation of extents, and keeping it's own manual count of the extent list size. Instead, manage that from ExtentList, and remove the preallocation from the callers. Fixes: http://tracker.ceph.com/issues/18573 Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index f193b3e3d7b..d3c1d0337e0 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1769,8 +1769,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len, int count = 0; uint64_t alloc_len = 0; - AllocExtentVector extents = AllocExtentVector(left / min_alloc_size); - + AllocExtentVector extents; r = alloc[id]->allocate(left, min_alloc_size, hint, &extents, &count, &alloc_len); if (r < 0 || alloc_len < left) { diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 7398eae9120..ba835c2589f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3810,8 +3810,9 @@ int BlueStore::_balance_bluefs_freespace(PExtentVector *extents) int count = 0; uint64_t alloc_len = 0; - AllocExtentVector exts = AllocExtentVector(gift / min_alloc_size); - r = alloc->allocate(gift, cct->_conf->bluefs_alloc_size, 0, 0, &exts, &count, &alloc_len); + AllocExtentVector exts; + r = alloc->allocate(gift, cct->_conf->bluefs_alloc_size, 0, 0, &exts, + &count, &alloc_len); if (r < 0 || alloc_len < gift) { derr << __func__ << " allocate failed on 0x" << std::hex << gift @@ -8109,8 +8110,7 @@ int BlueStore::_do_alloc_write( int count = 0; uint64_t alloc_len = 0; - AllocExtentVector extents = AllocExtentVector(final_length / min_alloc_size); - + AllocExtentVector extents; int r = alloc->allocate(final_length, min_alloc_size, max_alloc_size, hint, &extents, &count, &alloc_len); assert(r == 0 && alloc_len == final_length); diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index a0d51f320ef..68f9730413b 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -21,8 +21,8 @@ void ExtentList::add_extents(int64_t start, int64_t count) { AllocExtent *last_extent = NULL; bool can_merge = false; - if (m_num_extents > 0) { - last_extent = &((*m_extents)[m_num_extents - 1]); + if (!m_extents->empty()) { + last_extent = &(m_extents->back()); uint64_t last_offset = last_extent->end() / m_block_size; uint32_t last_length = last_extent->length / m_block_size; if ((last_offset == (uint64_t) start) && @@ -34,11 +34,9 @@ void ExtentList::add_extents(int64_t start, int64_t count) { if (can_merge) { last_extent->length += (count * m_block_size); } else { - (*m_extents)[m_num_extents].offset = start * m_block_size; - (*m_extents)[m_num_extents].length = count * m_block_size; - m_num_extents++; + m_extents->emplace_back(AllocExtent(start * m_block_size, + count * m_block_size)); } - assert((int64_t) m_extents->size() >= m_num_extents); } // bluestore_bdev_label_t diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index c5bc9f6b4f3..59f72ded023 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -86,28 +86,29 @@ inline static ostream& operator<<(ostream& out, const AllocExtent& e) { class ExtentList { AllocExtentVector *m_extents; - int64_t m_num_extents; int64_t m_block_size; int64_t m_max_blocks; public: - void init(AllocExtentVector *extents, int64_t block_size, uint64_t max_alloc_size) { + void init(AllocExtentVector *extents, int64_t block_size, + uint64_t max_alloc_size) { m_extents = extents; - m_num_extents = 0; m_block_size = block_size; m_max_blocks = max_alloc_size / block_size; + assert(m_extents->empty()); } ExtentList(AllocExtentVector *extents, int64_t block_size) { init(extents, block_size, 0); } - ExtentList(AllocExtentVector *extents, int64_t block_size, uint64_t max_alloc_size) { + ExtentList(AllocExtentVector *extents, int64_t block_size, + uint64_t max_alloc_size) { init(extents, block_size, max_alloc_size); } void reset() { - m_num_extents = 0; + m_extents->clear(); } void add_extents(int64_t start, int64_t count); @@ -123,7 +124,7 @@ public: } int64_t get_extent_count() { - return m_num_extents; + return m_extents->size(); } };