Class FileMemoryResource

Inheritance Relationships

Base Type

Class Documentation

class umpire::resource::FileMemoryResource : public umpire::resource::MemoryResource

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.

Public Functions

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

Construct a new FileMemoryResource.

Parameters

~FileMemoryResource()

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

void *allocate(std::size_t bytes)

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

Return

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.

Parameters
  • bytes: The requested amount of bytes the user wants to use. Can not be zero or greater than avalable amount of bytes available.

  • UMPIRE_MEMORY_FILE_DIR: Used to specify where memory is going to be allocated from

void deallocate(void *ptr)

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
  • ptr: Pointer location used to look up its information in m_size_map

std::size_t getCurrentSize() const noexcept

Return the current size of this MemoryResource.

This is sum of the sizes of all the tracked allocations. Note that this doesn’t ever have to be equal to getHighWatermark.

Return

current total size of active allocations in this MemoryResource.

std::size_t getHighWatermark() const noexcept

Return the memory high watermark for this MemoryResource.

This is the largest amount of memory allocated by this Allocator. Note that this may be larger than the largest value returned by getCurrentSize.

Return

Memory high watermark.

Platform getPlatform() noexcept

Get the Platform assocatiated with this MemoryResource.

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

Return

Platform associated with this MemoryResource.

MemoryResourceTraits getTraits() const noexcept override
void release()

Release any and all unused memory held by this AllocationStrategy.

std::size_t getActualSize() const noexcept

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.

Return

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

std::size_t getAllocationCount() const noexcept

Get the total number of active allocations by this allocator.

Return

The total number of active allocations this object has allocated.

const std::string &getName() noexcept

Get the name of this AllocationStrategy.

Return

The name of this AllocationStrategy.

int getId() noexcept

Get the id of this AllocationStrategy.

Return

The id of this AllocationStrategy.

Public Static Attributes

int s_file_counter = {0}

Protected Attributes

Platform m_platform
MemoryResourceTraits m_traits
std::string m_name
int m_id