From: Sage Weil Date: Wed, 30 Nov 2016 21:58:53 +0000 (-0500) Subject: buffer: put aligned buffers in buffer_data mempool X-Git-Tag: v11.1.0~84^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=098cbc4b40c9cf5a456e1e809227f147a53f02a5;p=ceph.git buffer: put aligned buffers in buffer_data mempool Oops! Signed-off-by: Sage Weil --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index dce326dadce..d26b8d67684 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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; } diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index 32ad4fc45bb..4113c53d27e 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -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 args;