Skip to content

Commit

Permalink
Implement new disk IO type: forced fallback to pread/pwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
HanabishiRecca committed Sep 5, 2024
1 parent a7f7c5f commit d25e4a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ namespace BitTorrent
{
Default = 0,
MMap = 1,
Posix = 2
Posix = 2,
Pread = 3
};
Q_ENUM_NS(DiskIOType)

Expand Down
8 changes: 8 additions & 0 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Pread)
{
pack.set_int(lt::settings_pack::mmap_file_size_cutoff, std::numeric_limits<int>::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), {}};
Expand All @@ -1648,6 +1655,7 @@ void SessionImpl::initializeNativeSession()
sessionParams.disk_io_constructor = customPosixDiskIOConstructor;
break;
case DiskIOType::MMap:
case DiskIOType::Pread:
sessionParams.disk_io_constructor = customMMapDiskIOConstructor;
break;
default:
Expand Down
1 change: 1 addition & 0 deletions src/gui/advancedsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,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("Pread/Pwrite"), QVariant::fromValue(BitTorrent::DiskIOType::Pread));
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);
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@
<option value="0">QBT_TR(Default)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">QBT_TR(Memory mapped files)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="2">QBT_TR(POSIX-compliant)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="3">QBT_TR(Pread/Pwrite)QBT_TR[CONTEXT=OptionsDialog]</option>
</select>
</td>
</tr>
Expand Down

0 comments on commit d25e4a2

Please sign in to comment.