From 1fcefbe23ff78dc88221d4de9e0690f6183b16e1 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 23 Aug 2021 17:46:10 +0300 Subject: [PATCH] test/allocator_replay_test: implement "try_alloc" command. This permits trying multiple allocations of chosen size on allocator being at specific state (which is determined by free-dump report replay) Signed-off-by: Igor Fedotov --- src/test/objectstore/allocator_replay_test.cc | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/test/objectstore/allocator_replay_test.cc b/src/test/objectstore/allocator_replay_test.cc index f9a35bbe4be37..7927790c485f3 100644 --- a/src/test/objectstore/allocator_replay_test.cc +++ b/src/test/objectstore/allocator_replay_test.cc @@ -18,7 +18,7 @@ using namespace std; void usage(const string &name) { - cerr << "Usage: " << name << " " + cerr << "Usage: " << name << " " << std::endl; } @@ -252,11 +252,11 @@ int replay_free_dump_and_apply(char* fname, JSONObj::data_val v; ceph_assert(p.is_object()); - auto *o = p.find_obj("allocator_type"); + auto *o = p.find_obj("alloc_type"); ceph_assert(o); alloc_type = o->get_data_val().str; - o = p.find_obj("allocator_name"); + o = p.find_obj("alloc_name"); ceph_assert(o); alloc_name = o->get_data_val().str; @@ -353,5 +353,41 @@ int main(int argc, char **argv) } return 0; }); + } else if (strcmp(argv[2], "try_alloc") == 0) { + if (argc < 6) { + std::cerr << "Error: insufficient arguments for \"try_alloc\" operation." + << std::endl; + usage(argv[0]); + return 1; + } + auto count = strtoul(argv[3], nullptr, 10); + auto want = strtoul(argv[4], nullptr, 10); + auto alloc_unit = strtoul(argv[5], 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; + { + 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; + return -1; + } + } + } + std::cout << "Successfully allocated: " << count << " * " << want + << ", unit:" << alloc_unit << std::endl; + return 0; + }); } } -- 2.39.5