Thrill  0.1
BlockPool Class Reference

Detailed Description

Pool to allocate, keep, swap out/in, and free all ByteBlocks on the host.

Starts a backgroud thread which is responsible for disk I/O

Definition at line 42 of file block_pool.hpp.

+ Inheritance diagram for BlockPool:
+ Collaboration diagram for BlockPool:

#include <block_pool.hpp>

Public Member Functions

 BlockPool (size_t workers_per_host=1)
 Creates a simple BlockPool for tests: allows only one thread, enforces no memory limitations, never swaps to disk. More...
 
 BlockPool (const BlockPool &)=delete
 non-copyable: delete copy-constructor More...
 
 BlockPool (size_t soft_ram_limit, size_t hard_ram_limit, common::JsonLogger *logger, mem::Manager *mem_manager, size_t workers_per_host)
 Creates a BlockPool with given memory constrains. More...
 
 ~BlockPool ()
 Checks that all blocks were freed. More...
 
void AdviseFree (size_t size)
 
PinnedByteBlockPtr AllocateByteBlock (size_t size, size_t local_worker_id)
 
void DecBlockPinCount (ByteBlock *block_ptr, size_t local_worker_id)
 Decrement a ByteBlock's pin count and possibly unpin it. More...
 
void DestroyBlock (ByteBlock *block_ptr)
 Destroys the block. Called by ByteBlockPtr's deleter. More...
 
void EvictBlock (ByteBlock *block_ptr)
 
foxxll::request_ptr EvictBlockLRU ()
 
foxxll::request_ptr GetAnyWriting ()
 Return any currently being written block (for waiting on completion) More...
 
void IncBlockPinCount (ByteBlock *block_ptr, size_t local_worker_id)
 Increment a ByteBlock's pin count, requires the pin count to be > 0. More...
 
common::JsonLoggerlogger ()
 Returns logger_. More...
 
ByteBlockPtr MapExternalBlock (const foxxll::file_ptr &file, uint64_t offset, size_t size)
 
std::pair< size_t, size_t > MaxMergeDegreePrefetch (size_t num_files)
 
size_t next_file_id ()
 return next unique File id More...
 
BlockPooloperator= (const BlockPool &)=delete
 non-copyable: delete assignment operator More...
 
PinRequestPtr PinBlock (const Block &block, size_t local_worker_id)
 Pins a block by swapping it in if required. More...
 
void ReleaseInternalMemory (size_t size)
 
void RequestInternalMemory (size_t size)
 
size_t workers_per_host () const
 return number of workers per host More...
 
Block Statistics
size_t hard_ram_limit () noexcept
 Hard limit on amount of memory used for ByteBlock. More...
 
size_t total_blocks () noexcept
 Total number of allocated blocks of this block pool. More...
 
size_t total_bytes () noexcept
 Total number of bytes allocated in blocks of this block pool. More...
 
size_t max_total_bytes () noexcept
 Maximum total number of bytes allocated in blocks of this block pool. More...
 
size_t pinned_blocks () noexcept
 Total number of pinned blocks of this block pool. More...
 
size_t unpinned_blocks () noexcept
 Total number of unpinned blocks in memory of this block pool. More...
 
size_t writing_blocks () noexcept
 Total number of blocks currently begin written. More...
 
size_t swapped_blocks () noexcept
 Total number of swapped blocks. More...
 
size_t reading_blocks () noexcept
 Total number of blocks currently begin read from EM. More...
 
Methods for ProfileTask
void RunTask (const std::chrono::steady_clock::time_point &tp) final
 method called by ProfileThread. More...
 
- Public Member Functions inherited from ProfileTask
virtual ~ProfileTask ()
 virtual destructor More...
 

Private Member Functions

void IntIncBlockPinCount (ByteBlock *block_ptr, size_t local_worker_id)
 Increment a ByteBlock's pin count - without locking the mutex. More...
 
void OnReadComplete (PinRequest *read, foxxll::request *req, bool success)
 callback for async read of blocks for pin requests More...
 
void OnWriteComplete (ByteBlock *block_ptr, foxxll::request *req, bool success)
 callback for async write of blocks during eviction More...
 

Private Attributes

std::condition_variable cv_read_complete_
 
std::unique_ptr< Data > d_
 pimpl data structure More...
 
common::JsonLogger logger_
 reference to HostContext's logger or a null sink More...
 
mem::Manager mem_manager_
 local Manager counting only ByteBlock allocations in internal memory. More...
 
std::mutex mutex_
 locked before internal state is changed More...
 
size_t workers_per_host_
 number of workers per host More...
 

Static Private Attributes

static constexpr bool debug = false
 

Friends

std::ostream & operator<< (std::ostream &os, const PinCount &p)
 make ostream-able More...
 

Constructor & Destructor Documentation

◆ BlockPool() [1/3]

BlockPool ( size_t  workers_per_host = 1)
explicit

Creates a simple BlockPool for tests: allows only one thread, enforces no memory limitations, never swaps to disk.

Definition at line 373 of file block_pool.cpp.

◆ BlockPool() [2/3]

BlockPool ( const BlockPool )
delete

non-copyable: delete copy-constructor

◆ BlockPool() [3/3]

BlockPool ( size_t  soft_ram_limit,
size_t  hard_ram_limit,
common::JsonLogger logger,
mem::Manager mem_manager,
size_t  workers_per_host 
)

Creates a BlockPool with given memory constrains.

Parameters
soft_ram_limitlimit (bytes) that causes the BlockPool to swap out victim pages. Enter 0 for no soft limit
hard_ram_limitlimit (bytes) that causes the BlockPool to block new allocations until some blocks are free'd. Enter 0 for no hard limit.
loggerPointer to logger for output.
mem_managerMemory Manager that tracks amount of RAM allocated. the BlockPool will create a child manager.
workers_per_hostnumber of workers on this host.

Definition at line 376 of file block_pool.cpp.

References BlockPool::d_, die_unless, singleton< stats >::get_instance(), BlockPool::hard_ram_limit(), BlockPool::logger_, and thrill::data::OurNewHandler().

◆ ~BlockPool()

~BlockPool ( )

Checks that all blocks were freed.

Definition at line 404 of file block_pool.cpp.

References BlockPool::d_, die_unequal, die_unless, LOGC, BlockPool::logger_, and BlockPool::mutex_.

Member Function Documentation

◆ AdviseFree()

void AdviseFree ( size_t  size)

Advice the block pool to free up memory in anticipation of a large future request.

Definition at line 1170 of file block_pool.cpp.

References BlockPool::d_, LOGC, and BlockPool::mutex_.

Referenced by BlockPool::logger(), and JoinNode< ValueType, FirstDIA, SecondDIA, KeyExtractor1, KeyExtractor2, JoinFunction, HashFunction, UseLocationDetection >::SortAndWriteToFile().

◆ AllocateByteBlock()

PinnedByteBlockPtr AllocateByteBlock ( size_t  size,
size_t  local_worker_id 
)

Allocates a byte block with the request size. May block this thread if the hard memory limit is reached, until memory is freed by another thread. The returned Block is allocated in RAM, but with a zero pin count.

Definition at line 484 of file block_pool.cpp.

References BlockPool::d_, die, CountingPtr< Type, Deleter >::get(), thrill::mem::GPool(), BlockPool::IntIncBlockPinCount(), tlx::is_power_of_two(), LOGC, max(), BlockPool::mutex_, THRILL_DEFAULT_ALIGN, and BlockPool::workers_per_host_.

Referenced by BlockSink::AllocateByteBlock(), BlockPool::logger(), ReadBinaryNode< ValueType >::VfsFileBlockSource::NextBlock(), and Multiplexer::OnMultiplexerHeader().

◆ DecBlockPinCount()

void DecBlockPinCount ( ByteBlock block_ptr,
size_t  local_worker_id 
)

◆ DestroyBlock()

void DestroyBlock ( ByteBlock block_ptr)

Destroys the block. Called by ByteBlockPtr's deleter.

Definition at line 939 of file block_pool.cpp.

References BlockPool::d_, die_unless, LOGC, BlockPool::mutex_, and sLOGC.

Referenced by BlockPool::logger(), and ByteBlock::Deleter::operator()().

◆ EvictBlock()

void EvictBlock ( ByteBlock block_ptr)

Evict a block into external memory. The block must be unpinned and not swapped.

Definition at line 1210 of file block_pool.cpp.

References BlockPool::d_, die_unless, ByteBlock::in_memory(), BlockPool::mutex_, and ByteBlock::size().

Referenced by BlockPool::logger().

◆ EvictBlockLRU()

foxxll::request_ptr EvictBlockLRU ( )

Evict a Block from the LRU chain into external memory. This can return nullptr if no blocks available, or if the Block was not dirty.

Definition at line 1228 of file block_pool.cpp.

References file::awrite(), BlockPool::ByteBlock, BlockPool::d_, ByteBlock::data_, die_unless, ByteBlock::em_bid_, ByteBlock::ext_file_, LOGC, BlockPool::mutex_, BID< 0 >::offset, ByteBlock::OnWriteComplete(), ByteBlock::size(), BID< 0 >::size, sLOGC, and BID< 0 >::storage.

Referenced by BlockPool::logger().

◆ GetAnyWriting()

foxxll::request_ptr GetAnyWriting ( )

Return any currently being written block (for waiting on completion)

Definition at line 1222 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ hard_ram_limit()

size_t hard_ram_limit ( )
noexcept

◆ IncBlockPinCount()

void IncBlockPinCount ( ByteBlock block_ptr,
size_t  local_worker_id 
)

Increment a ByteBlock's pin count, requires the pin count to be > 0.

Definition at line 796 of file block_pool.cpp.

References die_unless, BlockPool::IntIncBlockPinCount(), BlockPool::mutex_, ByteBlock::pin_count_, and BlockPool::workers_per_host_.

Referenced by ByteBlock::IncPinCount(), and BlockPool::logger().

◆ IntIncBlockPinCount()

void IntIncBlockPinCount ( ByteBlock block_ptr,
size_t  local_worker_id 
)
private

◆ logger()

◆ MapExternalBlock()

ByteBlockPtr MapExternalBlock ( const foxxll::file_ptr file,
uint64_t  offset,
size_t  size 
)

Allocate a byte block from an external file, used to directly map system files to data::File.

Definition at line 528 of file block_pool.cpp.

References BlockPool::d_, CountingPtr< Type, Deleter >::get(), thrill::mem::GPool(), LOGC, max(), and BlockPool::mutex_.

Referenced by BlockPool::logger(), and ReadBinaryNode< ValueType >::ReadBinaryNode().

◆ max_total_bytes()

size_t max_total_bytes ( )
noexcept

Maximum total number of bytes allocated in blocks of this block pool.

Definition at line 896 of file block_pool.cpp.

References BlockPool::d_, LOG, and BlockPool::mutex_.

Referenced by Context::Launch(), and BlockPool::logger().

◆ MaxMergeDegreePrefetch()

◆ next_file_id()

size_t next_file_id ( )

return next unique File id

Definition at line 1398 of file block_pool.cpp.

References BlockPool::d_.

Referenced by BlockPool::logger().

◆ OnReadComplete()

◆ OnWriteComplete()

void OnWriteComplete ( ByteBlock block_ptr,
foxxll::request req,
bool  success 
)
private

◆ operator=()

BlockPool& operator= ( const BlockPool )
delete

non-copyable: delete assignment operator

Referenced by BlockPoolMemoryHolder::BlockPoolMemoryHolder().

◆ PinBlock()

◆ pinned_blocks()

size_t pinned_blocks ( )
noexcept

Total number of pinned blocks of this block pool.

Definition at line 914 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ reading_blocks()

size_t reading_blocks ( )
noexcept

Total number of blocks currently begin read from EM.

Definition at line 934 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ ReleaseInternalMemory()

void ReleaseInternalMemory ( size_t  size)

Updates the memory manager for the internal memory, wakes up waiting BlockPool::RequestInternalMemory calls

Definition at line 1192 of file block_pool.cpp.

References BlockPool::d_, die_unless, LOGC, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ RequestInternalMemory()

void RequestInternalMemory ( size_t  size)

Updates the memory manager for internal memory. If the hard limit is reached, the call is blocked intil memory is free'd

Definition at line 1083 of file block_pool.cpp.

References BlockPool::d_, LOG1, LOGC, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ RunTask()

void RunTask ( const std::chrono::steady_clock::time_point &  tp)
finalvirtual

◆ swapped_blocks()

size_t swapped_blocks ( )
noexcept

Total number of swapped blocks.

Definition at line 929 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ total_blocks()

size_t total_blocks ( )
noexcept

Total number of allocated blocks of this block pool.

Definition at line 867 of file block_pool.cpp.

References BlockPool::d_, LOG, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ total_bytes()

size_t total_bytes ( )
noexcept

Total number of bytes allocated in blocks of this block pool.

Definition at line 891 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ unpinned_blocks()

size_t unpinned_blocks ( )
noexcept

Total number of unpinned blocks in memory of this block pool.

Definition at line 919 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

◆ workers_per_host()

size_t workers_per_host ( ) const
inline

return number of workers per host

Definition at line 82 of file block_pool.hpp.

References BlockPool::workers_per_host_.

Referenced by BlockQueue::BlockQueue(), thrill::data::OurNewHandler(), and BlockSink::workers_per_host().

◆ writing_blocks()

size_t writing_blocks ( )
noexcept

Total number of blocks currently begin written.

Definition at line 924 of file block_pool.cpp.

References BlockPool::d_, and BlockPool::mutex_.

Referenced by BlockPool::logger().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const PinCount &  p 
)
friend

make ostream-able

Definition at line 216 of file block_pool.cpp.

Member Data Documentation

◆ cv_read_complete_

std::condition_variable cv_read_complete_
private

For waiting on read/pin requests to finish (we use only one condition_variable for all read requests).

Definition at line 185 of file block_pool.hpp.

Referenced by BlockPool::OnReadComplete().

◆ d_

◆ debug

constexpr bool debug = false
staticprivate

Definition at line 44 of file block_pool.hpp.

◆ logger_

common::JsonLogger logger_
private

reference to HostContext's logger or a null sink

Definition at line 188 of file block_pool.hpp.

Referenced by BlockPool::BlockPool(), BlockPool::logger(), BlockPool::RunTask(), and BlockPool::~BlockPool().

◆ mem_manager_

mem::Manager mem_manager_
private

local Manager counting only ByteBlock allocations in internal memory.

Definition at line 191 of file block_pool.hpp.

◆ mutex_

◆ workers_per_host_


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