]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: manage vector from ExtentList
authorSage Weil <sage@redhat.com>
Tue, 17 Jan 2017 15:56:13 +0000 (10:56 -0500)
committerSage Weil <sage@redhat.com>
Wed, 18 Jan 2017 13:38:44 +0000 (07:38 -0600)
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 <sage@redhat.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueStore.cc
src/os/bluestore/bluestore_types.cc
src/os/bluestore/bluestore_types.h

index f193b3e3d7b7fd127b33633a8683e70d9490daa4..d3c1d0337e0791b4bc9e26e8bad5e7e850227a28 100644 (file)
@@ -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) {
index 7398eae9120b8ed8d09ab382dcf450590cc0d665..ba835c2589f6ec2616dcfc5a2dab8caba223ba5c 100644 (file)
@@ -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);
index a0d51f320ef2fa01f363ccff8db0da46cc89f467..68f9730413b9a2aec1cc8cdf167425ab6600ced3 100644 (file)
@@ -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
index c5bc9f6b4f355d17753a065e7984509a8ed73d94..59f72ded023aecf9dd0514916bf6c8d6643a6a78 100644 (file)
@@ -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();
   }
 };