Thrill
0.1
|
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.
#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::JsonLogger & | logger () |
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... | |
BlockPool & | operator= (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... | |
|
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 | ( | 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.
soft_ram_limit | limit (bytes) that causes the BlockPool to swap out victim pages. Enter 0 for no soft limit |
hard_ram_limit | limit (bytes) that causes the BlockPool to block new allocations until some blocks are free'd. Enter 0 for no hard limit. |
logger | Pointer to logger for output. |
mem_manager | Memory Manager that tracks amount of RAM allocated. the BlockPool will create a child manager. |
workers_per_host | number 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 | ( | ) |
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_.
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().
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().
void DecBlockPinCount | ( | ByteBlock * | block_ptr, |
size_t | local_worker_id | ||
) |
Decrement a ByteBlock's pin count and possibly unpin it.
Definition at line 818 of file block_pool.cpp.
References BlockPool::d_, die_unless, LOGC, BlockPool::mutex_, ByteBlock::pin_count(), ByteBlock::pin_count_, ByteBlock::size(), ByteBlock::total_pins_, and BlockPool::workers_per_host_.
Referenced by ByteBlock::DecPinCount(), and BlockPool::logger().
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()().
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().
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().
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().
|
noexcept |
Hard limit on amount of memory used for ByteBlock.
Definition at line 886 of file block_pool.cpp.
References BlockPool::d_, and BlockPool::mutex_.
Referenced by BlockPool::BlockPool(), MixStreamData::GetWriters(), CatStreamData::GetWriters(), BlockPool::logger(), BlockPool::MaxMergeDegreePrefetch(), and Multiplexer::Multiplexer().
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().
|
private |
Increment a ByteBlock's pin count - without locking the mutex.
Definition at line 803 of file block_pool.cpp.
References BlockPool::d_, LOGC, ByteBlock::pin_count_, ByteBlock::total_pins_, and BlockPool::workers_per_host_.
Referenced by BlockPool::AllocateByteBlock(), BlockPool::IncBlockPinCount(), BlockPool::OnReadComplete(), and BlockPool::PinBlock().
|
inline |
Returns logger_.
Definition at line 85 of file block_pool.hpp.
References BlockPool::AdviseFree(), BlockPool::AllocateByteBlock(), BlockPool::DecBlockPinCount(), BlockPool::DestroyBlock(), BlockPool::EvictBlock(), BlockPool::EvictBlockLRU(), BlockPool::GetAnyWriting(), BlockPool::hard_ram_limit(), BlockPool::IncBlockPinCount(), BlockPool::logger_, BlockPool::MapExternalBlock(), BlockPool::max_total_bytes(), BlockPool::MaxMergeDegreePrefetch(), BlockPool::next_file_id(), BlockPool::PinBlock(), BlockPool::pinned_blocks(), BlockPool::reading_blocks(), BlockPool::ReleaseInternalMemory(), BlockPool::RequestInternalMemory(), BlockPool::RunTask(), BlockPool::swapped_blocks(), BlockPool::total_blocks(), BlockPool::total_bytes(), BlockPool::unpinned_blocks(), and BlockPool::writing_blocks().
Referenced by BlockSink::logger(), and Multiplexer::logger().
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().
|
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().
std::pair< size_t, size_t > MaxMergeDegreePrefetch | ( | size_t | num_files | ) |
calculate maximum merging degree from available memory and the number of files. additionally calculate the prefetch size of each File.
Definition at line 703 of file block_pool.cpp.
References thrill::data::default_block_size, BlockPool::hard_ram_limit(), and BlockPool::workers_per_host_.
Referenced by BlockPool::logger(), JoinNode< ValueType, FirstDIA, SecondDIA, KeyExtractor1, KeyExtractor2, JoinFunction, HashFunction, UseLocationDetection >::MakePuller(), JoinNode< ValueType, FirstDIA, SecondDIA, KeyExtractor1, KeyExtractor2, JoinFunction, HashFunction, UseLocationDetection >::MergeFiles(), GroupByNode< ValueType, KeyExtractor, GroupFunction, HashFunction, UseLocationDetection >::PushData(), and SortNode< ValueType, CompareFunction, SortAlgorithm, Stable >::PushData().
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().
|
private |
callback for async read of blocks for pin requests
Definition at line 723 of file block_pool.cpp.
References PinRequest::block_, PinnedBlock::byte_block(), PinRequest::byte_block(), request::check_errors(), BlockPool::cv_read_complete_, BlockPool::d_, die_unless, ByteBlock::em_bid_, ByteBlock::ext_file_, CountingPtr< Type, Deleter >::get(), BlockPool::IntIncBlockPinCount(), PinnedBlock::local_worker_id_, LOGC, BlockPool::mutex_, PinRequest::ready_, request::release_file_reference(), CountingPtr< Type, Deleter >::reset(), ByteBlock::size(), and sLOGC.
|
private |
callback for async write of blocks during eviction
Definition at line 1297 of file block_pool.cpp.
References request::check_errors(), BlockPool::d_, ByteBlock::data_, die_unequal, die_unless, ByteBlock::em_bid_, ByteBlock::ext_file_, ByteBlock::is_deleted(), LOGC, BlockPool::mutex_, ByteBlock::size(), and sLOGC.
Referenced by ByteBlock::OnWriteComplete().
non-copyable: delete assignment operator
Referenced by BlockPoolMemoryHolder::BlockPoolMemoryHolder().
PinRequestPtr PinBlock | ( | const Block & | block, |
size_t | local_worker_id | ||
) |
Pins a block by swapping it in if required.
Definition at line 548 of file block_pool.cpp.
References file::aread(), Block::byte_block(), BlockPool::d_, die_unless, ByteBlock::em_bid_, ByteBlock::ext_file_, CountingPtr< Type, Deleter >::get(), thrill::mem::GPool(), ByteBlock::in_memory(), BlockPool::IntIncBlockPinCount(), LOGC, BlockPool::mutex_, BID< 0 >::offset, PinRequest::OnComplete(), ByteBlock::pin_count_, BlockPool::PinRequest, ByteBlock::size(), BID< 0 >::storage, ByteBlock::total_pins_, and BlockPool::workers_per_host_.
Referenced by BlockPool::logger().
|
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().
|
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().
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().
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().
|
finalvirtual |
method called by ProfileThread.
Implements ProfileTask.
Definition at line 1344 of file block_pool.cpp.
References BlockPool::d_, singleton< stats >::get_instance(), stats_data::get_read_bytes(), stats_data::get_read_count(), stats_data::get_write_bytes(), stats_data::get_write_count(), BlockPool::logger_, and BlockPool::mutex_.
Referenced by BlockPool::logger().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
friend |
make ostream-able
Definition at line 216 of file block_pool.cpp.
|
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().
|
private |
pimpl data structure
Definition at line 203 of file block_pool.hpp.
Referenced by BlockPool::AdviseFree(), BlockPool::AllocateByteBlock(), BlockPool::BlockPool(), BlockPool::DecBlockPinCount(), BlockPool::DestroyBlock(), BlockPool::EvictBlock(), BlockPool::EvictBlockLRU(), BlockPool::GetAnyWriting(), BlockPool::hard_ram_limit(), BlockPool::IntIncBlockPinCount(), BlockPool::MapExternalBlock(), BlockPool::max_total_bytes(), BlockPool::next_file_id(), BlockPool::OnReadComplete(), BlockPool::OnWriteComplete(), BlockPool::PinBlock(), BlockPool::pinned_blocks(), BlockPool::reading_blocks(), BlockPool::ReleaseInternalMemory(), BlockPool::RequestInternalMemory(), BlockPool::RunTask(), BlockPool::swapped_blocks(), BlockPool::total_blocks(), BlockPool::total_bytes(), BlockPool::unpinned_blocks(), BlockPool::writing_blocks(), and BlockPool::~BlockPool().
|
staticprivate |
Definition at line 44 of file block_pool.hpp.
|
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().
|
private |
local Manager counting only ByteBlock allocations in internal memory.
Definition at line 191 of file block_pool.hpp.
|
private |
locked before internal state is changed
Definition at line 181 of file block_pool.hpp.
Referenced by BlockPool::AdviseFree(), BlockPool::AllocateByteBlock(), BlockPool::DecBlockPinCount(), BlockPool::DestroyBlock(), BlockPool::EvictBlock(), BlockPool::EvictBlockLRU(), BlockPool::GetAnyWriting(), BlockPool::hard_ram_limit(), BlockPool::IncBlockPinCount(), BlockPool::MapExternalBlock(), BlockPool::max_total_bytes(), BlockPool::OnReadComplete(), BlockPool::OnWriteComplete(), BlockPool::PinBlock(), BlockPool::pinned_blocks(), BlockPool::reading_blocks(), BlockPool::ReleaseInternalMemory(), BlockPool::RequestInternalMemory(), BlockPool::RunTask(), BlockPool::swapped_blocks(), BlockPool::total_blocks(), BlockPool::total_bytes(), BlockPool::unpinned_blocks(), BlockPool::writing_blocks(), and BlockPool::~BlockPool().
|
private |
number of workers per host
Definition at line 194 of file block_pool.hpp.
Referenced by BlockPool::AllocateByteBlock(), BlockPool::DecBlockPinCount(), BlockPool::IncBlockPinCount(), BlockPool::IntIncBlockPinCount(), BlockPool::MaxMergeDegreePrefetch(), BlockPool::PinBlock(), and BlockPool::workers_per_host().