comparison base/StorageAdviser.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents cee1be4fb8c1
children
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
63 StorageAdviser::Recommendation 63 StorageAdviser::Recommendation
64 StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation; 64 StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation;
65 65
66 StorageAdviser::Recommendation 66 StorageAdviser::Recommendation
67 StorageAdviser::recommend(Criteria criteria, 67 StorageAdviser::recommend(Criteria criteria,
68 size_t minimumSize, 68 size_t minimumSize,
69 size_t maximumSize) 69 size_t maximumSize)
70 { 70 {
71 SVDEBUG << "StorageAdviser::recommend: criteria " << criteria 71 SVDEBUG << "StorageAdviser::recommend: criteria " << criteria
72 << " (" + criteriaToString(criteria) + ")" 72 << " (" + criteriaToString(criteria) + ")"
73 << ", minimumSize " << minimumSize 73 << ", minimumSize " << minimumSize
74 << ", maximumSize " << maximumSize << endl; 74 << ", maximumSize " << maximumSize << endl;
81 } 81 }
82 82
83 QString path; 83 QString path;
84 try { 84 try {
85 path = TempDirectory::getInstance()->getPath(); 85 path = TempDirectory::getInstance()->getPath();
86 } catch (std::exception e) { 86 } catch (const std::exception &e) {
87 SVDEBUG << "StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl; 87 SVDEBUG << "StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl;
88 int r = UseMemory | ConserveSpace; 88 int r = UseMemory | ConserveSpace;
89 SVDEBUG << "StorageAdviser: returning fallback " << r 89 SVDEBUG << "StorageAdviser: returning fallback " << r
90 << " (" << recommendationToString(r) << ")" << endl; 90 << " (" << recommendationToString(r) << ")" << endl;
91 return Recommendation(r); 91 return Recommendation(r);
95 GetRealMemoryMBAvailable(memoryFree, memoryTotal); 95 GetRealMemoryMBAvailable(memoryFree, memoryTotal);
96 96
97 SVDEBUG << "StorageAdviser: disc space: " << discFree 97 SVDEBUG << "StorageAdviser: disc space: " << discFree
98 << "M, memory free: " << memoryFree 98 << "M, memory free: " << memoryFree
99 << "M, memory total: " << memoryTotal << "M" << endl; 99 << "M, memory total: " << memoryTotal << "M" << endl;
100
101 // In 32-bit addressing mode we can't address more than 4Gb.
102 // If the total memory is reported as more than 4Gb, we should
103 // reduce the available amount by the difference between 4Gb
104 // and the total. This won't give us an accurate idea of the
105 // amount of memory available any more, but it should be enough
106 // to prevent us from trying to allocate more for our own use
107 // than can be addressed at all!
108 if (sizeof(void *) < 8) {
109 if (memoryTotal > 4096) {
110 ssize_t excess = memoryTotal - 4096;
111 if (memoryFree > excess) {
112 memoryFree -= excess;
113 } else {
114 memoryFree = 0;
115 }
116 SVDEBUG << "StorageAdviser: more real memory found than we "
117 << "can address in a 32-bit process, reducing free "
118 << "estimate to " << memoryFree << "M accordingly" << endl;
119 }
120 }
121
100 SVDEBUG << "StorageAdviser: disc planned: " << (m_discPlanned / 1024) 122 SVDEBUG << "StorageAdviser: disc planned: " << (m_discPlanned / 1024)
101 << "K, memory planned: " << (m_memoryPlanned / 1024) << "K" << endl; 123 << "K, memory planned: " << (m_memoryPlanned / 1024) << "K" << endl;
102 SVDEBUG << "StorageAdviser: min requested: " << minimumSize 124 SVDEBUG << "StorageAdviser: min requested: " << minimumSize
103 << "K, max requested: " << maximumSize << "K" << endl; 125 << "K, max requested: " << maximumSize << "K" << endl;
104 126