From a54d21749dc699fc32cd55522c48fdef5dbd7ee0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 Oct 2016 12:09:39 -0400 Subject: [PATCH] mempool: put pool namespaces within mempool:: 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 # Conflicts: # src/include/mempool.h --- src/global/mempool.cc | 2 +- src/include/mempool.h | 40 ++++++++++---------- src/os/bluestore/BlueStore.cc | 6 +-- src/os/bluestore/BlueStore.h | 13 ++++--- src/os/bluestore/bluestore_types.h | 2 +- src/test/test_mempool.cc | 60 +++++++++++++++--------------- 6 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/global/mempool.cc b/src/global/mempool.cc index b034a79af7a76..217ec1116ec22 100644 --- a/src/global/mempool.cc +++ b/src/global/mempool.cc @@ -35,7 +35,7 @@ mempool::pool_t& mempool::get_pool(mempool::pool_index_t ix) 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); diff --git a/src/include/mempool.h b/src/include/mempool.h index 565f0abe2c935..d801801bb5af2 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -66,13 +66,13 @@ with the appropriate allocators. 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 @@ -105,7 +105,7 @@ can't use :: in a variable name.) In order to use the STL containers, simply use the namespaced variant of the container type. For example, - unittest_1::map myvec; + mempool::unittest_1::map myvec; Introspection ------------- @@ -121,8 +121,8 @@ num_types). When debug name is disabled it is O(num_shards). 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). @@ -144,7 +144,7 @@ namespace mempool { 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. @@ -348,16 +348,14 @@ public: } }; -}; - // 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 \ - using pool_allocator = mempool::pool_allocator; \ + using pool_allocator = mempool::pool_allocator; \ template > \ using map = std::map>>; \ @@ -376,12 +374,12 @@ public: using unordered_map = \ std::unordered_map>>; \ template \ - using factory = mempool::factory; \ + using factory = mempool::factory; \ 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(); \ } \ }; @@ -389,10 +387,14 @@ DEFINE_MEMORY_POOLS_HELPER(P) #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 \ + mempool::pool::pool_allocator \ _factory_##pool##factoryname##_alloc = {true}; // Use this for each class that belongs to a mempool. For example, diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 61b7228fba9ab..2629075cede52 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2533,9 +2533,9 @@ void *BlueStore::MempoolThread::entry() { 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; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 848ab7efbf4b9..781c0993c69bb 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -210,7 +210,8 @@ public: boost::intrusive::list_member_hook<>, &Buffer::state_item> > state_list_t; - bluestore_meta_other::map> buffer_map; + mempool::bluestore_meta_other::map> + buffer_map; Cache *cache; // we use a bare intrusive list here instead of std::map because @@ -367,7 +368,7 @@ public: // we use a bare pointer because we don't want to affect the ref // count - bluestore_meta_other::unordered_map sb_map; + mempool::bluestore_meta_other::unordered_map sb_map; SharedBlobRef lookup(uint64_t sbid) { std::lock_guard l(lock); @@ -523,7 +524,7 @@ public: #endif }; typedef boost::intrusive_ptr BlobRef; - typedef bluestore_meta_other::map blob_map_t; + typedef mempool::bluestore_meta_other::map blob_map_t; /// a logical extent, pointing to (some portion of) a blob struct Extent : public boost::intrusive::set_base_hook> { @@ -603,7 +604,7 @@ public: bool loaded = false; ///< true if shard is loaded bool dirty = false; ///< true if shard is dirty and needs reencoding }; - bluestore_meta_other::vector shards; ///< shards + mempool::bluestore_meta_other::vector shards; ///< shards bufferlist inline_bl; ///< cached encoded map, if unsharded; empty=>dirty @@ -1024,7 +1025,7 @@ public: Cache *cache; /// forward lookups - bluestore_meta_other::unordered_map onode_map; + mempool::bluestore_meta_other::unordered_map onode_map; OnodeSpace(Cache *c) : cache(c) {} ~OnodeSpace() { @@ -1462,7 +1463,7 @@ private: bool mounted; RWLock coll_lock; ///< rwlock to protect coll_map - bluestore_meta_other::unordered_map coll_map; + mempool::bluestore_meta_other::unordered_map coll_map; vector cache_shards; diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 901954a4e1c62..123ad30b35bb4 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -188,7 +188,7 @@ struct bluestore_extent_ref_map_t { } }; - typedef bluestore_meta_other::map map_t; + typedef mempool::bluestore_meta_other::map map_t; map_t ref_map; void _check() const; diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index 73c90b985d387..37ad3a31826f0 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -86,32 +86,32 @@ void do_insert_key(A& a, B& b, int count, int base) 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 a; - unittest_1::vector b,c; + mempool::unittest_1::vector 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 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(); @@ -122,7 +122,7 @@ TEST(mempool, list_context) { for (unsigned i = 1; i < 10; ++i) { list a; - unittest_1::list b,c; + mempool::unittest_1::list b,c; eq_elements(a,b); do_push_back(a,b,i,i); eq_elements(a,b); @@ -139,12 +139,12 @@ TEST(mempool, list_context) mempool::stats_t total; map 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); } } @@ -152,22 +152,22 @@ TEST(mempool, set_context) { for (int i = 0; i < 10; ++i) { set a; - unittest_1::set b; + mempool::unittest_1::set 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 a; - unittest_1::set b; + mempool::unittest_1::set 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); } } @@ -189,7 +189,7 @@ TEST(mempool, test_factory) 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); @@ -201,18 +201,18 @@ TEST(mempool, test_factory) delete o1; delete o2; delete o3; - check_usage(mempool::unittest_2); + check_usage(mempool::unittest_2::id); } TEST(mempool, vector) { { - unittest_1::vector v; + mempool::unittest_1::vector v; v.push_back(1); v.push_back(2); } { - unittest_2::vector v; + mempool::unittest_2::vector v; v.push_back(obj()); v.push_back(obj(1)); } @@ -220,10 +220,10 @@ TEST(mempool, vector) TEST(mempool, set) { - unittest_1::set set_int; + mempool::unittest_1::set set_int; set_int.insert(1); set_int.insert(2); - unittest_2::set set_obj; + mempool::unittest_2::set set_obj; set_obj.insert(obj()); set_obj.insert(obj(1)); set_obj.insert(obj(1, 2)); @@ -232,12 +232,12 @@ TEST(mempool, set) TEST(mempool, map) { { - unittest_1::map v; + mempool::unittest_1::map v; v[1] = 2; v[3] = 4; } { - unittest_2::map v; + mempool::unittest_2::map v; v[1] = obj(); v[2] = obj(2); v[3] = obj(2, 3); @@ -247,12 +247,12 @@ TEST(mempool, map) TEST(mempool, list) { { - unittest_1::list v; + mempool::unittest_1::list v; v.push_back(1); v.push_back(2); } { - unittest_2::list v; + mempool::unittest_2::list v; v.push_back(obj()); v.push_back(obj(1)); } @@ -260,7 +260,7 @@ TEST(mempool, list) TEST(mempool, unordered_map) { - unittest_2::unordered_map h; + mempool::unittest_2::unordered_map h; h[1] = obj(); h[2] = obj(1); } -- 2.39.5