Overcommit memory on purpose and watch the host and guest react
Task
Allocate more memory to running guests than the host can supply, then drive the guests to use it, and record what happens: the host's free memory, paging, and a guest's responsiveness. Then compare a thin and a thick virtual disk by what the guest sees and what the host actually stores.
Steps
- Record the host's physical memory and the memory assigned to each guest in
lab/virt/allocation.csvwith headervm,assigned_mb, and the host total inlab/virt/host.txtashost_mb: <n>. - Raise the guests' assigned memory (or enable dynamic memory or ballooning) until the total assigned exceeds the host's free memory. Update the CSV.
- In each guest, run
stress-ng --vm 1 --vm-bytes 90% --timeout 120s. While it runs, record the host's free memory and paging (Task Manager orvmstat 5on the host) inlab/virt/host-under-load.txt, and time a simple command such asls -R /usr > /dev/nullin one guest, saving the timing tolab/virt/guest-timing.txt. - Create one 10 GB thin (dynamically expanding) and one 10 GB thick (fixed) virtual disk. Record the size each guest sees and the size of each file on the host in
lab/virt/disks.csvwith headerdisk,type,guest_gb,host_file_gb, with typethinorthick.
Verify
These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.
awk -F, 'NR>1 {t+=$2} END {print t" MB assigned"}' lab/virt/allocation.csv
grep -E '^host_mb: [0-9]+' lab/virt/host.txt
grep -c . lab/virt/host-under-load.txt
awk -F, 'NR>1 {print $1": guest "$3" GB, host file "$4" GB"}' lab/virt/disks.csv
awk -F, 'NR>1 && $2=="thin" && $4<$3 {print "thin disk uses less than it promises"}' lab/virt/disks.csv
The assigned total must exceed the host's free memory, the thin disk's host file must be much smaller than what the guest sees, and the thick disk's must match it. If thin disks across a host all grow to their promised size, the storage fills and every guest stops -- the thin-provisioning trap from the lesson.
Notes
Hypervisors reclaim memory in stages: ballooning first, then compression or page sharing, and host swapping last. Host swapping is the stage that makes every guest slow at once, which is why production memory is usually reserved rather than overcommitted.
This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.