Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Sep 3, 2023
1 parent a815617 commit fa0ee17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
17 changes: 10 additions & 7 deletions include/libtorrent/aux_/disk_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ struct cached_block_entry
if (write_job != nullptr)
{
TORRENT_ASSERT(write_job->get_type() == aux::job_action_t::write);
auto const& buf = std::get<job::write>(write_job->action).buf;
return {buf.data(), buf.size()};
auto const& job = std::get<job::write>(write_job->action);
return {job.buf.data(), job.buffer_size};
}
return {nullptr, 0};
}
Expand All @@ -89,6 +89,8 @@ struct cached_block_entry
// TODO: save space by just storing the buffer pointer here. The
// cached_piece_entry could hold the pointer to the buffer pool to be able
// to free these on destruction
// we would still need to save the *size* of the block, to support the
// shorter last block of a torrent
disk_buffer_holder buf_holder;
pread_disk_job* write_job = nullptr;

Expand All @@ -115,6 +117,7 @@ struct cached_piece_entry
piece_location piece;

// this is set to true when the piece has been populated with all blocks
// and the piece hash has been computed
bool ready_to_flush = false;

// when this is true, there is a thread currently hashing blocks and
Expand All @@ -130,7 +133,7 @@ struct cached_piece_entry
bool piece_hash_returned = false;

// this indicates that this piece belongs to a v2 torrent, and it has the
// block_hash member if cached_block_entry and we need to compute the block
// block_hash member of cached_block_entry and we need to compute the block
// hashes as well
bool v2_hashes = false;

Expand Down Expand Up @@ -383,6 +386,8 @@ struct disk_cache
auto i = view.find(loc);
if (i == view.end())
{
//#error this computation is not right for v2 torrents. it will make v2 hashes computed incorrectly
//#error we don't know what the block size actually is here. If the piece size is less than 16 kiB, this computation is incorrect
int const blocks_in_piece = (write_job->storage->files().piece_size(loc.piece) + default_block_size - 1) / default_block_size;
cached_piece_entry pe(loc, blocks_in_piece);
pe.v2_hashes = write_job->storage->files().v2();
Expand Down Expand Up @@ -458,8 +463,6 @@ struct disk_cache
}

// this should be called from a hasher thread
// #error this is not hooked up. we need a new job type to post to the
// hasher_threads
void kick_hasher(piece_location const& loc, jobqueue_t& completed_jobs)
{
std::unique_lock<std::mutex> l(m_mutex);
Expand Down Expand Up @@ -1028,8 +1031,8 @@ struct disk_cache
// if (idx < piece_entry.hasher_cursor)
// TORRENT_ASSERT(!be.buf_holder);

if (piece_entry.ready_to_flush)
TORRENT_ASSERT(be.write_job != nullptr);
// if (piece_entry.ready_to_flush)
// TORRENT_ASSERT(be.write_job != nullptr);
++idx;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pread_disk_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> pread_disk_io_constructor(
TORRENT_ASSERT(valid_flags(flags));
bool exceeded = false;
disk_buffer_holder buffer(m_buffer_pool, m_buffer_pool.allocate_buffer(
exceeded, o, "receive buffer"), default_block_size);
exceeded, o, "receive buffer"), r.length);
if (!buffer) aux::throw_ex<std::bad_alloc>();
std::memcpy(buffer.data(), buf, aux::numeric_cast<std::size_t>(r.length));

Expand Down
13 changes: 8 additions & 5 deletions tools/disk_io_stress_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ int run_test(test_case const& t)
|| !blocks_to_read.empty()
|| outstanding > 0)
{
// printf("o: %d w: %d r: %d\r"
// , outstanding
// , int(blocks_to_write.size())
// , int(blocks_to_read.size()));
// fflush(stdout);
if ((job_counter & 0x1fff) == 0)
{
printf("o: %d w: %d r: %d\r"
, outstanding
, int(blocks_to_write.size())
, int(blocks_to_read.size()));
fflush(stdout);
}
for (int i = 0; i < t.read_multiplier; ++i)
{
if (!blocks_to_read.empty() && outstanding < t.queue_size)
Expand Down

0 comments on commit fa0ee17

Please sign in to comment.