Turi Create  4.0
turi::fileio::fixed_size_cache_manager Class Reference

#include <core/storage/fileio/fixed_size_cache_manager.hpp>

Public Member Functions

cache_id_type get_temp_cache_id (std::string suffix="")
 
std::shared_ptr< cache_blocknew_cache (cache_id_type cache_id)
 
std::shared_ptr< cache_blockget_cache (cache_id_type cache_id)
 
void free (std::shared_ptr< cache_block > block)
 
void clear ()
 
size_t get_cache_utilization ()
 

Detailed Description

A global singleton object managing the allocation/deallocation of cache blocks. The basic mechanism of operation is such:

  • For every new cache block requested:
    • If there is FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE free bytes, a new cache block of FILEIO_INITIAL_CAPACITY_PER_FILE is allocated, where the new cache block is permitted to grow up to FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE. The capacity is not charged as utilization until it is actually used. i.e. utilization is only incremented by FILEIO_INITIAL_CACHE_CAPACITY_PER_FILE. Then as more memory is allocated for the cache, then utilization is incremented again.
    • If there is < FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE free bytes available: The largest cache block is evicted. If there is FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE free bytes, Goto the first case. Otherwise, create a new cache block with all the remaining free bytes.

The relevant constants are thus: FILEIO_MAXIMUM_CACHE_CAPACITY : the maximum total size of all cache blocks FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE : the maximum size of each cache blocks FILEIO_INITIAL_CAPACITY_PER_FILE : the initial size of each cache blocks

Overcommit Behavior

We try our best to maintain cache utilization below the maximum. However, it is possible to exceed maximum cache utilization under certain race conditions since we avoid locking on the cache utilization counter.

Definition at line 179 of file fixed_size_cache_manager.hpp.

Member Function Documentation

◆ clear()

void turi::fileio::fixed_size_cache_manager::clear ( )

Clear all cache blocks in the manager. Reset to initial state.

◆ free()

void turi::fileio::fixed_size_cache_manager::free ( std::shared_ptr< cache_block block)

Free the data in the cache block. Delete the allocated memory or temp file associated with the cache.

NOT thread safe to call on the same block.

◆ get_cache()

std::shared_ptr<cache_block> turi::fileio::fixed_size_cache_manager::get_cache ( cache_id_type  cache_id)

Returns the pointer to the cache_block assocaited with the cache_id, Throws std::out_of_range if the cache_id does not exist.

Thread safe.

◆ get_cache_utilization()

size_t turi::fileio::fixed_size_cache_manager::get_cache_utilization ( )
inline

Returns the amount of memory being used by the caches.

Definition at line 224 of file fixed_size_cache_manager.hpp.

◆ get_temp_cache_id()

cache_id_type turi::fileio::fixed_size_cache_manager::get_temp_cache_id ( std::string  suffix = "")

Returns a temporary cache id that is not yet used by the manager.

◆ new_cache()

std::shared_ptr<cache_block> turi::fileio::fixed_size_cache_manager::new_cache ( cache_id_type  cache_id)

Allocate a new cache block of up to some maximum capcity. If the cache_id already exists, the data will be lost.

Returns a pointer to the cache block. Thread safe.


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