Public Types | Public Member Functions | List of all members
rapidsmpf::SpillManager Class Reference

Manages memory spilling to free up device memory when needed. More...

#include <spill_manager.hpp>

Public Types

using SpillFunction = std::function< std::size_t(std::size_t)>
 Spill function type. More...
 
using SpillFunctionID = std::size_t
 Represents a unique identifier for a registered spill function.
 

Public Member Functions

 SpillManager (BufferResource *br, std::optional< Duration > periodic_spill_check=std::nullopt)
 Constructs a SpillManager instance. More...
 
 ~SpillManager ()
 Destructor for SpillManager. More...
 
SpillFunctionID add_spill_function (SpillFunction spill_function, int priority)
 Adds a spill function with a given priority to the spill manager. More...
 
void remove_spill_function (SpillFunctionID fid)
 Removes a spill function from the spill manager. More...
 
std::size_t spill (std::size_t amount)
 Initiates spilling to free up a specified amount of memory. More...
 
std::size_t spill_to_make_headroom (std::int64_t headroom=0)
 Attempts to free up memory by spilling data until the requested headroom is available. More...
 

Detailed Description

Manages memory spilling to free up device memory when needed.

The SpillManager is responsible for registering, prioritizing, and executing spill functions to ensure efficient memory management.

Definition at line 25 of file spill_manager.hpp.

Member Typedef Documentation

◆ SpillFunction

using rapidsmpf::SpillManager::SpillFunction = std::function<std::size_t(std::size_t)>

Spill function type.

A spill function takes a requested spill amount as input and returns the actual amount of memory (in bytes) that was spilled.

Definition at line 33 of file spill_manager.hpp.

Constructor & Destructor Documentation

◆ SpillManager()

rapidsmpf::SpillManager::SpillManager ( BufferResource br,
std::optional< Duration >  periodic_spill_check = std::nullopt 
)

Constructs a SpillManager instance.

Parameters
brBuffer resource used to retrieve current available memory.
periodic_spill_checkEnable periodic spill checks. A dedicated thread continuously checks and perform spilling based on the current available memory as reported by the buffer resource. The value of periodic_spill_check is used as the pause between checks. If std::nullopt, no periodic spill check is performed.

◆ ~SpillManager()

rapidsmpf::SpillManager::~SpillManager ( )

Destructor for SpillManager.

Cleans up any allocated resources and stops periodic spill checks if active (this will block until all spill functions has stopped).

Member Function Documentation

◆ add_spill_function()

SpillFunctionID rapidsmpf::SpillManager::add_spill_function ( SpillFunction  spill_function,
int  priority 
)

Adds a spill function with a given priority to the spill manager.

The spill function is prioritized according to the specified priority value.

Parameters
spill_functionThe spill function to be added.
priorityThe priority level of the spill function (higher values indicate higher priority).
Returns
The id assigned to the newly added spill function.

◆ remove_spill_function()

void rapidsmpf::SpillManager::remove_spill_function ( SpillFunctionID  fid)

Removes a spill function from the spill manager.

This method unregisters the spill function associated with the given ID and removes it from the priority list. If no more spill functions remain, the periodic spill thread is paused.

Parameters
fidThe id of the spill function to be removed.

◆ spill()

std::size_t rapidsmpf::SpillManager::spill ( std::size_t  amount)

Initiates spilling to free up a specified amount of memory.

This method iterates through registered spill functions in priority order, invoking them until at least the requested amount of memory has been spilled or no more spilling is possible.

Parameters
amountThe amount of memory (in bytes) to spill.
Returns
The actual amount of memory spilled (in bytes), which may be more, less or equal to the requested.

◆ spill_to_make_headroom()

std::size_t rapidsmpf::SpillManager::spill_to_make_headroom ( std::int64_t  headroom = 0)

Attempts to free up memory by spilling data until the requested headroom is available.

This method checks the currently available memory and, if insufficient, triggers spilling mechanisms to free up space. Spilling is performed in order of the function priorities until the required headroom is reached or no more spilling is possible.

Parameters
headroomThe target amount of headroom (in bytes). A negative headroom is allowed and can be used to only trigger spilling when the available memory becomes negative (as reported by the memory resource).
Returns
The actual amount of memory spilled (in bytes), which may be less than requested if there is insufficient spillable data, but may also be more or equal to requested depending on the sizes of spillable data buffers.

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