From 258ffd289a70a04a36c063959daebf84c83ba980 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 27 May 2021 22:26:05 +0800 Subject: [PATCH] os/bluestore: pass string_view to ctor of Allocator 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 --- src/os/bluestore/Allocator.cc | 9 ++++----- src/os/bluestore/Allocator.h | 10 +++++----- src/os/bluestore/AvlAllocator.cc | 4 ++-- src/os/bluestore/AvlAllocator.h | 4 ++-- src/os/bluestore/BitmapAllocator.cc | 2 +- src/os/bluestore/BitmapAllocator.h | 3 ++- src/os/bluestore/HybridAllocator.h | 2 +- src/os/bluestore/StupidAllocator.cc | 2 +- src/os/bluestore/StupidAllocator.h | 2 +- src/os/bluestore/ZonedAllocator.cc | 2 +- src/os/bluestore/ZonedAllocator.h | 2 +- src/test/objectstore/Allocator_bench.cc | 4 ++-- src/test/objectstore/Allocator_test.cc | 2 +- src/test/objectstore/allocator_replay_test.cc | 2 +- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/os/bluestore/Allocator.cc b/src/os/bluestore/Allocator.cc index 342854541469e..50ca3fa916321 100644 --- a/src/os/bluestore/Allocator.cc +++ b/src/os/bluestore/Allocator.cc @@ -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") { diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index 42da193c1e870..59be4a711d28e 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -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; diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index e7010b1691bed..799c3ce828ee7 100644 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -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("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("bluestore_avl_alloc_bf_threshold")), diff --git a/src/os/bluestore/AvlAllocator.h b/src/os/bluestore/AvlAllocator.h index a4b1b52cfe2cb..7ba053e64b443 100644 --- a/src/os/bluestore/AvlAllocator.h +++ b/src/os/bluestore/AvlAllocator.h @@ -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 { diff --git a/src/os/bluestore/BitmapAllocator.cc b/src/os/bluestore/BitmapAllocator.cc index 3571ddd219279..bbc77f1b45042 100644 --- a/src/os/bluestore/BitmapAllocator.cc +++ b/src/os/bluestore/BitmapAllocator.cc @@ -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) { diff --git a/src/os/bluestore/BitmapAllocator.h b/src/os/bluestore/BitmapAllocator.h index ec61e210823ec..ddaa8ca9eae05 100644 --- a/src/os/bluestore/BitmapAllocator.h +++ b/src/os/bluestore/BitmapAllocator.h @@ -16,7 +16,8 @@ class BitmapAllocator : public Allocator, public AllocatorLevel02 { 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 { } diff --git a/src/os/bluestore/HybridAllocator.h b/src/os/bluestore/HybridAllocator.h index 92e8b9e80b18a..e254ba654a30f 100644 --- a/src/os/bluestore/HybridAllocator.h +++ b/src/os/bluestore/HybridAllocator.h @@ -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 diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 572fb792fb8d9..b4739f28dd11c 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -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) diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index 9b18e4bb674a1..e5aebce8ee8c3 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -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 { diff --git a/src/os/bluestore/ZonedAllocator.cc b/src/os/bluestore/ZonedAllocator.cc index f25cc11bd33a4..bd4bde6037f8b 100644 --- a/src/os/bluestore/ZonedAllocator.cc +++ b/src/os/bluestore/ZonedAllocator.cc @@ -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), diff --git a/src/os/bluestore/ZonedAllocator.h b/src/os/bluestore/ZonedAllocator.h index 1db15d373bba0..5deedcae9ab02 100644 --- a/src/os/bluestore/ZonedAllocator.h +++ b/src/os/bluestore/ZonedAllocator.h @@ -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 { diff --git a/src/test/objectstore/Allocator_bench.cc b/src/test/objectstore/Allocator_bench.cc index 71277bc807e90..4afb2df4b4e7c 100644 --- a/src/test/objectstore/Allocator_bench.cc +++ b/src/test/objectstore/Allocator_bench.cc @@ -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); diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index 3e5a2209a63c3..d0d208ca61877 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -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)); } diff --git a/src/test/objectstore/allocator_replay_test.cc b/src/test/objectstore/allocator_replay_test.cc index 8f4fe18f017e7..ce562dade8e86 100644 --- a/src/test/objectstore/allocator_replay_test.cc +++ b/src/test/objectstore/allocator_replay_test.cc @@ -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); -- 2.39.5