15 #ifndef FOXXLL_MNG_BLOCK_MANAGER_HEADER 16 #define FOXXLL_MNG_BLOCK_MANAGER_HEADER 27 #include <foxxll/config.hpp> 56 constexpr
static bool debug =
false;
73 template <
typename DiskAssignFunctor,
typename BIDIterator>
75 const DiskAssignFunctor& functor,
76 BIDIterator bid_begin, BIDIterator bid_end,
77 size_t alloc_offset = 0);
90 template <
typename DiskAssignFunctor,
size_t BlockSize>
94 new_blocks(functor, &bid, std::next(&bid, 1), alloc_offset);
102 template <
typename BIDIterator>
104 const BIDIterator& bid_end);
108 template <
size_t BlockSize>
164 template <
typename DiskAssignFunctor,
typename BIDIterator>
166 const DiskAssignFunctor& functor,
167 BIDIterator bid_begin, BIDIterator bid_end,
170 std::unique_lock<std::mutex> lock(
mutex_);
172 using BIDType =
typename std::iterator_traits<BIDIterator>::value_type;
178 std::vector<std::vector<size_t> > disk_out(
ndisks_);
183 size_t bid_size =
static_cast<size_t>(bid_end - bid_begin);
185 BIDIterator bid = bid_begin;
186 for (
size_t i = 0; i < bid_size; ++i, ++bid)
188 size_t disk_id = functor(alloc_offset + i);
191 disk_bytes[disk_id] + bid->
size 196 for (
size_t adv = 1; adv <
ndisks_; ++adv)
198 size_t try_disk_id = (disk_id + adv) % ndisks_;
200 disk_bytes[try_disk_id] + bid->
size 203 disk_id = try_disk_id;
212 disk_blocks[disk_id]++;
213 disk_bytes[disk_id] += bid->
size;
214 disk_out[disk_id].push_back(i);
221 for (
size_t d = 0; d <
ndisks_; ++d)
223 if (disk_blocks[d] == 0)
continue;
224 bids.
resize(disk_blocks[d]);
226 std::vector<size_t>& bid_perm = disk_out[d];
229 for (
size_t i = 0; i < disk_blocks[d]; ++i)
230 bids[i] = bid_begin[bid_perm[i]];
236 for (
size_t i = 0; i < disk_blocks[d]; ++i) {
240 bid_begin[bid_perm[i]] = bids[i];
250 template <
size_t BlockSize>
253 std::unique_lock<std::mutex> lock(
mutex_);
256 TLX_LOG <<
"Warning: invalid block to be deleted.";
263 assert(bid.
storage->get_allocator_id() >= 0);
270 template <
typename BIDIterator>
272 const BIDIterator& bid_begin,
const BIDIterator& bid_end)
274 for (BIDIterator it = bid_begin; it != bid_end; ++it)
282 #endif // !FOXXLL_MNG_BLOCK_MANAGER_HEADER void new_blocks(const DiskAssignFunctor &functor, BIDIterator bid_begin, BIDIterator bid_end, size_t alloc_offset=0)
Allocates new blocks.
std::mutex mutex_
protect internal data structures
uint64_t free_bytes() const
Return total number of free bytes.
static uint_pair max()
return an uint_pair instance containing the largest value possible
void resize(size_type new_size)
resize the array to contain exactly new_size items
uint64_t current_allocation_
currently allocated bytes
void delete_blocks(const BIDIterator &bid_begin, const BIDIterator &bid_end)
Simpler non-growing vector without initialization.
external_size_type offset
offset within the file of the block (uint64_t)
void delete_block(const BID< BlockSize > &bid)
static constexpr bool debug
uint64_t current_allocation() const
return currently allocated bytes
tlx::simple_vector< disk_block_allocator * > block_allocators_
one block allocator per disk
uint64_t total_allocation_
total requested allocation in bytes
void fill(const value_type &v=value_type()) noexcept
Zero the whole array content.
uint64_t maximum_allocation() const
return maximum number of bytes allocated during program run.
uint64_t total_bytes() const
return total number of bytes available in all disks
size_type size() const noexcept
return number of items in vector
size_t ndisks_
number of managed disks
uint64_t total_allocation() const
return total requested allocation in bytes
#define TLX_LOGC(cond)
Explicitly specify the condition for logging.
block_manager()
private construction from singleton
void new_block(const DiskAssignFunctor &functor, BID< BlockSize > &bid, size_t alloc_offset=0)
Allocates a new block according to the strategy given by functor and stores the block identifier to b...
tlx::simple_vector< file_ptr > disk_files_
vector of opened disk files
file * storage
pointer to the file of the block
uint64_t maximum_allocation_
maximum number of bytes allocated during program run.
static constexpr bool verbose_block_life_cycle
log creation and destruction of blocks
static constexpr size_t size
Block size.
#define TLX_LOG
Default logging method: output if the local debug variable is true.