]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: add [de]allocate_aligned
authorSage Weil <sage@redhat.com>
Tue, 8 Nov 2016 23:50:37 +0000 (18:50 -0500)
committerSage Weil <sage@redhat.com>
Fri, 11 Nov 2016 19:59:54 +0000 (14:59 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/mempool.h

index aee5b0f3cd7d32a16510e97bbdd4763c43988c2a..7414ff2f08b4e1636b49ed98bf36b3941f6a9b76 100644 (file)
@@ -307,6 +307,33 @@ public:
     delete[] reinterpret_cast<char*>(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<T*>(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();
   }