Mercurial > hg > svcore
changeset 1405:91231350ee22
Change where the 32-bit memory calculation adjustment is carried out -- more transparent here
author | Chris Cannam |
---|---|
date | Tue, 07 Mar 2017 13:27:53 +0000 |
parents | d40246df828b |
children | 09751743647e |
files | base/StorageAdviser.cpp system/System.cpp system/System.h |
diffstat | 3 files changed, 24 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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