OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMemArena Class Reference

#include <PMemAllocator.h>

+ Inheritance diagram for PMemArena:
+ Collaboration diagram for PMemArena:

Public Member Functions

 PMemArena (size_t min_block_size=1ULL<< 32, size_t size_limit=0)
 
 ~PMemArena () override
 
void * allocate (const size_t num_bytes) override
 
void * allocateAndZero (const size_t num_bytes) override
 
size_t bytesUsed () const override
 
size_t totalBytes () const override
 
MemoryType getMemoryType () const override
 
- Public Member Functions inherited from Arena
virtual ~Arena ()
 

Private Attributes

size_t size_limit_
 
size_t size_
 
std::vector< std::pair< void
*, size_t > > 
allocations_
 
struct memkind * pmem_kind_ = NULL
 

Additional Inherited Members

- Public Types inherited from Arena
enum  MemoryType { MemoryType::DRAM, MemoryType::PMEM }
 

Detailed Description

Definition at line 24 of file PMemAllocator.h.

Constructor & Destructor Documentation

PMemArena::PMemArena ( size_t  min_block_size = 1ULL << 32,
size_t  size_limit = 0 
)
explicit

Definition at line 25 of file PMemAllocator.cpp.

References CHECK, CHECK_EQ, CHECK_GE, report::error_code(), g_pmem_path, g_pmem_size, logger::INFO, LOG, and pmem_kind_.

26  : size_limit_(size_limit), size_(0) {
27  std::error_code ec;
28  auto pmem_space_info = std::filesystem::space(g_pmem_path.c_str(), ec);
29  CHECK(!ec) << "Failed to get pmem space info for path: " << g_pmem_path
30  << "error code: " << ec << "\n";
31  size_t capacity = pmem_space_info.capacity;
32  CHECK_EQ(memkind_check_dax_path(g_pmem_path.c_str()), 0)
33  << g_pmem_path << " is not recognized as a direct-access pmem path.";
34  CHECK_GE(capacity, g_pmem_size)
35  << g_pmem_path << " is not large enough for the requested PMem space";
36  CHECK_EQ(memkind_create_pmem(g_pmem_path.c_str(), capacity, &pmem_kind_), 0)
37  << "Failed to create PMEM memory.";
38  LOG(INFO) << "Created Pmem direct-access allocator at " << g_pmem_path
39  << " with capacity " << capacity << "\n";
40 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t g_pmem_size
size_t size_limit_
Definition: PMemAllocator.h:41
#define LOG(tag)
Definition: Logger.h:285
#define CHECK_GE(x, y)
Definition: Logger.h:306
std::string g_pmem_path
size_t size_
Definition: PMemAllocator.h:42
struct memkind * pmem_kind_
Definition: PMemAllocator.h:44
def error_code
Definition: report.py:234
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

PMemArena::~PMemArena ( )
override

Definition at line 42 of file PMemAllocator.cpp.

References allocations_, and pmem_kind_.

42  {
43  for (auto [ptr, size] : allocations_) {
44  memkind_free(pmem_kind_, ptr);
45  }
46 }
std::vector< std::pair< void *, size_t > > allocations_
Definition: PMemAllocator.h:43
struct memkind * pmem_kind_
Definition: PMemAllocator.h:44

Member Function Documentation

void * PMemArena::allocate ( const size_t  num_bytes)
overridevirtual

Implements Arena.

Definition at line 48 of file PMemAllocator.cpp.

References allocations_, pmem_kind_, size_, and size_limit_.

Referenced by allocateAndZero().

48  {
49  if (size_limit_ != 0 && size_ + num_bytes > size_limit_) {
50  throw OutOfHostMemory(num_bytes);
51  }
52  auto ret = memkind_malloc(pmem_kind_, num_bytes);
53  size_ += num_bytes;
54  allocations_.push_back({ret, num_bytes});
55  return ret;
56 }
size_t size_limit_
Definition: PMemAllocator.h:41
std::vector< std::pair< void *, size_t > > allocations_
Definition: PMemAllocator.h:43
size_t size_
Definition: PMemAllocator.h:42
struct memkind * pmem_kind_
Definition: PMemAllocator.h:44

+ Here is the caller graph for this function:

void * PMemArena::allocateAndZero ( const size_t  num_bytes)
overridevirtual

Implements Arena.

Definition at line 58 of file PMemAllocator.cpp.

References allocate().

58  {
59  auto ret = allocate(num_bytes);
60  std::memset(ret, 0, num_bytes);
61  return ret;
62 }
void * allocate(const size_t num_bytes) override

+ Here is the call graph for this function:

size_t PMemArena::bytesUsed ( ) const
overridevirtual

Implements Arena.

Definition at line 64 of file PMemAllocator.cpp.

References size_.

64  {
65  return size_;
66 }
size_t size_
Definition: PMemAllocator.h:42
MemoryType PMemArena::getMemoryType ( ) const
inlineoverridevirtual

Implements Arena.

Definition at line 38 of file PMemAllocator.h.

References Arena::PMEM.

size_t PMemArena::totalBytes ( ) const
overridevirtual

Implements Arena.

Definition at line 68 of file PMemAllocator.cpp.

68  {
69  return 0;
70 }

Member Data Documentation

std::vector<std::pair<void*, size_t> > PMemArena::allocations_
private

Definition at line 43 of file PMemAllocator.h.

Referenced by allocate(), and ~PMemArena().

struct memkind* PMemArena::pmem_kind_ = NULL
private

Definition at line 44 of file PMemAllocator.h.

Referenced by allocate(), PMemArena(), and ~PMemArena().

size_t PMemArena::size_
private

Definition at line 42 of file PMemAllocator.h.

Referenced by allocate(), and bytesUsed().

size_t PMemArena::size_limit_
private

Definition at line 41 of file PMemAllocator.h.

Referenced by allocate().


The documentation for this class was generated from the following files: