From b5b34c9ff4e0967488b715618ad8b863af208381 Mon Sep 17 00:00:00 2001 From: Hanabishi <13597663+HanabishiRecca@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:58:35 +0500 Subject: [PATCH] Add "Simple pread/pwrite" disk IO type PR #21300. --- src/base/bittorrent/session.h | 3 ++- src/base/bittorrent/sessionimpl.cpp | 8 ++++++++ src/gui/advancedsettings.cpp | 1 + src/webui/www/private/views/preferences.html | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index b7bed67d4..7e1b9dc6c 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -92,7 +92,8 @@ namespace BitTorrent { Default = 0, MMap = 1, - Posix = 2 + Posix = 2, + SimplePreadPwrite = 3 }; Q_ENUM_NS(DiskIOType) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 5e52b3aa1..1e4e76f2d 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -1638,6 +1638,13 @@ void SessionImpl::initializeNativeSession() #ifdef QBT_USES_LIBTORRENT2 // preserve the same behavior as in earlier libtorrent versions pack.set_bool(lt::settings_pack::enable_set_file_valid_data, true); + + // This is a special case. We use MMap disk IO but tweak it to always fallback to pread/pwrite. + if (diskIOType() == DiskIOType::SimplePreadPwrite) + { + pack.set_int(lt::settings_pack::mmap_file_size_cutoff, std::numeric_limits::max()); + pack.set_int(lt::settings_pack::disk_write_mode, lt::settings_pack::mmap_write_mode_t::always_pwrite); + } #endif lt::session_params sessionParams {std::move(pack), {}}; @@ -1648,6 +1655,7 @@ void SessionImpl::initializeNativeSession() sessionParams.disk_io_constructor = customPosixDiskIOConstructor; break; case DiskIOType::MMap: + case DiskIOType::SimplePreadPwrite: sessionParams.disk_io_constructor = customMMapDiskIOConstructor; break; default: diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 1c39a5436..4903159ff 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -589,6 +589,7 @@ void AdvancedSettings::loadAdvancedSettings() m_comboBoxDiskIOType.addItem(tr("Default"), QVariant::fromValue(BitTorrent::DiskIOType::Default)); m_comboBoxDiskIOType.addItem(tr("Memory mapped files"), QVariant::fromValue(BitTorrent::DiskIOType::MMap)); m_comboBoxDiskIOType.addItem(tr("POSIX-compliant"), QVariant::fromValue(BitTorrent::DiskIOType::Posix)); + m_comboBoxDiskIOType.addItem(tr("Simple pread/pwrite"), QVariant::fromValue(BitTorrent::DiskIOType::SimplePreadPwrite)); m_comboBoxDiskIOType.setCurrentIndex(m_comboBoxDiskIOType.findData(QVariant::fromValue(session->diskIOType()))); addRow(DISK_IO_TYPE, tr("Disk IO type (requires restart)") + u' ' + makeLink(u"https://www.libtorrent.org/single-page-ref.html#default-disk-io-constructor", u"(?)") , &m_comboBoxDiskIOType); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 31febeb83..e92412dc3 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1344,6 +1344,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD +