From b40430f17583c8a835afcd202092cd6120979acc Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 6 Mar 2016 01:42:46 -0500 Subject: [PATCH] change the cache size calculation for auto cache size (-1) to be smaller, especially for machines with large amounts of RAM --- src/disk_buffer_pool.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 642c55477..79486d75e 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -481,9 +481,35 @@ namespace libtorrent int const cache_size = sett.get_int(settings_pack::cache_size); if (cache_size < 0) { - boost::uint64_t const phys_ram = total_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; + else + { + // this is the logic to calculate the automatic disk cache size + // based on the amount of physical RAM. + // The more physical RAM, the smaller portion of it is allocated + // for the cache. + + // we take a 30th of everything exceeding 4 GiB + // a 20th of everything exceeding 1 GiB + // and a 10th of everything below a GiB + + boost::int64_t const gb = 1024 * 1024 * 1024; + + boost::int64_t result = 0; + if (phys_ram > 4 * gb) + { + result += (phys_ram - 4 * gb) / 30; + phys_ram = 4 * gb; + } + if (phys_ram > 1 * gb) + { + result += (phys_ram - 1 * gb) / 20; + phys_ram = 1 * gb; + } + result += phys_ram / 10; + m_max_use = result / m_block_size; + } if (sizeof(void*) == 4) {