]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/objectstore: Allocator_test. Add test for dumping free regions and fragmentation...
authorAdam Kupczyk <akupczyk@redhat.com>
Tue, 6 Aug 2019 10:01:52 +0000 (12:01 +0200)
committerNeha Ojha <nojha@redhat.com>
Wed, 7 Aug 2019 19:58:49 +0000 (15:58 -0400)
Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(cherry picked from commit 355dc85372a15713ab1cdd78f44ea02db8e08a62)

src/test/objectstore/Allocator_test.cc

index 959932af9e5980f3dc36bd1bf032da5f90401e78..84a90b7c76b635b786b97f13f655824dcd4b8e6c 100644 (file)
@@ -286,6 +286,68 @@ TEST_P(AllocTest, test_alloc_fragmentation)
   EXPECT_EQ(0, uint64_t(alloc->get_fragmentation(alloc_unit) * 100));
 }
 
+TEST_P(AllocTest, test_dump_fragmentation_score)
+{
+  uint64_t capacity = 1024 * 1024 * 1024;
+  uint64_t one_alloc_max = 2 * 1024 * 1024;
+  uint64_t alloc_unit = 4096;
+  uint64_t want_size = alloc_unit;
+  uint64_t rounds = 10;
+  uint64_t actions_per_round = 1000;
+  PExtentVector allocated, tmp;
+  gen_type rng;
+
+  init_alloc(capacity, alloc_unit);
+  alloc->init_add_free(0, capacity);
+
+  EXPECT_EQ(0.0, alloc->get_fragmentation(alloc_unit));
+
+  uint64_t allocated_cnt = 0;
+  for (size_t round = 0; round < rounds ; round++) {
+    for (size_t j = 0; j < actions_per_round ; j++) {
+      //free or allocate ?
+      if ( rng() % capacity >= allocated_cnt ) {
+       //allocate
+       want_size = ( rng() % one_alloc_max ) / alloc_unit * alloc_unit + alloc_unit;
+       tmp.clear();
+       uint64_t r = alloc->allocate(want_size, alloc_unit, 0, 0, &tmp);
+       for (auto& t: tmp) {
+         if (t.length > 0)
+           allocated.push_back(t);
+       }
+       allocated_cnt += r;
+      } else {
+       //free
+       ceph_assert(allocated.size() > 0);
+       size_t item = rng() % allocated.size();
+       ceph_assert(allocated[item].length > 0);
+       allocated_cnt -= allocated[item].length;
+       interval_set<uint64_t> release_set;
+       release_set.insert(allocated[item].offset, allocated[item].length);
+       alloc->release(release_set);
+       std::swap(allocated[item], allocated[allocated.size() - 1]);
+       allocated.resize(allocated.size() - 1);
+      }
+    }
+
+    size_t free_sum = 0;
+    auto iterated_allocation = [&](size_t off, size_t len) {
+      ceph_assert(len > 0);
+      free_sum += len;
+    };
+    alloc->dump(iterated_allocation);
+    EXPECT_GT(1, alloc->get_fragmentation_score());
+    EXPECT_EQ(capacity, free_sum + allocated_cnt);
+  }
+
+  for (size_t i = 0; i < allocated.size(); i ++)
+  {
+    interval_set<uint64_t> release_set;
+    release_set.insert(allocated[i].offset, allocated[i].length);
+    alloc->release(release_set);
+  }
+}
+
 TEST_P(AllocTest, test_alloc_bug_24598)
 {
   if (string(GetParam()) != "bitmap")