Skip to content

Commit 94c7c65

Browse files
committed
Use free+inactive only for the low-RAM probe
Purgeable often overlaps the inactive queue on Darwin, so summing both overstates reclaimable memory. Keep the gate conservative.
1 parent eaf05b9 commit 94c7c65

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Sources/VocaMac/Services/SystemInfo.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ enum SystemInfo {
151151

152152
/// Approximate reclaimable memory in bytes. Zero means the probe failed.
153153
///
154-
/// Counts free, inactive, and purgeable pages. On Darwin, `free_count`
155-
/// already includes speculative pages, so they must not be added again.
156-
/// Compressor-resident pages still occupy RAM and are not available
157-
/// capacity for a new model allocation.
154+
/// Uses free + inactive only. On Darwin, `free_count` already includes
155+
/// speculative pages, purgeable pages often overlap the inactive queue,
156+
/// and compressor-resident pages still occupy RAM — so those counters
157+
/// must not be added on top or the gate can over-approve loads.
158158
static var availableMemoryBytes: UInt64 {
159159
var stats = vm_statistics64()
160160
var count = mach_msg_type_number_t(
@@ -172,7 +172,6 @@ enum SystemInfo {
172172
guard host_page_size(host, &pageSize) == KERN_SUCCESS, pageSize > 0 else { return 0 }
173173
let pages = UInt64(stats.free_count)
174174
+ UInt64(stats.inactive_count)
175-
+ UInt64(stats.purgeable_count)
176175
return pages * UInt64(pageSize)
177176
}
178177

0 commit comments

Comments
 (0)