]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: put aligned buffers in buffer_data mempool
authorSage Weil <sage@redhat.com>
Wed, 30 Nov 2016 21:58:53 +0000 (16:58 -0500)
committerSage Weil <sage@redhat.com>
Wed, 30 Nov 2016 21:58:53 +0000 (16:58 -0500)
Oops!

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/buffer.cc
src/test/test_mempool.cc

index dce326dadce608571faf30aad624018c5b3334ea..d26b8d676848e26a856a0de6055ae8b3fe8cec0e 100644 (file)
@@ -349,14 +349,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     raw_posix_aligned(unsigned l, unsigned _align) : raw(l) {
       align = _align;
       assert((align >= sizeof(void *)) && (align & (align - 1)) == 0);
-#ifdef DARWIN
-      data = (char *) valloc (len);
-#else
-      data = 0;
-      int r = ::posix_memalign((void**)(void*)&data, align, len);
-      if (r)
-       throw bad_alloc();
-#endif /* DARWIN */
+      data = mempool::buffer_data::alloc_char.allocate_aligned(len, align);
       if (!data)
        throw bad_alloc();
       inc_total_alloc(len);
@@ -364,7 +357,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
       bdout << "raw_posix_aligned " << this << " alloc " << (void *)data << " l=" << l << ", align=" << align << " total_alloc=" << buffer::get_total_alloc() << bendl;
     }
     ~raw_posix_aligned() {
-      ::free((void*)data);
+      mempool::buffer_data::alloc_char.deallocate_aligned(data, len);
       dec_total_alloc(len);
       bdout << "raw_posix_aligned " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl;
     }
index 32ad4fc45bb98584971f9a49ae0186d7328df1b6..4113c53d27e5c1cc878a0a9740317df8bb7db997 100644 (file)
@@ -265,6 +265,18 @@ TEST(mempool, unordered_map)
   h[2] = obj(1);
 }
 
+TEST(mempool, bufferlist)
+{
+  bufferlist bl;
+  int len = 1048576;
+  size_t before = mempool::buffer_data::allocated_bytes();
+  cout << "before " << before << std::endl;
+  bl.append(buffer::create_aligned(len, 4096));
+  size_t after = mempool::buffer_data::allocated_bytes();
+  cout << "after " << after << std::endl;
+  ASSERT_GE(after, before + len);
+}
+
 int main(int argc, char **argv)
 {
   vector<const char*> args;