package host // StartMarginGB is the commit memory a VM needs beyond its guest RAM: QEMU's own // allocations and the graphics path. Conservative; refine with measurements. const StartMarginGB = 1.0 // memoryChoices are the sizes the UI offers (GB). var memoryChoices = []float64{4, 6, 8, 12, 16, 24, 32, 48, 64} // RecommendedMemoryGB is the largest offered size that fits both in 60% of // physical RAM and in the commit memory free now (minus StartMarginGB and 2 GB // headroom for the host). At least 4. func RecommendedMemoryGB(rep Report) float64 { limit := rep.TotalRAMGB * 0.6 if rep.CommitAvailGB > 0 { if c := rep.CommitAvailGB - StartMarginGB - 2; c < limit { limit = c } } best := memoryChoices[0] for _, m := range memoryChoices { if m <= limit { best = m } } return best }