From 6f189d8ab3c549a5c5e01616310c6eb39119fbc1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Aug 2017 11:58:40 -0400 Subject: [PATCH] os/bluestore: put StupidAllocator btree into bluestore_alloc mempool Signed-off-by: Sage Weil --- src/include/btree_interval_set.h | 43 +++++++++++++++-------------- src/os/bluestore/StupidAllocator.cc | 17 ++++++------ src/os/bluestore/StupidAllocator.h | 9 +++++- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/include/btree_interval_set.h b/src/include/btree_interval_set.h index c72d4ab081a43..828fead2ae0b9 100644 --- a/src/include/btree_interval_set.h +++ b/src/include/btree_interval_set.h @@ -33,11 +33,12 @@ #include "assert.h" #include "encoding_btree.h" -template +template>> class btree_interval_set { public: - typedef btree::btree_map map_t; + typedef btree::btree_map, Alloc> map_t; class const_iterator; @@ -164,28 +165,28 @@ class btree_interval_set { return m.size(); } - typename btree_interval_set::iterator begin() { - return typename btree_interval_set::iterator(m.begin()); + typename btree_interval_set::iterator begin() { + return typename btree_interval_set::iterator(m.begin()); } - typename btree_interval_set::iterator lower_bound(T start) { - return typename btree_interval_set::iterator(find_inc_m(start)); + typename btree_interval_set::iterator lower_bound(T start) { + return typename btree_interval_set::iterator(find_inc_m(start)); } - typename btree_interval_set::iterator end() { - return typename btree_interval_set::iterator(m.end()); + typename btree_interval_set::iterator end() { + return typename btree_interval_set::iterator(m.end()); } - typename btree_interval_set::const_iterator begin() const { - return typename btree_interval_set::const_iterator(m.begin()); + typename btree_interval_set::const_iterator begin() const { + return typename btree_interval_set::const_iterator(m.begin()); } - typename btree_interval_set::const_iterator lower_bound(T start) const { - return typename btree_interval_set::const_iterator(find_inc(start)); + typename btree_interval_set::const_iterator lower_bound(T start) const { + return typename btree_interval_set::const_iterator(find_inc(start)); } - typename btree_interval_set::const_iterator end() const { - return typename btree_interval_set::const_iterator(m.end()); + typename btree_interval_set::const_iterator end() const { + return typename btree_interval_set::const_iterator(m.end()); } // helpers @@ -555,11 +556,11 @@ private: }; -template -inline std::ostream& operator<<(std::ostream& out, const btree_interval_set &s) { +template +inline std::ostream& operator<<(std::ostream& out, const btree_interval_set &s) { out << "["; const char *prequel = ""; - for (typename btree_interval_set::const_iterator i = s.begin(); + for (auto i = s.begin(); i != s.end(); ++i) { @@ -570,13 +571,13 @@ inline std::ostream& operator<<(std::ostream& out, const btree_interval_set & return out; } -template -inline void encode(const btree_interval_set& s, bufferlist& bl) +template +inline void encode(const btree_interval_set& s, bufferlist& bl) { s.encode(bl); } -template -inline void decode(btree_interval_set& s, bufferlist::iterator& p) +template +inline void decode(btree_interval_set& s, bufferlist::iterator& p) { s.decode(p); } diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index a64df0458f61f..5720432b648ba 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -71,8 +71,9 @@ void StupidAllocator::unreserve(uint64_t unused) } /// return the effective length of the extent if we align to alloc_unit -static uint64_t aligned_len(btree_interval_set::iterator p, - uint64_t alloc_unit) +uint64_t StupidAllocator::_aligned_len( + btree_interval_set::iterator p, + uint64_t alloc_unit) { uint64_t skew = p.get_start() % alloc_unit; if (skew) @@ -106,7 +107,7 @@ int64_t StupidAllocator::allocate_int( for (bin = orig_bin; bin < (int)free.size(); ++bin) { p = free[bin].lower_bound(hint); while (p != free[bin].end()) { - if (aligned_len(p, alloc_unit) >= want_size) { + if (_aligned_len(p, alloc_unit) >= want_size) { goto found; } ++p; @@ -119,7 +120,7 @@ int64_t StupidAllocator::allocate_int( p = free[bin].begin(); auto end = hint ? free[bin].lower_bound(hint) : free[bin].end(); while (p != end) { - if (aligned_len(p, alloc_unit) >= want_size) { + if (_aligned_len(p, alloc_unit) >= want_size) { goto found; } ++p; @@ -131,7 +132,7 @@ int64_t StupidAllocator::allocate_int( for (bin = orig_bin; bin >= 0; --bin) { p = free[bin].lower_bound(hint); while (p != free[bin].end()) { - if (aligned_len(p, alloc_unit) >= alloc_unit) { + if (_aligned_len(p, alloc_unit) >= alloc_unit) { goto found; } ++p; @@ -144,7 +145,7 @@ int64_t StupidAllocator::allocate_int( p = free[bin].begin(); auto end = hint ? free[bin].lower_bound(hint) : free[bin].end(); while (p != end) { - if (aligned_len(p, alloc_unit) >= alloc_unit) { + if (_aligned_len(p, alloc_unit) >= alloc_unit) { goto found; } ++p; @@ -284,10 +285,10 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length) std::lock_guard l(lock); dout(10) << __func__ << " 0x" << std::hex << offset << "~" << length << std::dec << dendl; - btree_interval_set rm; + btree_interval_set rm; rm.insert(offset, length); for (unsigned i = 0; i < free.size() && !rm.empty(); ++i) { - btree_interval_set overlap; + btree_interval_set overlap; overlap.intersection_of(rm, free[i]); if (!overlap.empty()) { dout(20) << __func__ << " bin " << i << " rm 0x" << std::hex << overlap diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index 445e8a6bc8a1c..431c636a61022 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -9,6 +9,7 @@ #include "Allocator.h" #include "include/btree_interval_set.h" #include "os/bluestore/bluestore_types.h" +#include "include/mempool.h" class StupidAllocator : public Allocator { CephContext* cct; @@ -17,13 +18,19 @@ class StupidAllocator : public Allocator { int64_t num_free; ///< total bytes in freelist int64_t num_reserved; ///< reserved bytes - std::vector > free; ///< leading-edge copy + typedef mempool::bluestore_alloc::pool_allocator< + pair> allocator; + std::vector> free; ///< leading-edge copy uint64_t last_alloc; unsigned _choose_bin(uint64_t len); void _insert_free(uint64_t offset, uint64_t len); + uint64_t _aligned_len( + btree_interval_set::iterator p, + uint64_t alloc_unit); + public: StupidAllocator(CephContext* cct); ~StupidAllocator() override; -- 2.39.5