]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: pass string_view to ctor of Allocator
authorKefu Chai <kchai@redhat.com>
Thu, 27 May 2021 14:26:05 +0000 (22:26 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 27 May 2021 15:37:08 +0000 (23:37 +0800)
just for the sake of correctness, as they don't need a full-blown
std::string, what they need is but a string like object. and they always
create a std::string instance as a member variable if they want to have
a copy of it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
14 files changed:
src/os/bluestore/Allocator.cc
src/os/bluestore/Allocator.h
src/os/bluestore/AvlAllocator.cc
src/os/bluestore/AvlAllocator.h
src/os/bluestore/BitmapAllocator.cc
src/os/bluestore/BitmapAllocator.h
src/os/bluestore/HybridAllocator.h
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h
src/os/bluestore/ZonedAllocator.cc
src/os/bluestore/ZonedAllocator.h
src/test/objectstore/Allocator_bench.cc
src/test/objectstore/Allocator_test.cc
src/test/objectstore/allocator_replay_test.cc

index 342854541469e01994e5c5d06560c6b324329ef8..50ca3fa91632170c723717e33b9f5425672ad352 100644 (file)
@@ -25,8 +25,7 @@ class Allocator::SocketHook : public AdminSocketHook {
   friend class Allocator;
   std::string name;
 public:
-  explicit SocketHook(Allocator *alloc,
-                      const std::string& _name) :
+  SocketHook(Allocator *alloc, std::string_view _name) :
     alloc(alloc), name(_name)
   {
     AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
@@ -106,7 +105,7 @@ public:
   }
 
 };
-Allocator::Allocator(const std::string& name,
+Allocator::Allocator(std::string_view name,
                      int64_t _capacity,
                      int64_t _block_size)
   : device_size(_capacity), block_size(_block_size)
@@ -124,8 +123,8 @@ const string& Allocator::get_name() const {
   return asok_hook->name;
 }
 
-Allocator *Allocator::create(CephContext* cct, string type,
-                             int64_t size, int64_t block_size, const std::string& name)
+Allocator *Allocator::create(CephContext* cct, std::string_view type,
+                             int64_t size, int64_t block_size, std::string_view name)
 {
   Allocator* alloc = nullptr;
   if (type == "stupid") {
index 42da193c1e8700c680f6c25f36ebb4c5c69e12b0..59be4a711d28ee54ae415f499205226e09c6b9c6 100644 (file)
@@ -19,9 +19,9 @@
 
 class Allocator {
 public:
-  explicit Allocator(const std::string& name,
-                     int64_t _capacity,
-                     int64_t _block_size);
+  Allocator(std::string_view name,
+           int64_t _capacity,
+           int64_t _block_size);
   virtual ~Allocator();
 
   /*
@@ -66,8 +66,8 @@ public:
   virtual double get_fragmentation_score();
   virtual void shutdown() = 0;
 
-  static Allocator *create(CephContext* cct, std::string type, int64_t size,
-                          int64_t block_size, const std::string& name = "");
+  static Allocator *create(CephContext* cct, std::string_view type, int64_t size,
+                          int64_t block_size, const std::string_view name = "");
 
 
   const string& get_name() const;
index e7010b1691beda2d015ec4d1a6fa43955fec4622..799c3ce828ee7e12768a70eacf3cf901aeb1b8ae 100644 (file)
@@ -301,7 +301,7 @@ AvlAllocator::AvlAllocator(CephContext* cct,
                            int64_t device_size,
                            int64_t block_size,
                            uint64_t max_mem,
-                           const std::string& name) :
+                           std::string_view name) :
   Allocator(name, device_size, block_size),
   range_size_alloc_threshold(
     cct->_conf.get_val<uint64_t>("bluestore_avl_alloc_bf_threshold")),
@@ -314,7 +314,7 @@ AvlAllocator::AvlAllocator(CephContext* cct,
 AvlAllocator::AvlAllocator(CephContext* cct,
                           int64_t device_size,
                           int64_t block_size,
-                          const std::string& name) :
+                          std::string_view name) :
   Allocator(name, device_size, block_size),
   range_size_alloc_threshold(
     cct->_conf.get_val<uint64_t>("bluestore_avl_alloc_bf_threshold")),
index a4b1b52cfe2cb7f7d3b850044efc791f5df65b82..7ba053e64b443d981394ca40c05f56db3716865a 100644 (file)
@@ -65,11 +65,11 @@ protected:
   */
   AvlAllocator(CephContext* cct, int64_t device_size, int64_t block_size,
     uint64_t max_mem,
-    const std::string& name);
+    std::string_view name);
 
 public:
   AvlAllocator(CephContext* cct, int64_t device_size, int64_t block_size,
-              const std::string& name);
+              std::string_view name);
   ~AvlAllocator();
   const char* get_type() const override
   {
index 3571ddd219279e7c2b57d6b0809a49533effadd2..bbc77f1b450425b40af50c32651b47f1dea409a3 100644 (file)
@@ -11,7 +11,7 @@
 BitmapAllocator::BitmapAllocator(CephContext* _cct,
                                         int64_t capacity,
                                         int64_t alloc_unit,
-                                        const std::string& name) :
+                                        std::string_view name) :
     Allocator(name, capacity, alloc_unit),
     cct(_cct)
 {
index ec61e210823ec7ef560c38f8ad67610afe84bb0f..ddaa8ca9eae05177a5d6e84be90268f4b08bda9b 100644 (file)
@@ -16,7 +16,8 @@ class BitmapAllocator : public Allocator,
   public AllocatorLevel02<AllocatorLevel01Loose> {
   CephContext* cct;
 public:
-  BitmapAllocator(CephContext* _cct, int64_t capacity, int64_t alloc_unit, const std::string& name);
+  BitmapAllocator(CephContext* _cct, int64_t capacity, int64_t alloc_unit,
+                 std::string_view name);
   ~BitmapAllocator() override
   {
   }
index 92e8b9e80b18a380c0c24dca7995a87d02f64112..e254ba654a30f3858bfad6f8171bb82d97770476 100644 (file)
@@ -13,7 +13,7 @@ class HybridAllocator : public AvlAllocator {
 public:
   HybridAllocator(CephContext* cct, int64_t device_size, int64_t _block_size,
                   uint64_t max_mem,
-                 const std::string& name) :
+                 std::string_view name) :
       AvlAllocator(cct, device_size, _block_size, max_mem, name) {
   }
   const char* get_type() const override
index 572fb792fb8d9bd05a886008bf2f4a2b54600e1c..b4739f28dd11c4a96d2cd99e034d54fbd1e44f51 100644 (file)
@@ -13,7 +13,7 @@
 StupidAllocator::StupidAllocator(CephContext* cct,
                                  int64_t capacity,
                                  int64_t _block_size,
-                                 const std::string& name)
+                                 std::string_view name)
   : Allocator(name, capacity, _block_size),
     cct(cct), num_free(0),
     free(10)
index 9b18e4bb674a16d9bf3fa0c4ac12a95bff803d33..e5aebce8ee8c32017665760bafbd6c0b6bcc5bdb 100644 (file)
@@ -39,7 +39,7 @@ public:
   StupidAllocator(CephContext* cct,
                   int64_t size,
                   int64_t block_size,
-                 const std::string& name);
+                 std::string_view name);
   ~StupidAllocator() override;
   const char* get_type() const override
   {
index f25cc11bd33a432e0dda2e8ee2d252db279ab130..bd4bde6037f8bd0f44ebc18f00cec3e435e18340 100644 (file)
@@ -21,7 +21,7 @@
 ZonedAllocator::ZonedAllocator(CephContext* cct,
                               int64_t size,
                               int64_t blk_size,
-                              const std::string& name)
+                              std::string_view name)
     : Allocator(name, size, blk_size),
       cct(cct),
       num_free(0),
index 1db15d373bba04762cd103c77fec055b2308f28a..5deedcae9ab02d86c955842af9e1764472906de4 100644 (file)
@@ -70,7 +70,7 @@ class ZonedAllocator : public Allocator {
 
 public:
   ZonedAllocator(CephContext* cct, int64_t size, int64_t block_size,
-                 const std::string& name);
+                 std::string_view name);
   ~ZonedAllocator() override;
 
   const char *get_type() const override {
index 71277bc807e9027e55b5545a34a922b3b5c498d9..4afb2df4b4e7c0f3fdbb8155157757a59a1e4548 100644 (file)
@@ -28,7 +28,7 @@ public:
   AllocTest(): alloc(0) { }
   void init_alloc(int64_t size, uint64_t min_alloc_size) {
     std::cout << "Creating alloc type " << string(GetParam()) << " \n";
-    alloc.reset(Allocator::create(g_ceph_context, string(GetParam()), size,
+    alloc.reset(Allocator::create(g_ceph_context, GetParam(), size,
                                  min_alloc_size));
   }
 
@@ -333,7 +333,7 @@ TEST_P(AllocTest, mempoolAccounting)
 
   uint64_t alloc_size = 4 * 1024;
   uint64_t capacity = 512ll * 1024 * 1024 * 1024;
-  Allocator* alloc = Allocator::create(g_ceph_context, string(GetParam()),
+  Allocator* alloc = Allocator::create(g_ceph_context, GetParam(),
                                       capacity, alloc_size);
   ASSERT_NE(alloc, nullptr);
   alloc->init_add_free(0, capacity);
index 3e5a2209a63c31444764c012b4aac5f231992075..d0d208ca61877b77bb103ee422adc083cef5c4c2 100644 (file)
@@ -23,7 +23,7 @@ public:
   AllocTest(): alloc(0) { }
   void init_alloc(int64_t size, uint64_t min_alloc_size) {
     std::cout << "Creating alloc type " << string(GetParam()) << " \n";
-    alloc.reset(Allocator::create(g_ceph_context, string(GetParam()), size,
+    alloc.reset(Allocator::create(g_ceph_context, GetParam(), size,
                                  min_alloc_size));
   }
 
index 8f4fe18f017e79404a07b9408ccae1a3a8ec3a59..ce562dade8e86836476975c35ed0e841219a1bd6 100644 (file)
@@ -202,7 +202,7 @@ int replay_and_check_for_duplicate(char* fname)
        std::cerr << "error: invalid init: " << s << std::endl;
       return -1;
       }
-      alloc.reset(Allocator::create(g_ceph_context, string("bitmap"), total,
+      alloc.reset(Allocator::create(g_ceph_context, "bitmap", total,
                                    alloc_unit));
       owned_by_app.insert(0, total);