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... | |
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.
| 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.
| rapidsmpf::SpillManager::SpillManager | ( | BufferResource * | br, |
| std::optional< Duration > | periodic_spill_check = std::nullopt |
||
| ) |
Constructs a SpillManager instance.
| br | Buffer resource used to retrieve current available memory. |
| periodic_spill_check | Enable 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. |
| 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).
| 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.
| spill_function | The spill function to be added. |
| priority | The priority level of the spill function (higher values indicate higher priority). |
| 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.
| fid | The id of the spill function to be removed. |
| 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.
| amount | The amount of memory (in bytes) to spill. |
| 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.
| headroom | The 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). |