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>
88 lines
3.1 KiB
Go
88 lines
3.1 KiB
Go
//go:build windows
|
|
|
|
package host
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"testing"
|
|
"unicode/utf16"
|
|
)
|
|
|
|
// pagingFileEntry writes one SYSTEM_PAGEFILE_INFORMATION_EX entry at off,
|
|
// with its name stored at nameOff inside the same buffer.
|
|
func pagingFileEntry(buf []byte, base uintptr, off, next, nameOff int, name string, sizePg, maxPg uint32) {
|
|
e := buf[off:]
|
|
binary.LittleEndian.PutUint32(e[pfNextEntryOffset:], uint32(next))
|
|
binary.LittleEndian.PutUint32(e[pfTotalSize:], sizePg)
|
|
u := utf16.Encode([]rune(name))
|
|
binary.LittleEndian.PutUint16(e[pfNameLength:], uint16(2*len(u)))
|
|
binary.LittleEndian.PutUint64(e[pfNameBuffer:], uint64(base)+uint64(nameOff))
|
|
binary.LittleEndian.PutUint32(e[pfMaximumSize:], maxPg)
|
|
for i, c := range u {
|
|
binary.LittleEndian.PutUint16(buf[nameOff+2*i:], c)
|
|
}
|
|
}
|
|
|
|
func TestParsePagingFilesEx(t *testing.T) {
|
|
const base = uintptr(0x10000)
|
|
buf := make([]byte, 512)
|
|
pagingFileEntry(buf, base, 0, 48, 200, `\??\C:\pagefile.sys`, 1469696, 9830400)
|
|
pagingFileEntry(buf, base, 48, 0, 300, `\??\D:\pagefile.sys`, 1024, 1024)
|
|
got, err := parsePagingFilesEx(buf, base)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []rawPagingFile{
|
|
{Name: `\??\C:\pagefile.sys`, SizePg: 1469696, MaxSizePg: 9830400},
|
|
{Name: `\??\D:\pagefile.sys`, SizePg: 1024, MaxSizePg: 1024},
|
|
}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("got %d entries, want %d", len(got), len(want))
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Errorf("entry %d: got %+v, want %+v", i, got[i], want[i])
|
|
}
|
|
}
|
|
if v := pagingFileVolume(got[0].Name); v != `C:\` {
|
|
t.Errorf("volume: got %q, want C:\\", v)
|
|
}
|
|
}
|
|
|
|
func TestParsePagingFilesExRejectsBadInput(t *testing.T) {
|
|
const base = uintptr(0x10000)
|
|
if _, err := parsePagingFilesEx(make([]byte, pfEntryMinSize-1), base); err == nil {
|
|
t.Error("short buffer: want error")
|
|
}
|
|
buf := make([]byte, 128)
|
|
pagingFileEntry(buf, base, 0, 100, 60, `\??\C:\pagefile.sys`, 1, 2) // next entry runs past the end
|
|
if _, err := parsePagingFilesEx(buf, base); err == nil {
|
|
t.Error("truncated list: want error")
|
|
}
|
|
buf = make([]byte, 128)
|
|
pagingFileEntry(buf, base, 0, 0, 60, `\??\C:\pagefile.sys`, 1, 2)
|
|
binary.LittleEndian.PutUint64(buf[pfNameBuffer:], 0x5000) // name outside the buffer
|
|
got, err := parsePagingFilesEx(buf, base)
|
|
if err != nil || len(got) != 1 || got[0].Name != "" {
|
|
t.Errorf("name outside buffer: got %+v, %v; want one entry with no name", got, err)
|
|
}
|
|
}
|
|
|
|
func TestProbePagingFilesLive(t *testing.T) {
|
|
files, err := probePagingFiles()
|
|
if err != nil {
|
|
t.Fatalf("probePagingFiles: %v", err)
|
|
}
|
|
for _, f := range files {
|
|
if f.Volume == "" || f.CurrentGB <= 0 || f.MaxGB < 0 || f.VolumeFreeGB < 0 {
|
|
t.Errorf("implausible paging file %+v", f)
|
|
}
|
|
t.Logf("%s current %.1f GB max %.1f GB volume free %.1f GB", f.Volume, f.CurrentGB, f.MaxGB, f.VolumeFreeGB)
|
|
}
|
|
limit, avail, growth, ok := probeCommitGB()
|
|
if !ok || limit <= 0 || avail < 0 || avail > limit || growth < 0 {
|
|
t.Fatalf("probeCommitGB = %.1f, %.1f, %.1f, %v", limit, avail, growth, ok)
|
|
}
|
|
t.Logf("reachable commit limit %.1f GB, can grant %.1f GB, paging file growth %.1f GB", limit, avail, growth)
|
|
}
|