From: Sage Weil Date: Tue, 30 May 2017 19:58:53 +0000 (-0400) Subject: buffer: remove buffer_data mempool X-Git-Tag: ses5-milestone6~9^2~44^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=390b4d15e5a454da46eb54d319ecd39d3c404df3;p=ceph.git buffer: remove buffer_data mempool We are explicitly accounting for buffers via arbitrary pools, defaulting to buffer_anon, so we don't need buffer_data anymore. It leads to double-counting. Signed-off-by: Sage Weil --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 42c150f45fad..7e884df31d5e 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -269,8 +269,6 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; } }; - MEMPOOL_DEFINE_FACTORY(char, char, buffer_data); - /* * raw_combined is always placed within a single allocation along * with the data buffer. the data goes at the beginning, and @@ -299,8 +297,14 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; alignof(buffer::raw_combined)); size_t datalen = ROUND_UP_TO(len, alignof(buffer::raw_combined)); - char *ptr = mempool::buffer_data::alloc_char.allocate_aligned( - rawlen + datalen, align); +#ifdef DARWIN + char *ptr = (char *) valloc(rawlen + datalen); +#else + char *ptr = 0; + int r = ::posix_memalign((void**)(void*)&ptr, align, rawlen + datalen); + if (r) + throw bad_alloc(); +#endif /* DARWIN */ if (!ptr) throw bad_alloc(); @@ -311,11 +315,7 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; static void operator delete(void *ptr) { raw_combined *raw = (raw_combined *)ptr; - size_t rawlen = ROUND_UP_TO(sizeof(buffer::raw_combined), - alignof(buffer::raw_combined)); - size_t datalen = ROUND_UP_TO(raw->len, alignof(buffer::raw_combined)); - mempool::buffer_data::alloc_char.deallocate_aligned( - raw->data, rawlen + datalen); + ::free((void *)raw->data); } }; @@ -380,7 +380,13 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; raw_posix_aligned(unsigned l, unsigned _align) : raw(l) { align = _align; assert((align >= sizeof(void *)) && (align & (align - 1)) == 0); - data = mempool::buffer_data::alloc_char.allocate_aligned(len, align); +#ifdef DARWIN + data = (char *) valloc(len); +#else + int r = ::posix_memalign((void**)(void*)&data, align, len); + if (r) + throw bad_alloc(); +#endif /* DARWIN */ if (!data) throw bad_alloc(); inc_total_alloc(len); @@ -388,7 +394,7 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; bdout << "raw_posix_aligned " << this << " alloc " << (void *)data << " l=" << l << ", align=" << align << " total_alloc=" << buffer::get_total_alloc() << bendl; } ~raw_posix_aligned() override { - mempool::buffer_data::alloc_char.deallocate_aligned(data, len); + ::free(data); dec_total_alloc(len); bdout << "raw_posix_aligned " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl; } @@ -614,7 +620,7 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; explicit raw_char(unsigned l) : raw(l) { if (len) - data = mempool::buffer_data::alloc_char.allocate(len); + data = new char[len]; else data = 0; inc_total_alloc(len); @@ -626,8 +632,7 @@ static std::atomic_flag buffer_debug_lock = ATOMIC_FLAG_INIT; bdout << "raw_char " << this << " alloc " << (void *)data << " " << l << " " << buffer::get_total_alloc() << bendl; } ~raw_char() override { - if (data) - mempool::buffer_data::alloc_char.deallocate(data, len); + delete[] data; dec_total_alloc(len); bdout << "raw_char " << this << " free " << (void *)data << " " << buffer::get_total_alloc() << bendl; } diff --git a/src/include/mempool.h b/src/include/mempool.h index 5eaf6b3d46a6..e75fedd2a125 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -143,7 +143,6 @@ namespace mempool { f(bluestore_fsck) \ f(bluefs) \ f(buffer_anon) \ - f(buffer_data) \ f(buffer_meta) \ f(osd) \ f(osdmap) \ diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index 3be6f02d171e..443d1b0ead57 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -269,10 +269,10 @@ TEST(mempool, bufferlist) { bufferlist bl; int len = 1048576; - size_t before = mempool::buffer_data::allocated_bytes(); + size_t before = mempool::buffer_anon::allocated_bytes(); cout << "before " << before << std::endl; bl.append(buffer::create_aligned(len, 4096)); - size_t after = mempool::buffer_data::allocated_bytes(); + size_t after = mempool::buffer_anon::allocated_bytes(); cout << "after " << after << std::endl; ASSERT_GE(after, before + len); }