From: Sage Weil Date: Tue, 8 Nov 2016 23:50:37 +0000 (-0500) Subject: mempool: add [de]allocate_aligned X-Git-Tag: v11.1.0~325^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dcc23765b49489bb7ab5242f36db15eaff309e72;p=ceph.git mempool: add [de]allocate_aligned Signed-off-by: Sage Weil --- diff --git a/src/include/mempool.h b/src/include/mempool.h index aee5b0f3cd7d..7414ff2f08b4 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -307,6 +307,33 @@ public: delete[] reinterpret_cast(p); } + T* allocate_aligned(size_t n, size_t align, void *p = nullptr) { + size_t total = sizeof(T) * n; + shard_t *shard = pool->pick_a_shard(); + shard->bytes += total; + shard->items += n; + if (type) { + type->items += n; + } + char *ptr; + int rc = ::posix_memalign((void**)(void*)&ptr, align, total); + if (rc) + throw std::bad_alloc(); + T* r = reinterpret_cast(ptr); + return r; + } + + void deallocate_aligned(T* p, size_t n) { + size_t total = sizeof(T) * n; + shard_t *shard = pool->pick_a_shard(); + shard->bytes -= total; + shard->items -= n; + if (type) { + type->items -= n; + } + ::free(p); + } + void destroy(T* p) { p->~T(); }