From 31ffbb1edde703bcc29fad361ba5db98498d0502 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Mon, 3 Dec 2012 17:22:40 +0100 Subject: [PATCH] Enabling Windows disk cache (and adding option to disable it) to prevent a relatively prevalent ERROR_INVALID_PARAMETER. From my test only the write cache was the culprit, if this can be confirmed the read cache can be disabled by default if that has a benefit. (Other systems are unchanged.) --- src/preferences/advancedsettings.h | 12 ++++++++++-- src/preferences/preferences.h | 16 ++++++++++++++++ src/qtlibtorrent/qbtsession.cpp | 9 +++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/preferences/advancedsettings.h b/src/preferences/advancedsettings.h index 496ab2764..13a1efebd 100644 --- a/src/preferences/advancedsettings.h +++ b/src/preferences/advancedsettings.h @@ -13,7 +13,7 @@ #include "preferences.h" enum AdvSettingsCols {PROPERTY, VALUE}; -enum AdvSettingsRows {DISK_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING, NETWORK_IFACE, NETWORK_ADDRESS, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT, +enum AdvSettingsRows {DISK_CACHE, OS_WRITE_CACHE, OS_READ_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING, NETWORK_IFACE, NETWORK_ADDRESS, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT, #if defined(Q_WS_WIN) || defined(Q_WS_MAC) UPDATE_CHECK, #endif @@ -29,7 +29,7 @@ class AdvancedSettings: public QTableWidget { private: QSpinBox spin_cache, outgoing_ports_min, outgoing_ports_max, spin_list_refresh, spin_maxhalfopen, spin_tracker_port; - QCheckBox cb_ignore_limits_lan, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, + QCheckBox cb_write_cache, cb_read_cache, cb_ignore_limits_lan, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding, cb_program_notifications, cb_tracker_status, cb_confirm_torrent_deletion, cb_enable_tracker_ext; QComboBox combo_iface; @@ -67,6 +67,8 @@ public slots: Preferences pref; // Disk write cache pref.setDiskCacheSize(spin_cache.value()); + pref.disableOSWriteCache(cb_write_cache.isChecked()); + pref.disableOSReadCache(cb_read_cache.isChecked()); // Outgoing ports pref.setOutgoingPortsMin(outgoing_ports_min.value()); pref.setOutgoingPortsMax(outgoing_ports_max.value()); @@ -159,6 +161,12 @@ private slots: spin_cache.setValue(pref.diskCacheSize()); spin_cache.setSuffix(tr(" MiB")); setRow(DISK_CACHE, tr("Disk write cache size"), &spin_cache); + // OS write cache + cb_write_cache.setChecked(pref.disableOSWriteCache()); + setRow(OS_WRITE_CACHE, tr("Disable OS caching of disk writes"), &cb_write_cache); + // OS read cache + cb_read_cache.setChecked(pref.disableOSReadCache()); + setRow(OS_READ_CACHE, tr("Disable OS caching of disk reads"), &cb_read_cache); // Outgoing port Min outgoing_ports_min.setMinimum(0); outgoing_ports_min.setMaximum(65535); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 4dc61e765..bb33739e5 100755 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -934,6 +934,22 @@ public: setValue(QString::fromUtf8("Preferences/Downloads/DiskCache"), size); } + bool disableOSWriteCache() const { + return value(QString::fromUtf8("Preferences/Advanced/DisableOSWriteCache"), false).toBool(); + } + + void disableOSWriteCache(bool disable) { + setValue(QString::fromUtf8("Preferences/Advanced/DisableOSWriteCache"), disable); + } + + bool disableOSReadCache() const { + return value(QString::fromUtf8("Preferences/Advanced/DisableOSReadCache"), false).toBool(); + } + + void disableOSReadCache(bool disable) { + setValue(QString::fromUtf8("Preferences/Advanced/DisableOSReadCache"), disable); + } + uint outgoingPortsMin() const { return value(QString::fromUtf8("Preferences/Advanced/OutgoingPortsMin"), 0).toUInt(); } diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 4d5bdb702..78fccccd0 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -404,12 +404,9 @@ void QBtSession::configureSession() { sessionSettings.auto_scrape_min_interval = 900; // 15 minutes sessionSettings.cache_size = pref.diskCacheSize()*64; qDebug() << "Using a disk cache size of" << pref.diskCacheSize() << "MiB"; - // Disable OS cache to avoid memory problems (uTorrent behavior) -#ifdef Q_WS_WIN - // Fixes huge memory usage on Windows 7 (especially when checking files) - sessionSettings.disk_io_write_mode = session_settings::disable_os_cache; - sessionSettings.disk_io_read_mode = session_settings::disable_os_cache; -#endif + // Disabling the OS disk cache is intended to reduce memory usage (especially when checking files) but might be unreliable + sessionSettings.disk_io_write_mode = pref.disableOSWriteCache() ? session_settings::disable_os_cache : session_settings::enable_os_cache; + sessionSettings.disk_io_read_mode = pref.disableOSReadCache() ? session_settings::disable_os_cache : session_settings::enable_os_cache; #if LIBTORRENT_VERSION_MINOR > 15 sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled(); if (sessionSettings.anonymous_mode) {