Files
千川白浪andClaude Opus 5.5 43c387affc fix(host): count page file growth in commit memory checks
The start check, start wait, memory recommendation and create/settings
validation compared guest RAM against GlobalMemoryStatusEx's current
commit limit. A system-managed or min/max page file grows on demand, so
that limit refused VMs that would start: with 30.7/37.4 GB committed an
8G guest was rejected while about 38 GB could still be committed.

Read each paging file's current and maximum size with
NtQuerySystemInformation(SystemPageFileInformationEx) and add the room
it can still grow, capped by its volume's free space minus a 2 GB
reserve. Fixed-size or disabled page files add nothing; if the query
fails the old values stand. Measured on Windows 10: one commit of free
commit + 10 GB (VirtualAlloc and CreateFileMapping) succeeded and grew
the limit from 37.4 to 47.4 GB.

The start error now names the total requirement and the guest share and
says page file growth is already counted; the host report gains
paging_file_growth_gb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 08:04:14 -07:00

62 lines
2.6 KiB
Go

package host
import "testing"
func TestPagingFileGrowth(t *testing.T) {
cases := []struct {
name string
files []PagingFile
want float64
}{
{"no paging file", nil, 0},
// The measured host: system-managed 5.6 GB file, max 37.5 GB (1/8 of C:), 141.7 GB free.
{"system managed", []PagingFile{{Volume: `C:\`, CurrentGB: 5.6, MaxGB: 37.5, VolumeFreeGB: 141.7}}, 31.9},
{"fixed size", []PagingFile{{Volume: `C:\`, CurrentGB: 16, MaxGB: 16, VolumeFreeGB: 100}}, 0},
{"max below current", []PagingFile{{Volume: `C:\`, CurrentGB: 8, MaxGB: 4, VolumeFreeGB: 100}}, 0},
{"disk nearly full", []PagingFile{{Volume: `C:\`, CurrentGB: 4, MaxGB: 40, VolumeFreeGB: 5}}, 3},
{"disk below reserve", []PagingFile{{Volume: `C:\`, CurrentGB: 4, MaxGB: 40, VolumeFreeGB: 1}}, 0},
{"two files share one volume", []PagingFile{
{Volume: `D:\`, CurrentGB: 2, MaxGB: 10, VolumeFreeGB: 12},
{Volume: `d:\`, CurrentGB: 2, MaxGB: 10, VolumeFreeGB: 12},
}, 10},
{"files on two volumes", []PagingFile{
{Volume: `C:\`, CurrentGB: 2, MaxGB: 6, VolumeFreeGB: 50},
{Volume: `D:\`, CurrentGB: 1, MaxGB: 3, VolumeFreeGB: 50},
}, 6},
}
for _, tc := range cases {
got := PagingFileGrowthGB(tc.files)
if diff := got - tc.want; diff > 1e-9 || diff < -1e-9 {
t.Errorf("%s: got %.2f, want %.2f", tc.name, got, tc.want)
}
}
}
func TestCommitHeadroomAddsGrowth(t *testing.T) {
// Task Manager on the measured host: 30.7 / 37.4 GB committed. The current
// limit leaves 6.7 GB, which refused an 8G guest that starts fine.
limit, avail := CommitHeadroom(37.4, 6.7, []PagingFile{{Volume: `C:\`, CurrentGB: 5.6, MaxGB: 37.5, VolumeFreeGB: 141.7}})
if limit < 69.2 || limit > 69.4 || avail < 38.5 || avail > 38.7 {
t.Fatalf("got limit %.2f avail %.2f, want ~69.3 / ~38.6", limit, avail)
}
if limit, avail := CommitHeadroom(37.4, 6.7, nil); limit != 37.4 || avail != 6.7 {
t.Fatalf("no paging file info: got %.2f / %.2f, want the current values", limit, avail)
}
}
func TestRecommendedMemoryFollowsCommitMemory(t *testing.T) {
// 32 GB host with 14.7 GiB commit Windows can still grant -> 8G.
if got := RecommendedMemoryGB(Report{TotalRAMGB: 31.8, CommitAvailGB: 14.7}); got != 8 {
t.Fatalf("got %v, want 8", got)
}
if got := RecommendedMemoryGB(Report{TotalRAMGB: 64, CommitAvailGB: 60}); got != 32 {
t.Fatalf("got %v, want 32", got)
}
if got := RecommendedMemoryGB(Report{TotalRAMGB: 8, CommitAvailGB: 3}); got != 4 {
t.Fatalf("got %v, want the 4 GB floor", got)
}
if got := RecommendedMemoryGB(Report{TotalRAMGB: 32}); got != 16 {
t.Fatalf("unknown commit: got %v, want 16", got)
}
}