UMPIRE
Umpire: resource management and provision
umpire::resource::FileMemoryResource Class Reference

File Memory allocator. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/umpire/checkouts/develop/src/umpire/resource/FileMemoryResource.hpp>

Inheritance diagram for umpire::resource::FileMemoryResource:

Public Member Functions

 FileMemoryResource (Platform platform, const std::string &name, int id, MemoryResourceTraits traits)
 Construct a new FileMemoryResource. More...
 
 ~FileMemoryResource ()
 Dallocates and removes all files created by the code meant for allocations. More...
 
void * allocate (std::size_t bytes)
 Creates the allocation of size bytes using mmap. More...
 
void deallocate (void *ptr, std::size_t size)
 Deallocates file connected to the pointer. More...
 
std::size_t getCurrentSize () const noexcept
 Get current (total) size of the allocated memory. More...
 
std::size_t getHighWatermark () const noexcept
 Get the high watermark of the total allocated size. More...
 
bool isAccessibleFrom (Platform p) noexcept
 
Platform getPlatform () noexcept
 Get the Platform assocatiated with this MemoryResource. More...
 
MemoryResourceTraits getTraits () const noexcept override
 
void * allocate_internal (std::size_t bytes)
 
void * allocate_named_internal (const std::string &name, std::size_t bytes)
 
void deallocate_internal (void *ptr, std::size_t size=0)
 
virtual void release ()
 Release any and all unused memory held by this AllocationStrategy. More...
 
virtual std::size_t getActualSize () const noexcept
 Get the current amount of memory allocated by this allocator. More...
 
virtual std::size_t getAllocationCount () const noexcept
 Get the total number of active allocations by this allocator. More...
 
const std::string & getName () noexcept
 Get the name of this AllocationStrategy. More...
 
const std::string & getStrategyName () const noexcept
 
int getId () noexcept
 Get the id of this AllocationStrategy. More...
 
virtual AllocationStrategygetParent () const noexcept
 Traces where the allocator came from. More...
 
virtual bool tracksMemoryUse () const noexcept
 
bool isTracked () const noexcept
 

Public Attributes

std::size_t m_current_size {0}
 
std::size_t m_high_watermark {0}
 
std::size_t m_allocation_count {0}
 

Static Public Attributes

static int s_file_counter {0}
 

Protected Member Functions

void setTracking (bool) noexcept
 

Protected Attributes

Platform m_platform
 
MemoryResourceTraits m_traits
 
std::string m_name
 
std::string m_strategy_name
 
int m_id
 
bool m_tracked {true}
 
AllocationStrategym_parent
 

Detailed Description

File Memory allocator.

This FileMemoryResource uses mmap to create a file mapping in order to use as additional memory. To create this mapping the function needs to take in the size of memory wanted for the allocation. The set location for the allocation by defult is ./ but can be assigned using enviroment variable "UMPIRE_MEMORY_FILE_DIR"

The return should be a pointer location. The same pointer location can be used for the deallocation. Deallocation uses munmap and removes the file associated with the pointer location.

Constructor & Destructor Documentation

◆ FileMemoryResource()

umpire::resource::FileMemoryResource::FileMemoryResource ( Platform  platform,
const std::string &  name,
int  id,
MemoryResourceTraits  traits 
)

Construct a new FileMemoryResource.

Parameters
platformPlatform of this instance of the FileMemoryResource.
nameName of this instance of the FileMemoryResource.
idId of this instance of the FileMemoryResource.
traitsTraits of this instance of the FileMemoryResource.

◆ ~FileMemoryResource()

umpire::resource::FileMemoryResource::~FileMemoryResource ( )

Dallocates and removes all files created by the code meant for allocations.

References deallocate().

Member Function Documentation

◆ allocate()

void * umpire::resource::FileMemoryResource::allocate ( std::size_t  bytes)
virtual

Creates the allocation of size bytes using mmap.

Does the allocation as follows: 1) Find output file directory for mmap files using UMPIRE_MEMORY_FILE_DIR 2) Create name and create the file index using open 3) Setting Size Of Map File. Size is scaled to a page length on the system. 4) Truncate file using ftruncate64 5) Map file index with mmap 6) Store information about the allocated file into m_size_map

Parameters
bytesThe requested amount of bytes the user wants to use. Can not be zero or greater than avalable amount of bytes available.
UMPIRE_MEMORY_FILE_DIRUsed to specify where memory is going to be allocated from
Returns
void* Since you are only reciving a pointer location of any size non spcaific to a type you will have to cast it to the desired type if needed.

Implements umpire::resource::MemoryResource.

References umpire::util::MemoryMap< V >::insert(), s_file_counter, and UMPIRE_ERROR.

◆ deallocate()

void umpire::resource::FileMemoryResource::deallocate ( void *  ptr,
std::size_t  size 
)
virtual

Deallocates file connected to the pointer.

Using m_size_map, the pointer is looked up and the file name and size can be returned. With this munmap can be called to deallocated the correct file.

Parameters
ptrPointer location used to look up its information in m_size_map

Implements umpire::resource::MemoryResource.

References umpire::util::MemoryMap< V >::erase(), umpire::util::MemoryMap< V >::find(), and UMPIRE_ERROR.

Referenced by ~FileMemoryResource().

◆ getCurrentSize()

std::size_t umpire::resource::FileMemoryResource::getCurrentSize ( ) const
virtualnoexcept

Get current (total) size of the allocated memory.

This is the total size of all allocation currently 'live' that have been made by this AllocationStrategy object.

Returns
Current total size of allocations.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ getHighWatermark()

std::size_t umpire::resource::FileMemoryResource::getHighWatermark ( ) const
virtualnoexcept

Get the high watermark of the total allocated size.

This is equivalent to the highest observed value of getCurrentSize.

Returns
High watermark allocation size.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ isAccessibleFrom()

bool umpire::resource::FileMemoryResource::isAccessibleFrom ( Platform  p)
virtualnoexcept

◆ getPlatform()

Platform umpire::resource::FileMemoryResource::getPlatform ( )
virtualnoexcept

Get the Platform assocatiated with this MemoryResource.

This function is pure virtual and must be implemented by the inheriting class.

Returns
Platform associated with this MemoryResource.

Implements umpire::resource::MemoryResource.

References m_platform.

◆ getTraits()

MemoryResourceTraits umpire::resource::MemoryResource::getTraits ( ) const
overridevirtualnoexceptinherited

◆ allocate_internal()

◆ allocate_named_internal()

void * umpire::strategy::AllocationStrategy::allocate_named_internal ( const std::string &  name,
std::size_t  bytes 
)
inherited

◆ deallocate_internal()

◆ release()

void umpire::strategy::AllocationStrategy::release ( )
virtualinherited

◆ getActualSize()

std::size_t umpire::strategy::AllocationStrategy::getActualSize ( ) const
virtualnoexceptinherited

Get the current amount of memory allocated by this allocator.

Note that this can be larger than getCurrentSize(), particularly if the AllocationStrategy implements some kind of pooling.

Returns
The total size of all the memory this object has allocated.

Reimplemented in umpire::strategy::FixedPool, umpire::strategy::ResourceAwarePool, umpire::strategy::QuickPool, umpire::strategy::MixedPool, umpire::strategy::DynamicPoolList, and umpire::resource::HostSharedMemoryResource.

References umpire::strategy::AllocationStrategy::getCurrentSize().

Referenced by umpire::Allocator::getActualSize().

◆ getAllocationCount()

std::size_t umpire::strategy::AllocationStrategy::getAllocationCount ( ) const
virtualnoexceptinherited

Get the total number of active allocations by this allocator.

Returns
The total number of active allocations this object has allocated.

References umpire::strategy::AllocationStrategy::m_allocation_count.

Referenced by umpire::Allocator::getAllocationCount().

◆ getName()

◆ getStrategyName()

const std::string & umpire::strategy::AllocationStrategy::getStrategyName ( ) const
noexceptinherited

◆ getId()

int umpire::strategy::AllocationStrategy::getId ( )
noexceptinherited

Get the id of this AllocationStrategy.

Returns
The id of this AllocationStrategy.

References umpire::strategy::AllocationStrategy::m_id.

Referenced by umpire::ResourceManager::destroyAllocator(), and umpire::Allocator::getId().

◆ getParent()

AllocationStrategy * umpire::strategy::AllocationStrategy::getParent ( ) const
virtualnoexceptinherited

Traces where the allocator came from.

Returns
Pointer to the parent AllocationStrategy.

References umpire::strategy::AllocationStrategy::m_parent.

Referenced by umpire::ResourceManager::destroyAllocator(), umpire::Allocator::getParent(), and umpire::is_accessible().

◆ tracksMemoryUse()

bool umpire::strategy::AllocationStrategy::tracksMemoryUse ( ) const
virtualnoexceptinherited

◆ isTracked()

bool umpire::strategy::AllocationStrategy::isTracked ( ) const
noexceptinherited

◆ setTracking()

void umpire::strategy::AllocationStrategy::setTracking ( bool  tracking)
protectednoexceptinherited

Member Data Documentation

◆ s_file_counter

int umpire::resource::FileMemoryResource::s_file_counter {0}
static

Referenced by allocate().

◆ m_platform

Platform umpire::resource::FileMemoryResource::m_platform
protected

Referenced by getPlatform().

◆ m_traits

◆ m_current_size

◆ m_high_watermark

◆ m_allocation_count

◆ m_name

std::string umpire::strategy::AllocationStrategy::m_name
protectedinherited

◆ m_strategy_name

std::string umpire::strategy::AllocationStrategy::m_strategy_name
protectedinherited

◆ m_id

int umpire::strategy::AllocationStrategy::m_id
protectedinherited

◆ m_tracked

bool umpire::strategy::AllocationStrategy::m_tracked {true}
protectedinherited

◆ m_parent

AllocationStrategy* umpire::strategy::AllocationStrategy::m_parent
protectedinherited