From 432fa9ddf4240919c29da7e81574da716bea6bfc Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 13 Jan 2016 16:51:23 -0500 Subject: [PATCH] os/bluestore/StupidAllocator: use btree_map<> instead of map<> btree_map uses about half the memory. According to the cpp-btree docs they are also faster than STL maps... especially when they get big. Signed-off-by: Sage Weil --- src/os/bluestore/StupidAllocator.cc | 16 ++++++++-------- src/os/bluestore/StupidAllocator.h | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index d96e945569420..4c4f395034f05 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -73,7 +73,7 @@ void StupidAllocator::unreserve(uint64_t unused) } /// return the effective length of the extent if we align to alloc_unit -static uint64_t aligned_len(interval_set::iterator p, +static uint64_t aligned_len(btree_interval_set::iterator p, uint64_t alloc_unit) { uint64_t skew = p.get_start() % alloc_unit; @@ -98,7 +98,7 @@ int StupidAllocator::allocate( int bin = _choose_bin(want); int orig_bin = bin; - interval_set::iterator p = free[0].begin(); + auto p = free[0].begin(); if (!hint) hint = last_alloc; @@ -223,7 +223,7 @@ void StupidAllocator::dump(ostream& out) for (unsigned bin = 0; bin < free.size(); ++bin) { dout(30) << __func__ << " free bin " << bin << ": " << free[bin].num_intervals() << " extents" << dendl; - for (interval_set::iterator p = free[bin].begin(); + for (auto p = free[bin].begin(); p != free[bin].end(); ++p) { dout(30) << __func__ << " " << p.get_start() << "~" << p.get_len() << dendl; @@ -231,14 +231,14 @@ void StupidAllocator::dump(ostream& out) } dout(30) << __func__ << " committing: " << committing.num_intervals() << " extents" << dendl; - for (interval_set::iterator p = committing.begin(); + for (auto p = committing.begin(); p != committing.end(); ++p) { dout(30) << __func__ << " " << p.get_start() << "~" << p.get_len() << dendl; } dout(30) << __func__ << " uncommitted: " << uncommitted.num_intervals() << " extents" << dendl; - for (interval_set::iterator p = uncommitted.begin(); + for (auto p = uncommitted.begin(); p != uncommitted.end(); ++p) { dout(30) << __func__ << " " << p.get_start() << "~" << p.get_len() << dendl; @@ -257,10 +257,10 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length) { Mutex::Locker l(lock); dout(10) << __func__ << " " << offset << "~" << length << dendl; - interval_set rm; + btree_interval_set rm; rm.insert(offset, length); for (unsigned i = 0; i < free.size() && !rm.empty(); ++i) { - interval_set overlap; + btree_interval_set overlap; overlap.intersection_of(rm, free[i]); if (!overlap.empty()) { dout(20) << __func__ << " bin " << i << " rm " << overlap << dendl; @@ -295,7 +295,7 @@ void StupidAllocator::commit_finish() Mutex::Locker l(lock); dout(10) << __func__ << " released " << num_committing << " in extents " << committing.num_intervals() << dendl; - for (interval_set::iterator p = committing.begin(); + for (auto p = committing.begin(); p != committing.end(); ++p) { _insert_free(p.get_start(), p.get_len()); diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index ec71b863df192..e5cf17d100669 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -5,7 +5,7 @@ #define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H #include "Allocator.h" -#include "include/interval_set.h" +#include "include/btree_interval_set.h" #include "common/Mutex.h" class StupidAllocator : public Allocator { @@ -16,9 +16,9 @@ class StupidAllocator : public Allocator { int64_t num_committing; int64_t num_reserved; ///< reserved bytes - vector > free; ///< leading-edge copy - interval_set uncommitted; ///< released but not yet usable - interval_set committing; ///< released but not yet usable + std::vector > free; ///< leading-edge copy + btree_interval_set uncommitted; ///< released but not yet usable + btree_interval_set committing; ///< released but not yet usable uint64_t last_alloc; @@ -44,7 +44,7 @@ public: uint64_t get_free(); - void dump(ostream& out); + void dump(std::ostream& out); void init_add_free(uint64_t offset, uint64_t length); void init_rm_free(uint64_t offset, uint64_t length); -- 2.39.5