]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/memory/memkind_kmem_allocator.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / memory / memkind_kmem_allocator.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // Copyright (c) 2019 Intel Corporation
3 // This source code is licensed under both the GPLv2 (found in the
4 // COPYING file in the root directory) and Apache 2.0 License
5 // (found in the LICENSE.Apache file in the root directory).
6
7 #ifdef MEMKIND
8 #include <memkind.h>
9 #endif // MEMKIND
10
11 #include "memory/memkind_kmem_allocator.h"
12
13 namespace ROCKSDB_NAMESPACE {
14 Status MemkindKmemAllocator::PrepareOptions(const ConfigOptions& options) {
15 std::string message;
16 if (!IsSupported(&message)) {
17 return Status::NotSupported(message);
18 } else {
19 return MemoryAllocator::PrepareOptions(options);
20 }
21 }
22
23 #ifdef MEMKIND
24 void* MemkindKmemAllocator::Allocate(size_t size) {
25 void* p = memkind_malloc(MEMKIND_DAX_KMEM, size);
26 if (p == NULL) {
27 throw std::bad_alloc();
28 }
29 return p;
30 }
31
32 void MemkindKmemAllocator::Deallocate(void* p) {
33 memkind_free(MEMKIND_DAX_KMEM, p);
34 }
35
36 #ifdef ROCKSDB_MALLOC_USABLE_SIZE
37 size_t MemkindKmemAllocator::UsableSize(void* p,
38 size_t /*allocation_size*/) const {
39 return memkind_malloc_usable_size(MEMKIND_DAX_KMEM, p);
40 }
41 #endif // ROCKSDB_MALLOC_USABLE_SIZE
42 #endif // MEMKIND
43
44 } // namespace ROCKSDB_NAMESPACE