memkind_kmem_allocator.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #pragma once
  7. #include "rocksdb/memory_allocator.h"
  8. #include "utilities/memory_allocators.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. class MemkindKmemAllocator : public BaseMemoryAllocator {
  11. public:
  12. static const char* kClassName() { return "MemkindKmemAllocator"; }
  13. const char* Name() const override { return kClassName(); }
  14. static bool IsSupported() {
  15. std::string unused;
  16. return IsSupported(&unused);
  17. }
  18. static bool IsSupported(std::string* msg) {
  19. #ifdef MEMKIND
  20. (void)msg;
  21. return true;
  22. #else
  23. *msg = "Not compiled with MemKind";
  24. return false;
  25. #endif
  26. }
  27. Status PrepareOptions(const ConfigOptions& options) override;
  28. #ifdef MEMKIND
  29. void* Allocate(size_t size) override;
  30. void Deallocate(void* p) override;
  31. #ifdef ROCKSDB_MALLOC_USABLE_SIZE
  32. size_t UsableSize(void* p, size_t /*allocation_size*/) const override;
  33. #endif
  34. #endif // MEMKIND
  35. };
  36. } // namespace ROCKSDB_NAMESPACE