e.g., mempool::bluestore_meta_other::list<...> ...
This avoids colliding with other names and types when the pool
name is something common (like "osd").
Signed-off-by: Sage Weil <sage@redhat.com>
# Conflicts:
# src/include/mempool.h
switch (ix) {
#define P(x) \
- case x: pools[ix] = new mempool::pool_t(#x); break;
+ case mempool_##x: pools[ix] = new mempool::pool_t(#x); break;
DEFINE_MEMORY_POOLS_HELPER(P);
#undef P
default: assert(0);
Thus for mempool "unittest_1" we have automatically available to us:
- unittest_1::map
- unittest_1::multimap
- unittest_1::set
- unittest_1::multiset
- unittest_1::list
- unittest_1::vector
- unittest_1::unordered_map
+ mempool::unittest_1::map
+ mempool::unittest_1::multimap
+ mempool::unittest_1::set
+ mempool::unittest_1::multiset
+ mempool::unittest_1::list
+ mempool::unittest_1::vector
+ mempool::unittest_1::unordered_map
Putting objects in a mempool
In order to use the STL containers, simply use the namespaced variant
of the container type. For example,
- unittest_1::map<int> myvec;
+ mempool::unittest_1::map<int> myvec;
Introspection
-------------
You can also interogate a specific pool programatically with
- size_t bytes = unittest_2::allocated_bytes();
- size_t items = unittest_2::allocated_items();
+ size_t bytes = mempool::unittest_2::allocated_bytes();
+ size_t items = mempool::unittest_2::allocated_items();
The runtime complexity is O(num_shards).
f(bluestore_meta_other)
// give them integer ids
-#define P(x) x,
+#define P(x) mempool_##x,
enum pool_index_t {
DEFINE_MEMORY_POOLS_HELPER(P)
num_pools // Must be last.
}
};
-};
-
// Namespace mempool
#define P(x) \
namespace x { \
- static const mempool::pool_index_t pool_ix = mempool::x; \
+ static const mempool::pool_index_t id = mempool::mempool_##x; \
template<typename v> \
- using pool_allocator = mempool::pool_allocator<mempool::x,v>; \
+ using pool_allocator = mempool::pool_allocator<id,v>; \
template<typename k,typename v, typename cmp = std::less<k> > \
using map = std::map<k, v, cmp, \
pool_allocator<std::pair<k,v>>>; \
using unordered_map = \
std::unordered_map<k,v,h,eq,pool_allocator<std::pair<k,v>>>; \
template<typename v> \
- using factory = mempool::factory<mempool::x,v>; \
+ using factory = mempool::factory<id,v>; \
inline size_t allocated_bytes() { \
- return mempool::get_pool(mempool::x).allocated_bytes(); \
+ return mempool::get_pool(id).allocated_bytes(); \
} \
inline size_t allocated_items() { \
- return mempool::get_pool(mempool::x).allocated_items(); \
+ return mempool::get_pool(id).allocated_items(); \
} \
};
#undef P
+};
+
+
+
// Use this for any type that is contained by a container (unless it
// is a class you defined; see below).
#define MEMPOOL_DEFINE_FACTORY(obj, factoryname, pool) \
- pool::pool_allocator<obj> \
+ mempool::pool::pool_allocator<obj> \
_factory_##pool##factoryname##_alloc = {true};
// Use this for each class that belongs to a mempool. For example,
{
Mutex::Locker l(lock);
while (!stop) {
- store->mempool_bytes = bluestore_meta_other::allocated_bytes() +
- bluestore_meta_onode::allocated_bytes();
- store->mempool_onodes = bluestore_meta_onode::allocated_items();
+ store->mempool_bytes = mempool::bluestore_meta_other::allocated_bytes() +
+ mempool::bluestore_meta_onode::allocated_bytes();
+ store->mempool_onodes = mempool::bluestore_meta_onode::allocated_items();
++store->mempool_seq;
utime_t wait;
wait += g_conf->bluestore_cache_trim_interval;
boost::intrusive::list_member_hook<>,
&Buffer::state_item> > state_list_t;
- bluestore_meta_other::map<uint64_t, std::unique_ptr<Buffer>> buffer_map;
+ mempool::bluestore_meta_other::map<uint64_t, std::unique_ptr<Buffer>>
+ buffer_map;
Cache *cache;
// we use a bare intrusive list here instead of std::map because
// we use a bare pointer because we don't want to affect the ref
// count
- bluestore_meta_other::unordered_map<uint64_t,SharedBlob*> sb_map;
+ mempool::bluestore_meta_other::unordered_map<uint64_t,SharedBlob*> sb_map;
SharedBlobRef lookup(uint64_t sbid) {
std::lock_guard<std::mutex> l(lock);
#endif
};
typedef boost::intrusive_ptr<Blob> BlobRef;
- typedef bluestore_meta_other::map<int,BlobRef> blob_map_t;
+ typedef mempool::bluestore_meta_other::map<int,BlobRef> blob_map_t;
/// a logical extent, pointing to (some portion of) a blob
struct Extent : public boost::intrusive::set_base_hook<boost::intrusive::optimize_size<true>> {
bool loaded = false; ///< true if shard is loaded
bool dirty = false; ///< true if shard is dirty and needs reencoding
};
- bluestore_meta_other::vector<Shard> shards; ///< shards
+ mempool::bluestore_meta_other::vector<Shard> shards; ///< shards
bufferlist inline_bl; ///< cached encoded map, if unsharded; empty=>dirty
Cache *cache;
/// forward lookups
- bluestore_meta_other::unordered_map<ghobject_t,OnodeRef> onode_map;
+ mempool::bluestore_meta_other::unordered_map<ghobject_t,OnodeRef> onode_map;
OnodeSpace(Cache *c) : cache(c) {}
~OnodeSpace() {
bool mounted;
RWLock coll_lock; ///< rwlock to protect coll_map
- bluestore_meta_other::unordered_map<coll_t, CollectionRef> coll_map;
+ mempool::bluestore_meta_other::unordered_map<coll_t, CollectionRef> coll_map;
vector<Cache*> cache_shards;
}
};
- typedef bluestore_meta_other::map<uint64_t,record_t> map_t;
+ typedef mempool::bluestore_meta_other::map<uint64_t,record_t> map_t;
map_t ref_map;
void _check() const;
for (int i = 0; i < count; ++i) {
a.insert(make_pair(base+i,base+i));
b.insert(make_pair(base+i,base+i));
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
}
}
TEST(mempool, vector_context)
{
- check_usage(mempool::unittest_1);
- EXPECT_EQ(unittest_1::allocated_bytes(), 0u);
- EXPECT_EQ(unittest_1::allocated_items(), 0u);
+ check_usage(mempool::unittest_1::id);
+ EXPECT_EQ(mempool::unittest_1::allocated_bytes(), 0u);
+ EXPECT_EQ(mempool::unittest_1::allocated_items(), 0u);
for (unsigned i = 0; i < 10; ++i) {
vector<int> a;
- unittest_1::vector<int> b,c;
+ mempool::unittest_1::vector<int> b,c;
eq_elements(a,b);
do_push_back(a,b,i,i);
eq_elements(a,b);
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
mempool::stats_t total;
map<std::string,mempool::stats_t> by_type;
- mempool::get_pool(mempool::unittest_1).get_stats(&total, &by_type);
- EXPECT_GE(unittest_1::allocated_bytes(), i * 4u);
- EXPECT_GE(unittest_1::allocated_items(), i);
+ mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type);
+ EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u);
+ EXPECT_GE(mempool::unittest_1::allocated_items(), i);
c.swap(b);
eq_elements(a,c);
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
a.clear();
b.clear();
c.clear();
{
for (unsigned i = 1; i < 10; ++i) {
list<int> a;
- unittest_1::list<int> b,c;
+ mempool::unittest_1::list<int> b,c;
eq_elements(a,b);
do_push_back(a,b,i,i);
eq_elements(a,b);
mempool::stats_t total;
map<std::string,mempool::stats_t> by_type;
- mempool::get_pool(mempool::unittest_1).get_stats(&total, &by_type);
- EXPECT_GE(unittest_1::allocated_bytes(), i * 4u);
- EXPECT_EQ(unittest_1::allocated_items(), i);
+ mempool::get_pool(mempool::unittest_1::id).get_stats(&total, &by_type);
+ EXPECT_GE(mempool::unittest_1::allocated_bytes(), i * 4u);
+ EXPECT_EQ(mempool::unittest_1::allocated_items(), i);
eq_elements(a,c);
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
}
}
{
for (int i = 0; i < 10; ++i) {
set<int> a;
- unittest_1::set<int> b;
+ mempool::unittest_1::set<int> b;
do_insert(a,b,i,i);
eq_elements(a,b);
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
}
for (int i = 1; i < 10; ++i) {
set<int> a;
- unittest_1::set<int> b;
+ mempool::unittest_1::set<int> b;
do_insert(a,b,i,0);
EXPECT_NE(a.find(i/2),a.end());
EXPECT_NE(b.find(i/2),b.end());
a.erase(a.find(i/2));
b.erase(b.find(i/2));
eq_elements(a,b);
- check_usage(mempool::unittest_1);
+ check_usage(mempool::unittest_1::id);
}
}
obj *o1 = new obj();
obj *o2 = new obj(10);
obj *o3 = new obj(20,30);
- check_usage(mempool::unittest_2);
+ check_usage(mempool::unittest_2::id);
EXPECT_NE(o1,nullptr);
EXPECT_EQ(o1->a,1);
EXPECT_EQ(o1->b,1);
delete o1;
delete o2;
delete o3;
- check_usage(mempool::unittest_2);
+ check_usage(mempool::unittest_2::id);
}
TEST(mempool, vector)
{
{
- unittest_1::vector<int> v;
+ mempool::unittest_1::vector<int> v;
v.push_back(1);
v.push_back(2);
}
{
- unittest_2::vector<obj> v;
+ mempool::unittest_2::vector<obj> v;
v.push_back(obj());
v.push_back(obj(1));
}
TEST(mempool, set)
{
- unittest_1::set<int> set_int;
+ mempool::unittest_1::set<int> set_int;
set_int.insert(1);
set_int.insert(2);
- unittest_2::set<obj> set_obj;
+ mempool::unittest_2::set<obj> set_obj;
set_obj.insert(obj());
set_obj.insert(obj(1));
set_obj.insert(obj(1, 2));
TEST(mempool, map)
{
{
- unittest_1::map<int,int> v;
+ mempool::unittest_1::map<int,int> v;
v[1] = 2;
v[3] = 4;
}
{
- unittest_2::map<int,obj> v;
+ mempool::unittest_2::map<int,obj> v;
v[1] = obj();
v[2] = obj(2);
v[3] = obj(2, 3);
TEST(mempool, list)
{
{
- unittest_1::list<int> v;
+ mempool::unittest_1::list<int> v;
v.push_back(1);
v.push_back(2);
}
{
- unittest_2::list<obj> v;
+ mempool::unittest_2::list<obj> v;
v.push_back(obj());
v.push_back(obj(1));
}
TEST(mempool, unordered_map)
{
- unittest_2::unordered_map<int,obj> h;
+ mempool::unittest_2::unordered_map<int,obj> h;
h[1] = obj();
h[2] = obj(1);
}