]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore:Bluefs balance should use alloc_extent api with bluefs_alloc_size
authorRamesh Chander <Ramesh.Chander@sandisk.com>
Wed, 7 Dec 2016 06:04:30 +0000 (22:04 -0800)
committerRamesh Chander <Ramesh.Chander@sandisk.com>
Sun, 18 Dec 2016 18:40:40 +0000 (10:40 -0800)
Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
src/os/bluestore/BitMapAllocator.cc
src/os/bluestore/BlueStore.cc
src/test/objectstore/Allocator_test.cc

index 7b0f3a8beb1e8457829149e2664c8fb4195b5f98..8e9aa5c41f5e3c94d72dd20199ff9d35187f797b 100644 (file)
@@ -178,26 +178,28 @@ int BitMapAllocator::alloc_extents_cont(
   *count = 0;
   assert(alloc_unit);
   assert(!(alloc_unit % m_block_size));
+  assert(!(want_size % alloc_unit));
   assert(!(max_alloc_size % m_block_size));
 
   int64_t nblks = (want_size + m_block_size - 1) / m_block_size;
   int64_t start_blk = 0;
   int64_t need_blks = nblks;
-  int64_t max_blks = max_alloc_size / m_block_size;
+  int64_t cont_blks = alloc_unit / m_block_size;
 
   ExtentList block_list = ExtentList(extents, m_block_size, max_alloc_size);
 
   while (need_blks > 0) {
     int64_t count = 0;
-    count = m_bit_alloc->alloc_blocks_res(
-      (max_blks && need_blks > max_blks) ? max_blks : need_blks, hint, &start_blk);
+    count = m_bit_alloc->alloc_blocks_res(cont_blks, hint, &start_blk);
     if (count == 0) {
       break;
     }
+    assert(cont_blks == count);
     dout(30) << __func__ <<" instance "<< (uint64_t) this
       << " offset " << start_blk << " length " << count << dendl;
     need_blks -= count;
     block_list.add_extents(start_blk, count);
+    hint = start_blk + count;
   }
 
   if (need_blks > 0) {
index 7b6084fdd79c5b86cd6d0fb9d3553efbb469921a..fbe6d246da08a33533362abd60761e84189a1f01 100644 (file)
@@ -3592,26 +3592,25 @@ int BlueStore::_balance_bluefs_freespace(vector<bluestore_pextent_t> *extents)
     int r = alloc->reserve(gift);
     assert(r == 0);
 
-    uint64_t hint = 0;
-    while (gift > 0) {
-      uint64_t eoffset;
-      uint32_t elength;
-      r = alloc->allocate(gift, min_alloc_size, hint, &eoffset, &elength);
-      if (r < 0) {
-       derr << __func__ << " allocate failed on 0x" << std::hex << gift
-            << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl;
-       alloc->dump();
-        assert(0 == "allocate failed, wtf");
-        return r;
-      }
+    int count = 0;
+    AllocExtentVector exts = AllocExtentVector(gift / min_alloc_size);
+    r = alloc->alloc_extents(gift, g_conf->bluefs_alloc_size, 0, 0, &exts, &count);
 
-      bluestore_pextent_t e(eoffset, elength);
+    if (r < 0) {
+      derr << __func__ << " allocate failed on 0x" << std::hex << gift
+           << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl;
+      alloc->dump();
+      assert(0 == "allocate failed, wtf");
+      return r;
+    }
+    assert(count > 0);
+    
+    for (int i = 0; i < count; i++) {
+      bluestore_pextent_t e = bluestore_pextent_t(exts[i]);
       dout(1) << __func__ << " gifting " << e << " to bluefs" << dendl;
       extents->push_back(e);
-      gift -= e.length;
-      hint = e.end();
     }
-    assert(gift == 0); // otherwise there is a reservation leak
+    gift = 0;
 
     ret = 1;
   }
index ef9f090959478a0d4b892aa416ea18feca8ed2c4..d6564fbe2625a24865ee3294e1635b281edc6a36 100644 (file)
@@ -141,6 +141,24 @@ TEST_P(AllocTest, test_alloc_min_max_alloc)
     EXPECT_EQ(count, 2);
   }
 
+  /*
+   * Make sure allocations are of min_alloc_size when min_alloc_size > block_size.
+   */
+  {
+    alloc->init_add_free(0, block_size * 1024);
+    EXPECT_EQ(alloc->reserve(block_size * 1024), 0);
+    AllocExtentVector extents = AllocExtentVector 
+                        (1024, AllocExtent(0, 0));
+  
+    EXPECT_EQ(alloc->alloc_extents(1024 * (uint64_t)block_size, (uint64_t) block_size * 4, 
+                                   block_size * 4, (int64_t) 0, &extents, &count), 0);
+    for (int i = 0; i < count; i++) {
+      EXPECT_EQ(extents[i].length, block_size * 4);
+    }
+    EXPECT_EQ(count, 1024 / 4);
+  }
+
   /*
    * Allocate and free.
    */