From 9c10e99aef0a627da24100e0a1b3bf0f0b13230a Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 7 Nov 2015 22:00:20 -0500 Subject: [PATCH] forward port fix to not auto-detect disk cache size greater than the virtual address space for 32 bit builds --- ChangeLog | 2 ++ src/disk_buffer_pool.cpp | 63 +++++++--------------------------------- src/settings_pack.cpp | 2 +- 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11ceb4144..b9409a63f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -78,6 +78,8 @@ 1.0.7 release + * fix bug where 32 bit builds could use more disk cache than the virtual + address space (when set to automatic) * fix support for torrents with > 500'000 pieces * fix ip filter bug when banning peers * fix IPv6 IP address resolution in URLs diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 709c06826..47f4837c5 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert.hpp" #include "libtorrent/alert_types.hpp" #include "libtorrent/disk_observer.hpp" +#include "libtorrent/platform_util.hpp" // for total_physical_ram #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -459,57 +460,6 @@ namespace libtorrent check_buffer_level(l); } - namespace { - - boost::uint64_t physical_ram() - { - boost::uint64_t ret = 0; - // figure out how much physical RAM there is in - // this machine. This is used for automatically - // sizing the disk cache size when it's set to - // automatic. -#ifdef TORRENT_BSD -#ifdef HW_MEMSIZE - int mib[2] = { CTL_HW, HW_MEMSIZE }; -#else - // not entirely sure this sysctl supports 64 - // bit return values, but it's probably better - // than not building - int mib[2] = { CTL_HW, HW_PHYSMEM }; -#endif - size_t len = sizeof(ret); - if (sysctl(mib, 2, &ret, &len, NULL, 0) != 0) - ret = 0; -#elif defined TORRENT_WINDOWS - MEMORYSTATUSEX ms; - ms.dwLength = sizeof(MEMORYSTATUSEX); - if (GlobalMemoryStatusEx(&ms)) - ret = ms.ullTotalPhys; - else - ret = 0; -#elif defined TORRENT_LINUX - ret = sysconf(_SC_PHYS_PAGES); - ret *= sysconf(_SC_PAGESIZE); -#elif defined TORRENT_AMIGA - ret = AvailMem(MEMF_PUBLIC); -#endif - -#if TORRENT_USE_RLIMIT - if (ret > 0) - { - struct rlimit r; - if (getrlimit(rlimit_as, &r) == 0 && r.rlim_cur != rlim_infinity) - { - if (ret > r.rlim_cur) - ret = r.rlim_cur; - } - } -#endif - return ret; - } - - } // anonymous namespace - void disk_buffer_pool::set_settings(aux::session_settings const& sett , error_code& ec) { @@ -543,9 +493,18 @@ namespace libtorrent int cache_size = sett.get_int(settings_pack::cache_size); if (cache_size < 0) { - boost::uint64_t phys_ram = physical_ram(); + boost::uint64_t phys_ram = total_physical_ram(); if (phys_ram == 0) m_max_use = 1024; else m_max_use = phys_ram / 8 / m_block_size; + + if (sizeof(void*) == 4) + { + // 32 bit builds should capped below 2 GB of memory, even + // when more actual ram is available, because we're still + // constrained by the 32 bit virtual address space. + m_max_use = (std::min)(1 * 1024 + * 1024 * 1024 / m_block_size, m_max_use); + } } else { diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 26ae8a6f8..55d2ff131 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/settings_pack.hpp" #include "libtorrent/aux_/session_impl.hpp" -#include "libtorrent/platform_util.hpp" // for total_physical_ram +//#include "libtorrent/platform_util.hpp" // for total_physical_ram #include