# HG changeset patch # User Chris Cannam # Date 1488893273 0 # Node ID 91231350ee228678a3f238133d00753a42a13476 # Parent d40246df828b259b6fbf0a1461809b20b7042927 Change where the 32-bit memory calculation adjustment is carried out -- more transparent here diff -r d40246df828b -r 91231350ee22 base/StorageAdviser.cpp --- a/base/StorageAdviser.cpp Tue Mar 07 13:27:31 2017 +0000 +++ b/base/StorageAdviser.cpp Tue Mar 07 13:27:53 2017 +0000 @@ -97,6 +97,28 @@ SVDEBUG << "StorageAdviser: disc space: " << discFree << "M, memory free: " << memoryFree << "M, memory total: " << memoryTotal << "M" << endl; + + // In 32-bit addressing mode we can't address more than 4Gb. + // If the total memory is reported as more than 4Gb, we should + // reduce the available amount by the difference between 4Gb + // and the total. This won't give us an accurate idea of the + // amount of memory available any more, but it should be enough + // to prevent us from trying to allocate more for our own use + // than can be addressed at all! + if (sizeof(void *) < 8) { + if (memoryTotal > 4096) { + ssize_t excess = memoryTotal - 4096; + if (memoryFree > excess) { + memoryFree -= excess; + } else { + memoryFree = 0; + } + SVDEBUG << "StorageAdviser: more real memory found than we " + << "can address in a 32-bit process, reducing free " + << "estimate to " << memoryFree << "M accordingly" << endl; + } + } + SVDEBUG << "StorageAdviser: disc planned: " << (m_discPlanned / 1024) << "K, memory planned: " << (m_memoryPlanned / 1024) << "K" << endl; SVDEBUG << "StorageAdviser: min requested: " << minimumSize diff -r d40246df828b -r 91231350ee22 system/System.cpp --- a/system/System.cpp Tue Mar 07 13:27:31 2017 +0000 +++ b/system/System.cpp Tue Mar 07 13:27:53 2017 +0000 @@ -181,24 +181,6 @@ if (size > INT_MAX) size = INT_MAX; total = ssize_t(size); - // In 32-bit addressing mode we can't address more than 4Gb. - // If the total memory is reported as more than 4Gb, we should - // reduce the available amount by the difference between 4Gb - // and the total. This won't give us an accurate idea of the - // amount of memory available any more, but it should be enough - // to prevent us from trying to allocate more for our own use - // than can be addressed at all! - if (sizeof(void *) < 8) { - if (total > 4096) { - ssize_t excess = total - 4096; - if (available > excess) { - available -= excess; - } else { - available = 0; - } - } - } - return; #else diff -r d40246df828b -r 91231350ee22 system/System.h --- a/system/System.h Tue Mar 07 13:27:31 2017 +0000 +++ b/system/System.h Tue Mar 07 13:27:53 2017 +0000 @@ -154,7 +154,8 @@ extern ProcessStatus GetProcessStatus(int pid); // Return a vague approximation to the number of free megabytes of real memory. -// Return -1 if unknown. (Hence signed args) +// Return -1 if unknown. (Hence signed args.) Note that this could be more than +// is actually addressable, e.g. for a 32-bit process on a 64-bit system. extern void GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total); // Return a vague approximation to the number of free megabytes of