| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3462b46 commit 44a8ecf
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -138,6 +138,11 @@ void PerIsolateOptions::HandleMaxOldSpaceSizePercentage( | |||
| 138 | 138 | ? constrained_memory | |
| 139 | 139 | : total_memory; | |
| 140 | 140 | ||
| 141 | + if (available_memory == 0) { | ||
| 142 | + errors->push_back("the available memory can not be calculated"); | ||
| 143 | + return; | ||
| 144 | + } | ||
| 145 | + | ||
| 141 | 146 | // Convert to MB and calculate the percentage | |
| 142 | 147 | uint64_t memory_mb = available_memory / (1024 * 1024); | |
| 143 | 148 | uint64_t calculated_mb = static_cast<size_t>(memory_mb * percentage / 100.0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,14 +119,19 @@ assert( | |||
| 119 | 119 | ||
| 120 | 120 | // Validate heap sizes against system memory | |
| 121 | 121 | const totalMemoryMB = Math.floor(os.totalmem() / 1024 / 1024); | |
| 122 | - const margin = 10; // 5% margin | ||
| 122 | + const uint64Max = 2 ** 64 - 1; | ||
| 123 | + const constrainedMemory = process.constrainedMemory(); | ||
| 124 | + const constrainedMemoryMB = Math.floor(constrainedMemory / 1024 / 1024); | ||
| 125 | + const effectiveMemoryMB = | ||
| 126 | + constrainedMemory > 0 && constrainedMemory !== uint64Max ? constrainedMemoryMB : totalMemoryMB; | ||
| 127 | + const margin = 10; // 10% margin | ||
| 123 | 128 | testPercentages.forEach((percentage) => { | |
| 124 | - const upperLimit = totalMemoryMB * ((percentage + margin) / 100); | ||
| 129 | + const upperLimit = effectiveMemoryMB * ((percentage + margin) / 100); | ||
| 125 | 130 | assert( | |
| 126 | 131 | heapSizes[percentage] <= upperLimit, | |
| 127 | 132 | `Heap size for ${percentage}% (${heapSizes[percentage]} MB) should not exceed upper limit (${upperLimit} MB)` | |
| 128 | 133 | ); | |
| 129 | - const lowerLimit = totalMemoryMB * ((percentage - margin) / 100); | ||
| 134 | + const lowerLimit = effectiveMemoryMB * ((percentage - margin) / 100); | ||
| 130 | 135 | assert( | |
| 131 | 136 | heapSizes[percentage] >= lowerLimit, | |
| 132 | 137 | `Heap size for ${percentage}% (${heapSizes[percentage]} MB) should not be less than lower limit (${lowerLimit} MB)` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments