From 098cbc4b40c9cf5a456e1e809227f147a53f02a5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 30 Nov 2016 16:58:53 -0500 Subject: [PATCH] buffer: put aligned buffers in buffer_data mempool Oops! Signed-off-by: Sage Weil --- src/common/buffer.cc | 11 ++--------- src/test/test_mempool.cc | 12 ++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index dce326dadce60..d26b8d676848e 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 32ad4fc45bb98..4113c53d27e5c 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; -- 2.39.5