]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: put pool namespaces within mempool::
authorSage Weil <sage@redhat.com>
Tue, 18 Oct 2016 16:09:39 +0000 (12:09 -0400)
committerSage Weil <sage@redhat.com>
Wed, 2 Nov 2016 17:48:49 +0000 (13:48 -0400)
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

src/global/mempool.cc
src/include/mempool.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/bluestore_types.h
src/test/test_mempool.cc

index b034a79af7a76676732b3984f506b7017b9e9446..217ec1116ec221a575a0ee7599e6f0729fe4df69 100644 (file)
@@ -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);
index 565f0abe2c9352995d57153251cc7b9bb0237479..d801801bb5af299e1ba9ed6af9dfe73f8e8b9cd9 100644 (file)
@@ -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<int> myvec;
+  mempool::unittest_1::map<int> 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<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>>>;               \
@@ -376,12 +374,12 @@ public:
     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();                  \
     }                                                                  \
   };
 
@@ -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<obj>                                            \
+  mempool::pool::pool_allocator<obj>                                   \
   _factory_##pool##factoryname##_alloc = {true};
 
 // Use this for each class that belongs to a mempool.  For example,
index 61b7228fba9abc76eaac3b774864b42188f4aabe..2629075cede520e10de7b0c902eb18cbc6c2b08d 100644 (file)
@@ -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;
index 848ab7efbf4b9d67fbca7184d675fc04ebce324b..781c0993c69bb49986035fc649bfa358b2e0ecfa 100644 (file)
@@ -210,7 +210,8 @@ public:
        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
@@ -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<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);
@@ -523,7 +524,7 @@ public:
 #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>> {
@@ -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<Shard> shards;    ///< shards
+    mempool::bluestore_meta_other::vector<Shard> 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<ghobject_t,OnodeRef> onode_map;
+    mempool::bluestore_meta_other::unordered_map<ghobject_t,OnodeRef> 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_t, CollectionRef> coll_map;
+  mempool::bluestore_meta_other::unordered_map<coll_t, CollectionRef> coll_map;
 
   vector<Cache*> cache_shards;
 
index 901954a4e1c6224f4008d99e0640be2e0073eb37..123ad30b35bb48a7040c40f6b731eaf8ba904936 100644 (file)
@@ -188,7 +188,7 @@ struct bluestore_extent_ref_map_t {
     }
   };
 
-  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;
index 73c90b985d387e79719c133fe0dfed861be3b9f2..37ad3a31826f03479afbb441f296397fc6963dd3 100644 (file)
@@ -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<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();
@@ -122,7 +122,7 @@ TEST(mempool, list_context)
 {
   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);
@@ -139,12 +139,12 @@ TEST(mempool, list_context)
 
     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);
   }
 }
 
@@ -152,22 +152,22 @@ TEST(mempool, set_context)
 {
   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);
   }
 }
 
@@ -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<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));
   }
@@ -220,10 +220,10 @@ TEST(mempool, vector)
 
 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));
@@ -232,12 +232,12 @@ TEST(mempool, set)
 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);
@@ -247,12 +247,12 @@ TEST(mempool, map)
 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));
   }
@@ -260,7 +260,7 @@ TEST(mempool, list)
 
 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);
 }