Thrill  0.1
byte_block.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/data/byte_block.cpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015-2018 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
13 #include <thrill/data/file.hpp>
14 #include <thrill/mem/pool.hpp>
15 
17 
18 #include <sstream>
19 #include <string>
20 
21 namespace thrill {
22 namespace data {
23 
24 size_t start_block_size = 4 * 1024;
25 size_t default_block_size = 2 * 1024 * 1024;
26 
28 
29 ByteBlock::ByteBlock(BlockPool* block_pool, Byte* data, size_t size)
30  : data_(data), size_(size),
31  block_pool_(block_pool),
32  pin_count_(block_pool_->workers_per_host())
33 { }
34 
36  BlockPool* block_pool, const foxxll::file_ptr& ext_file,
37  int64_t offset, size_t size)
38  : data_(nullptr), size_(size),
39  block_pool_(block_pool),
40  pin_count_(block_pool_->workers_per_host()),
41  em_bid_(ext_file.get(), offset, size),
42  ext_file_(ext_file)
43 { }
44 
46  sLOG << "ByteBlock[" << bb << "]::deleter()"
47  << "pin_count_" << bb->pin_count_str();
48  assert(bb->total_pins_ == 0);
49  assert(bb->reference_count() == 0);
50 
51  // call BlockPool's DestroyBlock() to de-register ByteBlock and free data
52  assert(bb->block_pool_);
53  bb->block_pool_->DestroyBlock(bb);
54 
55  sLOG << "ByteBlock[ " << bb << "]::destroy()";
56  mem::GPool().destroy(bb);
57 }
58 
60  return operator () (const_cast<ByteBlock*>(bb));
61 }
62 
64  return "[" + tlx::join(',', pin_count_) + "]";
65 }
66 
67 void ByteBlock::IncPinCount(size_t local_worker_id) {
68  return block_pool_->IncBlockPinCount(this, local_worker_id);
69 }
70 
71 void ByteBlock::DecPinCount(size_t local_worker_id) {
72  return block_pool_->DecBlockPinCount(this, local_worker_id);
73 }
74 
75 void ByteBlock::OnWriteComplete(foxxll::request* req, bool success) {
76  return block_pool_->OnWriteComplete(this, req, success);
77 }
78 
79 std::ostream& operator << (std::ostream& os, const ByteBlock& b) {
80  os << "[ByteBlock" << " " << &b
81  << " data_=" << static_cast<const void*>(b.data_)
82  << " size_=" << b.size_
83  << " block_pool_=" << b.block_pool_
84  << " total_pins_=" << b.total_pins_
85  << " ext_file_=" << b.ext_file_;
86  return os << "]";
87 }
88 
89 } // namespace data
90 } // namespace thrill
91 
92 /******************************************************************************/
#define sLOG
Default logging method: output if the local debug variable is true.
Definition: logger.hpp:34
std::vector< size_t, mem::GPoolAllocator< size_t > > pin_count_
counts the number of pins in this block per thread_id.
Definition: byte_block.hpp:125
size_t size() const
the block size
Definition: byte_block.hpp:84
void OnWriteComplete(foxxll::request *req, bool success)
forwarded to block_pool_
Definition: byte_block.cpp:75
friend std::ostream & operator<<(std::ostream &os, const ByteBlock &b)
Definition: byte_block.cpp:79
void OnWriteComplete(ByteBlock *block_ptr, foxxll::request *req, bool success)
callback for async write of blocks during eviction
size_t default_block_size
default size of blocks in File, Channel, BlockQueue, etc.
Definition: byte_block.cpp:25
void DecBlockPinCount(ByteBlock *block_ptr, size_t local_worker_id)
Decrement a ByteBlock&#39;s pin count and possibly unpin it.
Definition: block_pool.cpp:818
BlockPool * block_pool_
reference to BlockPool for deletion.
Definition: byte_block.hpp:122
void IncPinCount(size_t local_worker_id)
increment pin count, must be >= 1 before.
Definition: byte_block.cpp:67
static ssize_t get(const CounterType &a)
void DestroyBlock(ByteBlock *block_ptr)
Destroys the block. Called by ByteBlockPtr&#39;s deleter.
Definition: block_pool.cpp:939
void IncBlockPinCount(ByteBlock *block_ptr, size_t local_worker_id)
Increment a ByteBlock&#39;s pin count, requires the pin count to be > 0.
Definition: block_pool.cpp:796
std::string pin_count_str() const
return string list of pin_counts
Definition: byte_block.cpp:63
void operator()(ByteBlock *bb) const
Definition: byte_block.cpp:45
foxxll::BID< 0 > em_bid_
Definition: byte_block.hpp:133
ByteBlock()=delete
No default construction of Byteblock.
void destroy(Type *t)
Destroy and deallocate a single item of given Type.
Definition: pool.hpp:112
foxxll::file_ptr ext_file_
Definition: byte_block.hpp:137
size_t start_block_size
starting size of blocks in BlockWriter.
Definition: byte_block.cpp:24
const size_t size_
the allocated size of the buffer in bytes
Definition: byte_block.hpp:119
Pool & GPool()
singleton instance of global pool for I/O data structures
Definition: pool.cpp:26
uint8_t Byte
type of underlying memory area
Definition: byte_block.hpp:37
Pool to allocate, keep, swap out/in, and free all ByteBlocks on the host.
Definition: block_pool.hpp:42
A ByteBlock is the basic storage units of containers like File, BlockQueue, etc.
Definition: byte_block.hpp:51
size_t reference_count() const noexcept
Return the number of references to this object (for debugging)
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
High-performance smart pointer used as a wrapping reference counting pointer.
static size_t default_prefetch_size_
Definition: file.hpp:66
Request object encapsulating basic properties like file and offset.
Definition: request.hpp:49
std::string join(char glue, const std::vector< std::string > &parts)
Join a vector of strings by some glue character between each pair from the sequence.
Definition: join.cpp:16
void DecPinCount(size_t local_worker_id)
decrement pin count, possibly signal block pool that if it reaches zero.
Definition: byte_block.cpp:71