Atlas Runtime
pregion_mgr_api.cpp File Reference
#include "atlas_alloc.h"
#include "atlas_alloc_cpp.hpp"
#include "pregion_mgr.hpp"
Include dependency graph for pregion_mgr_api.cpp:

Functions

uint32_t NVM_FindOrCreateRegion (const char *name, int flags, int *is_created)
 Create a persistent region with the provided name. More...
 
uint32_t NVM_FindRegion (const char *name, int flags)
 Find the id of a region when it is known to exist already. More...
 
uint32_t NVM_CreateRegion (const char *name, int flags)
 Create a named persistent region. More...
 
void NVM_CloseRegion (uint32_t rid)
 Close a persistent region. More...
 
void NVM_DeleteRegion (const char *name)
 Delete the region with the provided name. More...
 
void * NVM_GetRegionRoot (uint32_t rid)
 Get the root pointer of the persistent region. More...
 
void NVM_SetRegionRoot (uint32_t rid, void *new_root)
 Set the root pointer of an existing persistent region. More...
 
void * nvm_alloc (size_t sz, uint32_t rid)
 Malloc style interface for allocation from a persistent region. More...
 
void * nvm_calloc (size_t nmemb, size_t sz, uint32_t rid)
 Calloc style interface for allocation from a persistent region. More...
 
void * nvm_realloc (void *ptr, size_t sz, uint32_t rid)
 Realloc style interface for allocation from a persistent region. More...
 
void nvm_free (void *ptr)
 Deallocation interface for persistent data. More...
 
void nvm_delete (void *ptr)
 
int NVM_IsInOpenPR (void *addr, size_t sz)
 
int isOnDifferentCacheLine (void *p1, void *p2)
 Determines if the addresses are on different cache lines. More...
 
int isCacheLineAligned (void *p)
 Determines if a memory location is aligned to a cache line. More...
 
int NVM_IsInRegion (void *ptr, size_t sz)
 Determines if a memory location is within a region. More...
 
PRegionNVM_GetRegion (uint32_t rid)
 Get a handle to a persistent region. More...
 
void * operator new (size_t sz, Atlas::PRegion *rgn) noexcept
 Object allocation for C++. More...
 
void * operator new[] (size_t sz, Atlas::PRegion *rgn) noexcept
 Array form allocation for C++, type must have explicit destructor. More...
 

Function Documentation

int isCacheLineAligned ( void *  p)

Determines if a memory location is aligned to a cache line.

Parameters
pAddress of memory location under consideration
Returns
Indicates whether the memory location is cache line aligned
int isOnDifferentCacheLine ( void *  p1,
void *  p2 
)

Determines if the addresses are on different cache lines.

Parameters
p1First address
p2Second address
Returns
Indicates whether the addresses are on different cache lines

The objects under consideration must not cross cache lines, otherwise this interface is inadequate.

void* nvm_alloc ( size_t  sz,
uint32_t  rid 
)

Malloc style interface for allocation from a persistent region.

Parameters
szSize of location to be allocated
ridId of persistent region for allocation
Returns
Address of memory location allocated
void* nvm_calloc ( size_t  nmemb,
size_t  sz,
uint32_t  rid 
)

Calloc style interface for allocation from a persistent region.

Parameters
nmembNumber of elements in the array to be allocated
szSize of each element
ridId of persistent region for allocation
Returns
Pointer to allocated memory
void NVM_CloseRegion ( uint32_t  rid)

Close a persistent region.

Parameters
ridRegion id

After closing, it won't be available to the calling process without calling NVM_FindOrCreateRegion. The region will stay in NVM even after calling this interface. This interface allows closing a region with normal bookkeeping.

uint32_t NVM_CreateRegion ( const char *  name,
int  flags 
)

Create a named persistent region.

Parameters
nameName of the persistent region
flagsaccess flag (one of O_RDONLY, O_WRONLY, O_RDWR)
Returns
Id of the region created

This interface does not check for an existing entry with the same name. If a region with the same name already exists, the behavior of the program is undefined.

void nvm_delete ( void *  ptr)
void NVM_DeleteRegion ( const char *  name)

Delete the region with the provided name.

Parameters
nameName of the persistent region

Use this interface to completely destroy a region. If the region does not exist, an assertion failure will occur.

uint32_t NVM_FindOrCreateRegion ( const char *  name,
int  flags,
int *  is_created 
)

Create a persistent region with the provided name.

Parameters
nameName of the persistent region
flagsaccess flag (one of O_RDONLY, O_WRONLY, O_RDWR)
is_createdIndicator whether the region got created as a result of the call
Returns
Id of the region found or created

If the region already exists, the existing id of the region is returned. Otherwise a region is created and its newly assigned id returned.

uint32_t NVM_FindRegion ( const char *  name,
int  flags 
)

Find the id of a region when it is known to exist already.

Parameters
nameName of the persistent region
flagsaccess flag (one of O_RDONLY, O_WRONLY, O_RDWR)
Returns
Id of the region found

This interface should be used over NVM_FindOrCreateRegion for efficiency reasons if the region is known to exist. If a region with the provided name does not exist, an assertion failure will occur.

void nvm_free ( void *  ptr)

Deallocation interface for persistent data.

Parameters
ptrAddress of memory location to be freed.

Though the usual use case would be for the location to be in persistent memory, this interface will also work for transient data. The implementation is required to transparently handle this case as well.

PRegion* NVM_GetRegion ( uint32_t  rid)

Get a handle to a persistent region.

Parameters
ridRegion identifier
Returns
Pointer to the corresponding persistent region

Currently, this interface is to be used by a client only for the placement new operations

void* NVM_GetRegionRoot ( uint32_t  rid)

Get the root pointer of the persistent region.

Parameters
ridRegion id
Returns
Root pointer of the region

The region must have been created already. Currently, only one root is implemented for a given region. The idea is that anything within a region that is not reachable from the root after program termination is assumed to be garbage and can be recycled. During execution, anything within a region that is not reachable from the root or from other roots (in the GC sense) is assumed to be garbage as well.

int NVM_IsInOpenPR ( void *  addr,
size_t  sz 
)

Is the following address with associated size within an open persistent region?

int NVM_IsInRegion ( void *  ptr,
size_t  sz 
)

Determines if a memory location is within a region.

Parameters
ptrQueried address
szSize of the location in bytes
Returns
1 if within the region, otherwise 0
void* nvm_realloc ( void *  ptr,
size_t  sz,
uint32_t  rid 
)

Realloc style interface for allocation from a persistent region.

Parameters
ptrAddress of memory block provided
szNew size of allocation
ridId of persistent region for allocation
Returns
Pointer to re-allocated memory
void NVM_SetRegionRoot ( uint32_t  rid,
void *  root 
)

Set the root pointer of an existing persistent region.

Parameters
ridRegion id
rootThe new root of the region
void* operator new ( size_t  sz,
Atlas::PRegion rgn 
)
noexcept

Object allocation for C++.

Parameters
szAllocation size
rgnPointer to the region to serve the allocation from
Returns
Pointer to memory allocated

This interface overloads the C++ placement new operator. The corresponding delete operation is NVM_Destroy.

void* operator new[] ( size_t  sz,
Atlas::PRegion rgn 
)
noexcept

Array form allocation for C++, type must have explicit destructor.

Parameters
szAllocation size
rgnPointer to the region to serve the allocation from
Returns
Pointer to memory allocated

This interface overloads the array form C++ placement new operator. The type of the array elements must have an explicit destructor. The corresponding delete operation is NVM_Destroy_Array.