Browse Source

Split the OS cache settings into Disk IO read/write modes

Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
adaptive-webui-19844
summer 2 years ago committed by Chocobo1
parent
commit
5b730ffb72
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 61
      src/base/bittorrent/session.cpp
  2. 26
      src/base/bittorrent/session.h
  3. 28
      src/gui/advancedsettings.cpp
  4. 2
      src/gui/advancedsettings.h
  5. 15
      src/webui/api/appcontroller.cpp
  6. 25
      src/webui/www/private/views/preferences.html

61
src/base/bittorrent/session.cpp

@ -343,7 +343,8 @@ Session::Session(QObject *parent)
, m_diskCacheTTL(BITTORRENT_SESSION_KEY(u"DiskCacheTTL"_qs), 60) , m_diskCacheTTL(BITTORRENT_SESSION_KEY(u"DiskCacheTTL"_qs), 60)
, m_diskQueueSize(BITTORRENT_SESSION_KEY(u"DiskQueueSize"_qs), (1024 * 1024)) , m_diskQueueSize(BITTORRENT_SESSION_KEY(u"DiskQueueSize"_qs), (1024 * 1024))
, m_diskIOType(BITTORRENT_SESSION_KEY(u"DiskIOType"_qs), DiskIOType::Default) , m_diskIOType(BITTORRENT_SESSION_KEY(u"DiskIOType"_qs), DiskIOType::Default)
, m_useOSCache(BITTORRENT_SESSION_KEY(u"UseOSCache"_qs), true) , m_diskIOReadMode(BITTORRENT_SESSION_KEY(u"DiskIOReadMode"_qs), DiskIOReadMode::EnableOSCache)
, m_diskIOWriteMode(BITTORRENT_SESSION_KEY(u"DiskIOWriteMode"_qs), DiskIOWriteMode::EnableOSCache)
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
, m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY(u"CoalesceReadWrite"_qs), true) , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY(u"CoalesceReadWrite"_qs), true)
#else #else
@ -1612,10 +1613,32 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_int(lt::settings_pack::max_queued_disk_bytes, diskQueueSize()); settingsPack.set_int(lt::settings_pack::max_queued_disk_bytes, diskQueueSize());
lt::settings_pack::io_buffer_mode_t mode = useOSCache() ? lt::settings_pack::enable_os_cache switch (diskIOReadMode())
: lt::settings_pack::disable_os_cache; {
settingsPack.set_int(lt::settings_pack::disk_io_read_mode, mode); case DiskIOReadMode::DisableOSCache:
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, mode); settingsPack.set_int(lt::settings_pack::disk_io_read_mode, lt::settings_pack::disable_os_cache);
break;
case DiskIOReadMode::EnableOSCache:
default:
settingsPack.set_int(lt::settings_pack::disk_io_read_mode, lt::settings_pack::enable_os_cache);
break;
}
switch (diskIOWriteMode())
{
case DiskIOWriteMode::DisableOSCache:
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, lt::settings_pack::disable_os_cache);
break;
case DiskIOWriteMode::EnableOSCache:
default:
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, lt::settings_pack::enable_os_cache);
break;
#ifdef QBT_USES_LIBTORRENT2
case DiskIOWriteMode::WriteThrough:
settingsPack.set_int(lt::settings_pack::disk_io_write_mode, lt::settings_pack::write_through);
break;
#endif
}
#ifndef QBT_USES_LIBTORRENT2 #ifndef QBT_USES_LIBTORRENT2
settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled()); settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled());
@ -3762,18 +3785,32 @@ void Session::setDiskQueueSize(const qint64 size)
configureDeferred(); configureDeferred();
} }
bool Session::useOSCache() const DiskIOReadMode Session::diskIOReadMode() const
{ {
return m_useOSCache; return m_diskIOReadMode;
} }
void Session::setUseOSCache(const bool use) void Session::setDiskIOReadMode(const DiskIOReadMode mode)
{ {
if (use != m_useOSCache) if (mode == m_diskIOReadMode)
{ return;
m_useOSCache = use;
m_diskIOReadMode = mode;
configureDeferred();
}
DiskIOWriteMode Session::diskIOWriteMode() const
{
return m_diskIOWriteMode;
}
void Session::setDiskIOWriteMode(const DiskIOWriteMode mode)
{
if (mode == m_diskIOWriteMode)
return;
m_diskIOWriteMode = mode;
configureDeferred(); configureDeferred();
}
} }
bool Session::isCoalesceReadWriteEnabled() const bool Session::isCoalesceReadWriteEnabled() const

26
src/base/bittorrent/session.h

@ -121,6 +121,13 @@ namespace BitTorrent
}; };
Q_ENUM_NS(ChokingAlgorithm) Q_ENUM_NS(ChokingAlgorithm)
enum class DiskIOReadMode : int
{
DisableOSCache = 0,
EnableOSCache = 1
};
Q_ENUM_NS(DiskIOReadMode)
enum class DiskIOType : int enum class DiskIOType : int
{ {
Default = 0, Default = 0,
@ -129,6 +136,16 @@ namespace BitTorrent
}; };
Q_ENUM_NS(DiskIOType) Q_ENUM_NS(DiskIOType)
enum class DiskIOWriteMode : int
{
DisableOSCache = 0,
EnableOSCache = 1,
#ifdef QBT_USES_LIBTORRENT2
WriteThrough = 2
#endif
};
Q_ENUM_NS(DiskIOWriteMode)
enum class MixedModeAlgorithm : int enum class MixedModeAlgorithm : int
{ {
TCP = 0, TCP = 0,
@ -359,8 +376,10 @@ namespace BitTorrent
void setDiskQueueSize(qint64 size); void setDiskQueueSize(qint64 size);
DiskIOType diskIOType() const; DiskIOType diskIOType() const;
void setDiskIOType(DiskIOType type); void setDiskIOType(DiskIOType type);
bool useOSCache() const; DiskIOReadMode diskIOReadMode() const;
void setUseOSCache(bool use); void setDiskIOReadMode(DiskIOReadMode mode);
DiskIOWriteMode diskIOWriteMode() const;
void setDiskIOWriteMode(DiskIOWriteMode mode);
bool isCoalesceReadWriteEnabled() const; bool isCoalesceReadWriteEnabled() const;
void setCoalesceReadWriteEnabled(bool enabled); void setCoalesceReadWriteEnabled(bool enabled);
bool usePieceExtentAffinity() const; bool usePieceExtentAffinity() const;
@ -687,7 +706,8 @@ namespace BitTorrent
CachedSettingValue<int> m_diskCacheTTL; CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<qint64> m_diskQueueSize; CachedSettingValue<qint64> m_diskQueueSize;
CachedSettingValue<DiskIOType> m_diskIOType; CachedSettingValue<DiskIOType> m_diskIOType;
CachedSettingValue<bool> m_useOSCache; CachedSettingValue<DiskIOReadMode> m_diskIOReadMode;
CachedSettingValue<DiskIOWriteMode> m_diskIOWriteMode;
CachedSettingValue<bool> m_coalesceReadWriteEnabled; CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_usePieceExtentAffinity; CachedSettingValue<bool> m_usePieceExtentAffinity;
CachedSettingValue<bool> m_isSuggestMode; CachedSettingValue<bool> m_isSuggestMode;

28
src/gui/advancedsettings.cpp

@ -114,7 +114,8 @@ namespace
#ifdef QBT_USES_LIBTORRENT2 #ifdef QBT_USES_LIBTORRENT2
DISK_IO_TYPE, DISK_IO_TYPE,
#endif #endif
OS_CACHE, DISK_IO_READ_MODE,
DISK_IO_WRITE_MODE,
#ifndef QBT_USES_LIBTORRENT2 #ifndef QBT_USES_LIBTORRENT2
COALESCE_RW, COALESCE_RW,
#endif #endif
@ -208,8 +209,10 @@ void AdvancedSettings::saveAdvancedSettings() const
#ifdef QBT_USES_LIBTORRENT2 #ifdef QBT_USES_LIBTORRENT2
session->setDiskIOType(m_comboBoxDiskIOType.currentData().value<BitTorrent::DiskIOType>()); session->setDiskIOType(m_comboBoxDiskIOType.currentData().value<BitTorrent::DiskIOType>());
#endif #endif
// Enable OS cache // Disk IO read mode
session->setUseOSCache(m_checkBoxOsCache.isChecked()); session->setDiskIOReadMode(m_comboBoxDiskIOReadMode.currentData().value<BitTorrent::DiskIOReadMode>());
// Disk IO write mode
session->setDiskIOWriteMode(m_comboBoxDiskIOWriteMode.currentData().value<BitTorrent::DiskIOWriteMode>());
#ifndef QBT_USES_LIBTORRENT2 #ifndef QBT_USES_LIBTORRENT2
// Coalesce reads & writes // Coalesce reads & writes
session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked()); session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked());
@ -508,10 +511,21 @@ void AdvancedSettings::loadAdvancedSettings()
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"(?)") 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); , &m_comboBoxDiskIOType);
#endif #endif
// Enable OS cache // Disk IO read mode
m_checkBoxOsCache.setChecked(session->useOSCache()); m_comboBoxDiskIOReadMode.addItem(tr("Disable OS cache"), QVariant::fromValue(BitTorrent::DiskIOReadMode::DisableOSCache));
addRow(OS_CACHE, (tr("Enable OS cache") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", u"(?)")) m_comboBoxDiskIOReadMode.addItem(tr("Enable OS cache"), QVariant::fromValue(BitTorrent::DiskIOReadMode::EnableOSCache));
, &m_checkBoxOsCache); m_comboBoxDiskIOReadMode.setCurrentIndex(m_comboBoxDiskIOReadMode.findData(QVariant::fromValue(session->diskIOReadMode())));
addRow(DISK_IO_READ_MODE, (tr("Disk IO read mode") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#disk_io_read_mode", u"(?)"))
, &m_comboBoxDiskIOReadMode);
// Disk IO write mode
m_comboBoxDiskIOWriteMode.addItem(tr("Disable OS cache"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::DisableOSCache));
m_comboBoxDiskIOWriteMode.addItem(tr("Enable OS cache"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::EnableOSCache));
#ifdef QBT_USES_LIBTORRENT2
m_comboBoxDiskIOWriteMode.addItem(tr("Write-through"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::WriteThrough));
#endif
m_comboBoxDiskIOWriteMode.setCurrentIndex(m_comboBoxDiskIOWriteMode.findData(QVariant::fromValue(session->diskIOWriteMode())));
addRow(DISK_IO_WRITE_MODE, (tr("Disk IO write mode") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", u"(?)"))
, &m_comboBoxDiskIOWriteMode);
#ifndef QBT_USES_LIBTORRENT2 #ifndef QBT_USES_LIBTORRENT2
// Coalesce reads & writes // Coalesce reads & writes
m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled()); m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled());

2
src/gui/advancedsettings.h

@ -71,7 +71,7 @@ private:
m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity, m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport; m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage; m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage;
QLineEdit m_lineEditAnnounceIP; QLineEdit m_lineEditAnnounceIP;

15
src/webui/api/appcontroller.cpp

@ -324,8 +324,10 @@ void AppController::preferencesAction()
data[u"disk_queue_size"_qs] = session->diskQueueSize(); data[u"disk_queue_size"_qs] = session->diskQueueSize();
// Disk IO Type // Disk IO Type
data[u"disk_io_type"_qs] = static_cast<int>(session->diskIOType()); data[u"disk_io_type"_qs] = static_cast<int>(session->diskIOType());
// Enable OS cache // Disk IO read mode
data[u"enable_os_cache"_qs] = session->useOSCache(); data[u"disk_io_read_mode"_qs] = static_cast<int>(session->diskIOReadMode());
// Disk IO write mode
data[u"disk_io_write_mode"_qs] = static_cast<int>(session->diskIOWriteMode());
// Coalesce reads & writes // Coalesce reads & writes
data[u"enable_coalesce_read_write"_qs] = session->isCoalesceReadWriteEnabled(); data[u"enable_coalesce_read_write"_qs] = session->isCoalesceReadWriteEnabled();
// Piece Extent Affinity // Piece Extent Affinity
@ -817,9 +819,12 @@ void AppController::setPreferencesAction()
// Disk IO Type // Disk IO Type
if (hasKey(u"disk_io_type"_qs)) if (hasKey(u"disk_io_type"_qs))
session->setDiskIOType(static_cast<BitTorrent::DiskIOType>(it.value().toInt())); session->setDiskIOType(static_cast<BitTorrent::DiskIOType>(it.value().toInt()));
// Enable OS cache // Disk IO read mode
if (hasKey(u"enable_os_cache"_qs)) if (hasKey(u"disk_io_read_mode"_qs))
session->setUseOSCache(it.value().toBool()); session->setDiskIOReadMode(static_cast<BitTorrent::DiskIOReadMode>(it.value().toInt()));
// Disk IO write mode
if (hasKey(u"disk_io_write_mode"_qs))
session->setDiskIOWriteMode(static_cast<BitTorrent::DiskIOWriteMode>(it.value().toInt()));
// Coalesce reads & writes // Coalesce reads & writes
if (hasKey(u"enable_coalesce_read_write"_qs)) if (hasKey(u"enable_coalesce_read_write"_qs))
session->setCoalesceReadWriteEnabled(it.value().toBool()); session->setCoalesceReadWriteEnabled(it.value().toBool());

25
src/webui/www/private/views/preferences.html

@ -1060,10 +1060,25 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<label for="enableOSCache">QBT_TR(Enable OS cache:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode" target="_blank">(?)</a></label> <label for="diskIOReadMode">QBT_TR(Disk IO read mode:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#disk_io_read_mode" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="checkbox" id="enableOSCache" /> <select id="diskIOReadMode" style="width: 15em;">
<option value="0">QBT_TR(Disable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">QBT_TR(Enable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="diskIOWriteMode">QBT_TR(Disk IO write mode:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode" target="_blank">(?)</a></label>
</td>
<td>
<select id="diskIOWriteMode" style="width: 15em;">
<option value="0">QBT_TR(Disable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">QBT_TR(Enable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="2">QBT_TR(Write-through (requires libtorrent >= 2.0.6))QBT_TR[CONTEXT=OptionsDialog]</option>
</select>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -2003,7 +2018,8 @@
$('diskCacheExpiryInterval').setProperty('value', pref.disk_cache_ttl); $('diskCacheExpiryInterval').setProperty('value', pref.disk_cache_ttl);
$('diskQueueSize').setProperty('value', (pref.disk_queue_size / 1024)); $('diskQueueSize').setProperty('value', (pref.disk_queue_size / 1024));
$('diskIOType').setProperty('value', pref.disk_io_type); $('diskIOType').setProperty('value', pref.disk_io_type);
$('enableOSCache').setProperty('checked', pref.enable_os_cache); $('diskIOReadMode').setProperty('value', pref.disk_io_read_mode);
$('diskIOWriteMode').setProperty('value', pref.disk_io_write_mode);
$('coalesceReadsAndWrites').setProperty('checked', pref.enable_coalesce_read_write); $('coalesceReadsAndWrites').setProperty('checked', pref.enable_coalesce_read_write);
$('pieceExtentAffinity').setProperty('checked', pref.enable_piece_extent_affinity); $('pieceExtentAffinity').setProperty('checked', pref.enable_piece_extent_affinity);
$('sendUploadPieceSuggestions').setProperty('checked', pref.enable_upload_suggestions); $('sendUploadPieceSuggestions').setProperty('checked', pref.enable_upload_suggestions);
@ -2409,7 +2425,8 @@
settings.set('disk_cache_ttl', $('diskCacheExpiryInterval').getProperty('value')); settings.set('disk_cache_ttl', $('diskCacheExpiryInterval').getProperty('value'));
settings.set('disk_queue_size', ($('diskQueueSize').getProperty('value') * 1024)); settings.set('disk_queue_size', ($('diskQueueSize').getProperty('value') * 1024));
settings.set('disk_io_type', $('diskIOType').getProperty('value')); settings.set('disk_io_type', $('diskIOType').getProperty('value'));
settings.set('enable_os_cache', $('enableOSCache').getProperty('checked')); settings.set('disk_io_read_mode', $('diskIOReadMode').getProperty('value'));
settings.set('disk_io_write_mode', $('diskIOWriteMode').getProperty('value'));
settings.set('enable_coalesce_read_write', $('coalesceReadsAndWrites').getProperty('checked')); settings.set('enable_coalesce_read_write', $('coalesceReadsAndWrites').getProperty('checked'));
settings.set('enable_piece_extent_affinity', $('pieceExtentAffinity').getProperty('checked')); settings.set('enable_piece_extent_affinity', $('pieceExtentAffinity').getProperty('checked'));
settings.set('enable_upload_suggestions', $('sendUploadPieceSuggestions').getProperty('checked')); settings.set('enable_upload_suggestions', $('sendUploadPieceSuggestions').getProperty('checked'));

Loading…
Cancel
Save