]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/allocator_replay_test: add assess_free command.
authorIgor Fedotov <igor.fedotov@croit.io>
Wed, 16 Feb 2022 21:52:04 +0000 (00:52 +0300)
committerJoshua Baergen <jbaergen@digitalocean.com>
Wed, 9 Apr 2025 19:39:02 +0000 (13:39 -0600)
This permits to estimate amount of free space for the given
allocation unit.

Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/test/objectstore/allocator_replay_test.cc

index 6d2a557333c6e834d18b7770a049752d828de3ad..707db72a9e2996dc206b121c5f49d9c111c3c2e0 100644 (file)
@@ -24,6 +24,7 @@ void usage(const string &name) {
        << " raw_duplicates|"
           "duplicates|"
           "free_dump|"
+          "assess_free <alloc_unit>|"
           "try_alloc <count> <want> <alloc_unit>|"
           "replay_alloc <alloc_list_file|"
           "export_binary <out_file>|"
@@ -564,6 +565,42 @@ int main(int argc, char **argv)
         }
         return 0;
       });
+  } else if (strcmp(argv[2], "assess_free") == 0) {
+    if (argc < 4) {
+      std::cerr << "Error: insufficient arguments for \"assess_free_extents\" operation."
+                << std::endl;
+      usage(argv[0]);
+      return 1;
+    }
+    auto alloc_unit = strtoul(argv[3], nullptr, 10);
+    return replay_free_dump_and_apply(argv[1],
+      [&](Allocator* a, const string& aname) {
+        ceph_assert(a);
+        std::cout << "Fragmentation:" << a->get_fragmentation()
+                  << std::endl;
+        std::cout << "Fragmentation score:" << a->get_fragmentation_score()
+                  << std::endl;
+        std::cout << "Free:" << std::hex << a->get_free() << std::dec
+                  << std::endl;
+        {
+          uint64_t available = 0;
+          uint64_t available2 = 0;
+          a->foreach([&](uint64_t offs, uint64_t len) {
+            auto a = p2align(len, alloc_unit);
+            available += a;
+            auto a0 = p2roundup(offs, alloc_unit);
+            a = p2align(offs + len, alloc_unit);
+            if (a > a0) {
+              available2 += a - a0;
+            }
+          });
+          std::cout << "Available: 0x" << std::hex << available
+                    << " Available(strict align): 0x" << available2
+                    << " alloc_unit: 0x" << alloc_unit << std::dec
+                    << std::endl;
+        }
+        return 0;
+      });
   } else if (strcmp(argv[2], "try_alloc") == 0) {
     if (argc < 6) {
       std::cerr << "Error: insufficient arguments for \"try_alloc\" operation."
@@ -587,13 +624,20 @@ int main(int argc, char **argv)
         {
           PExtentVector extents;
           for(size_t i = 0; i < count; i++) {
-              extents.clear();
-              auto r = a->allocate(want, alloc_unit, 0, &extents);
-              if (r < 0) {
-                  std::cerr << "Error: allocation failure at step:" << i + 1
-                            << ", ret = " << r << std::endl;
+            extents.clear();
+            auto r = a->allocate(want, alloc_unit, 0, &extents);
+            if (r < 0) {
+              std::cerr << "Error: allocation failure at step:" << i + 1
+                        << ", ret = " << r << std::endl;
               return -1;
             }
+            std::cout << ">allocated: " << r << std::endl;
+
+            std::cout << "Extents:" << std::hex;
+            for (auto& e : extents) {
+              std::cout << e.offset << "~" << e.length << " ";
+            }
+            std::cout << std::dec << std::endl;
          }
         }
         std::cout << "Successfully allocated: " << count << " * " << want