Skip to content

Commit

Permalink
add new multi-threaded disk I/O subsystem using preadv and pwritev
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Oct 26, 2024
1 parent baba7ff commit 264c66a
Show file tree
Hide file tree
Showing 43 changed files with 4,492 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ set(libtorrent_aux_include_files
disable_warnings_pop.hpp
disable_warnings_push.hpp
disk_buffer_pool.hpp
disk_cache.hpp
visit_block_iovecs.hpp
disk_completed_queue.hpp
mmap_disk_job.hpp
disk_job.hpp
Expand Down Expand Up @@ -225,6 +227,7 @@ set(libtorrent_aux_include_files
portmap.hpp
posix_part_file.hpp
posix_storage.hpp
pread_disk_job.hpp
proxy_base.hpp
proxy_settings.hpp
puff.hpp
Expand Down Expand Up @@ -326,6 +329,7 @@ set(sources
disabled_disk_io.cpp
disk_buffer_holder.cpp
disk_buffer_pool.cpp
disk_cache.cpp
disk_completed_queue.cpp
disk_io_thread_pool.cpp
disk_job_fence.cpp
Expand Down Expand Up @@ -383,6 +387,8 @@ set(sources
posix_disk_io.cpp
posix_part_file.cpp
posix_storage.cpp
pread_disk_io.cpp
pread_storage.cpp
proxy_base.cpp
proxy_settings.cpp
puff.cpp
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2.1.0 not released

* add a multi-threaded, pread()-based, disk I/O backend (pread_disk_io)
* try harder to bind TCP and UDP sockets to the same port
* made disk_interface's status_t type a flags type
* optimize resume data format to use less space
Expand Down
3 changes: 3 additions & 0 deletions Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ SOURCES =
directory
disk_buffer_holder
disk_buffer_pool
disk_cache
disk_completed_queue
disk_io_thread_pool
disabled_disk_io
Expand Down Expand Up @@ -910,6 +911,8 @@ SOURCES =
mmap
mmap_disk_io
mmap_storage
pread_disk_io
pread_storage
posix_disk_io
posix_part_file
posix_storage
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ SOURCES = \
disabled_disk_io.cpp \
disk_buffer_holder.cpp \
disk_buffer_pool.cpp \
disk_cache.cpp \
disk_completed_queue.cpp \
disk_io_thread_pool.cpp \
disk_job_fence.cpp \
Expand Down Expand Up @@ -381,6 +382,8 @@ SOURCES = \
posix_disk_io.cpp \
posix_part_file.cpp \
posix_storage.cpp \
pread_disk_io.cpp \
pread_storage.cpp \
proxy_base.cpp \
proxy_settings.cpp \
puff.cpp \
Expand Down Expand Up @@ -497,6 +500,7 @@ HEADERS = \
piece_block.hpp \
portmap.hpp \
posix_disk_io.hpp \
pread_disk_io.hpp \
read_resume_data.hpp \
session.hpp \
session_handle.hpp \
Expand Down Expand Up @@ -561,6 +565,8 @@ HEADERS = \
aux_/disable_warnings_pop.hpp \
aux_/disable_warnings_push.hpp \
aux_/disk_buffer_pool.hpp \
aux_/disk_cache.hpp \
aux_/visit_block_iovecs.hpp \
aux_/disk_completed_queue.hpp \
aux_/disk_io_thread_pool.hpp \
aux_/disk_job_fence.hpp \
Expand Down Expand Up @@ -627,6 +633,8 @@ HEADERS = \
aux_/portmap.hpp \
aux_/posix_part_file.hpp \
aux_/posix_storage.hpp \
aux_/pread_disk_job.hpp \
aux_/pread_storage.hpp \
aux_/proxy_base.hpp \
aux_/proxy_settings.hpp \
aux_/puff.hpp \
Expand Down Expand Up @@ -892,6 +900,8 @@ TEST_SOURCES = \
test_dht.cpp \
test_dht_storage.cpp \
test_direct_dht.cpp \
test_disk_cache.cpp \
test_disk_io.cpp \
test_dos_blocker.cpp \
test_ed25519.cpp \
test_enum_net.cpp \
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/src/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <libtorrent/mmap_disk_io.hpp>
#include <libtorrent/posix_disk_io.hpp>
#include <libtorrent/pread_disk_io.hpp>

namespace boost
{
Expand Down Expand Up @@ -882,6 +883,8 @@ namespace
#endif
if (disk_io == "posix_disk_io_constructor")
s.disk_io_constructor = &lt::posix_disk_io_constructor;
else if (disk_io == "pread_disk_io_constructor")
s.disk_io_constructor = &lt::pread_disk_io_constructor;
else
s.disk_io_constructor = &lt::default_disk_io_constructor;
}
Expand Down
7 changes: 6 additions & 1 deletion examples/client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ see LICENSE file.

#include "libtorrent/mmap_disk_io.hpp"
#include "libtorrent/posix_disk_io.hpp"
#include "libtorrent/pread_disk_io.hpp"
#include "libtorrent/disabled_disk_io.hpp"

#include "torrent_view.hpp"
Expand Down Expand Up @@ -1347,7 +1348,7 @@ CLIENT OPTIONS
-O print session stats counters to the log
-1 exit on first torrent completing (useful for benchmarks)
-i <disk-io> specify which disk I/O back-end to use. One of:
mmap, posix, disabled
mmap, posix, pread, disabled
)"
#ifdef TORRENT_UTP_LOG_ENABLE
R"(
Expand Down Expand Up @@ -1561,6 +1562,10 @@ int main(int argc, char* argv[])
#endif
if (arg == "posix"_sv)
params.disk_io_constructor = lt::posix_disk_io_constructor;
#if TORRENT_HAVE_PREAD || defined TORRENT_WINDOWS
else if (arg == "pread"_sv)
params.disk_io_constructor = lt::pread_disk_io_constructor;
#endif
else if (arg == "disabled"_sv)
params.disk_io_constructor = lt::disabled_disk_io_constructor;
else
Expand Down
9 changes: 7 additions & 2 deletions include/libtorrent/aux_/debug_disk_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ see LICENSE file.
#include <string>
#include <sstream>
#include <unordered_map>
#include <thread>

#include "libtorrent/aux_/disk_job.hpp"
#include "libtorrent/disk_interface.hpp"
Expand Down Expand Up @@ -81,18 +82,22 @@ inline std::string print_job(aux::disk_job const& j)
}

void operator()(job::file_priority const& j) const {
m_ss << "file-priority( num-files:" << j.prio.size() << " )";
m_ss << "file-priority( num-files: " << j.prio.size() << " )";
}

void operator()(job::clear_piece const& j) const {
m_ss << "clear-piece( piece:" << j.piece << " )";
m_ss << "clear-piece( piece: " << j.piece << " )";
}

void operator()(job::partial_read const& j) const {
m_ss << "partial-read( piece: " << j.piece << " offset: " << j.offset
<< " buf-offset: " << j.buffer_offset << " size: " << j.buffer_size << " )";
}

void operator()(job::kick_hasher const& j) const {
m_ss << "kick-hasher( piece: " << j.piece << " )";
}

private:
std::stringstream& m_ss;
};
Expand Down
9 changes: 6 additions & 3 deletions include/libtorrent/aux_/disk_buffer_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ see LICENSE file.
#include <mutex>
#include <functional>
#include <memory>
#include <optional>

#include "libtorrent/io_context.hpp"
#include "libtorrent/span.hpp"
Expand Down Expand Up @@ -54,6 +55,8 @@ namespace aux {
return m_in_use;
}

std::optional<int> flush_request() const;

void set_settings(settings_interface const& sett);

private:
Expand All @@ -67,10 +70,10 @@ namespace aux {
// cache size limit
int m_max_use;

// if we have exceeded the limit, we won't start
// allowing allocations again until we drop below
// this low watermark
// if we have exceeded the high watermark we start flushing blocks to
// disk until we're below the low watermark.
int m_low_watermark;
int m_high_watermark;

// if we exceed the max number of buffers, we start
// adding up callbacks to this queue. Once the number
Expand Down
Loading

0 comments on commit 264c66a

Please sign in to comment.