]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/bloom_filter: put filter data in mempool 13009/head
authorSage Weil <sage@redhat.com>
Thu, 19 Jan 2017 21:09:36 +0000 (15:09 -0600)
committerSage Weil <sage@redhat.com>
Thu, 19 Jan 2017 21:09:36 +0000 (15:09 -0600)
We need to be a bit careful with deallocation because we need to pass
the mempool the size of the deallocated char array.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/bloom_filter.cc
src/common/bloom_filter.hpp
src/include/mempool.h

index d85dbea223a20301c7d8f737e3a4481008dda007..5a7a3ac18c3bf4836b0df2f872497f66aa2e9c6a 100644 (file)
@@ -4,6 +4,8 @@
 #include "include/types.h"
 #include "common/bloom_filter.hpp"
 
+MEMPOOL_DEFINE_FACTORY(unsigned char, byte, bloom_filter);
+
 void bloom_filter::encode(bufferlist& bl) const
 {
   ENCODE_START(2, 2, bl);
index 2a04d12016a2deceb0490a0ddfafee61f0e1bc95..8e826c4af6db9413d43802df9215d744baa23646 100644 (file)
@@ -30,6 +30,7 @@
 #include <string>
 #include <vector>
 
+#include "include/mempool.h"
 #include "include/encoding.h"
 #include "common/Formatter.h"
 
@@ -45,6 +46,7 @@ static const unsigned char bit_mask[bits_per_char] = {
   0x80   //10000000
 };
 
+MEMPOOL_DECLARE_FACTORY(unsigned char, byte, bloom_filter);
 
 class bloom_filter
 {
@@ -103,7 +105,7 @@ public:
   void init() {
     generate_unique_salt();
     if (table_size_) {
-      bit_table_ = new cell_type[table_size_];
+      bit_table_ = mempool::bloom_filter::alloc_byte.allocate(table_size_);
       std::fill_n(bit_table_, table_size_, 0x00);
     } else {
       bit_table_ = NULL;
@@ -119,13 +121,15 @@ public:
   bloom_filter& operator = (const bloom_filter& filter)
   {
     if (this != &filter) {
+      if (bit_table_) {
+       mempool::bloom_filter::alloc_byte.deallocate(bit_table_, table_size_);
+      }
       salt_count_ = filter.salt_count_;
       table_size_ = filter.table_size_;
       insert_count_ = filter.insert_count_;
       target_element_count_ = filter.target_element_count_;
       random_seed_ = filter.random_seed_;
-      delete[] bit_table_;
-      bit_table_ = new cell_type[table_size_];
+      bit_table_ = mempool::bloom_filter::alloc_byte.allocate(table_size_);
       std::copy(filter.bit_table_, filter.bit_table_ + table_size_, bit_table_);
       salt_ = filter.salt_;
     }
@@ -134,7 +138,7 @@ public:
 
   virtual ~bloom_filter()
   {
-    delete[] bit_table_;
+    mempool::bloom_filter::alloc_byte.deallocate(bit_table_, table_size_);
   }
 
   inline bool operator!() const
@@ -576,7 +580,7 @@ public:
       return false;
     }
 
-    cell_type* tmp = new cell_type[new_table_size];
+    cell_type* tmp = mempool::bloom_filter::alloc_byte.allocate(new_table_size);
     std::copy(bit_table_, bit_table_ + (new_table_size), tmp);
     cell_type* itr = bit_table_ + (new_table_size);
     cell_type* end = bit_table_ + (original_table_size);
@@ -589,7 +593,7 @@ public:
        itr_tmp = tmp;
     }
 
-    delete[] bit_table_;
+    mempool::bloom_filter::alloc_byte.deallocate(bit_table_, table_size_);
     bit_table_ = tmp;
     size_list.push_back(new_table_size);
     table_size_ = new_table_size;
index 607ad3dc99474dbdd2fb4fed50890bae094dd5a6..b89451ee995f5cf149097bb18f04fd7521691ea7 100644 (file)
@@ -30,6 +30,7 @@
 #include <typeinfo>
 
 #include <common/Formatter.h>
+#include "include/assert.h"
 
 
 /*
@@ -413,6 +414,13 @@ DEFINE_MEMORY_POOLS_HELPER(P)
 
 // Use this for any type that is contained by a container (unless it
 // is a class you defined; see below).
+#define MEMPOOL_DECLARE_FACTORY(obj, factoryname, pool)                        \
+  namespace mempool {                                                  \
+    namespace pool {                                                   \
+      extern pool_allocator<obj> alloc_##factoryname;                  \
+    }                                                                  \
+  }
+
 #define MEMPOOL_DEFINE_FACTORY(obj, factoryname, pool)                 \
   namespace mempool {                                                  \
     namespace pool {                                                   \