diff --git a/assets/win10x64-enterprise-eval.xml b/assets/win10x64-enterprise-eval.xml index ee75f27..f8adba8 100644 --- a/assets/win10x64-enterprise-eval.xml +++ b/assets/win10x64-enterprise-eval.xml @@ -246,6 +246,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 26 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win10x64-enterprise.xml b/assets/win10x64-enterprise.xml index 5e5eb8c..2005231 100644 --- a/assets/win10x64-enterprise.xml +++ b/assets/win10x64-enterprise.xml @@ -249,6 +249,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 26 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win10x64-iot.xml b/assets/win10x64-iot.xml index 00a049e..170c813 100644 --- a/assets/win10x64-iot.xml +++ b/assets/win10x64-iot.xml @@ -255,6 +255,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 26 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win10x64-ltsc.xml b/assets/win10x64-ltsc.xml index e77dd6a..7cf03f8 100644 --- a/assets/win10x64-ltsc.xml +++ b/assets/win10x64-ltsc.xml @@ -252,6 +252,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 26 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win10x64.xml b/assets/win10x64.xml index 7c21359..deb995d 100644 --- a/assets/win10x64.xml +++ b/assets/win10x64.xml @@ -249,6 +249,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 26 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win11x64-enterprise-eval.xml b/assets/win11x64-enterprise-eval.xml index 39c3f02..42df0f3 100644 --- a/assets/win11x64-enterprise-eval.xml +++ b/assets/win11x64-enterprise-eval.xml @@ -269,6 +269,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 27 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win11x64-enterprise.xml b/assets/win11x64-enterprise.xml index bafed49..21c12e2 100644 --- a/assets/win11x64-enterprise.xml +++ b/assets/win11x64-enterprise.xml @@ -272,6 +272,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 27 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win11x64-iot.xml b/assets/win11x64-iot.xml index d6825d0..70ed099 100644 --- a/assets/win11x64-iot.xml +++ b/assets/win11x64-iot.xml @@ -272,6 +272,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 27 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win11x64-ltsc.xml b/assets/win11x64-ltsc.xml index a9a6ce7..ed184b6 100644 --- a/assets/win11x64-ltsc.xml +++ b/assets/win11x64-ltsc.xml @@ -272,6 +272,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 27 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win11x64.xml b/assets/win11x64.xml index 8082c7c..def9498 100644 --- a/assets/win11x64.xml +++ b/assets/win11x64.xml @@ -272,6 +272,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 27 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2008r2-eval.xml b/assets/win2008r2-eval.xml index 09a23ce..94c7eb6 100644 --- a/assets/win2008r2-eval.xml +++ b/assets/win2008r2-eval.xml @@ -154,6 +154,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win2008r2.xml b/assets/win2008r2.xml index 5dee0a5..c24157e 100644 --- a/assets/win2008r2.xml +++ b/assets/win2008r2.xml @@ -157,6 +157,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win2012r2-eval.xml b/assets/win2012r2-eval.xml index 6351559..7aba11e 100644 --- a/assets/win2012r2-eval.xml +++ b/assets/win2012r2-eval.xml @@ -155,6 +155,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2012r2.xml b/assets/win2012r2.xml index bb3dd70..cdd3978 100644 --- a/assets/win2012r2.xml +++ b/assets/win2012r2.xml @@ -158,6 +158,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2016-eval.xml b/assets/win2016-eval.xml index d788960..a325f8b 100644 --- a/assets/win2016-eval.xml +++ b/assets/win2016-eval.xml @@ -155,6 +155,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2016.xml b/assets/win2016.xml index e055e00..f2ac93f 100644 --- a/assets/win2016.xml +++ b/assets/win2016.xml @@ -158,6 +158,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2019-eval.xml b/assets/win2019-eval.xml index 332d974..df6d418 100644 --- a/assets/win2019-eval.xml +++ b/assets/win2019-eval.xml @@ -159,6 +159,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2019-hv.xml b/assets/win2019-hv.xml index 2fb6e32..2f31c01 100644 --- a/assets/win2019-hv.xml +++ b/assets/win2019-hv.xml @@ -164,6 +164,11 @@ dism.exe /online /Disable-Feature /FeatureName:Microsoft-Hyper-V /NoRestart Disable Hyper-V role + + 3 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2019.xml b/assets/win2019.xml index b5d8235..9581320 100644 --- a/assets/win2019.xml +++ b/assets/win2019.xml @@ -162,6 +162,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2022-eval.xml b/assets/win2022-eval.xml index 5748cb4..1bb039f 100644 --- a/assets/win2022-eval.xml +++ b/assets/win2022-eval.xml @@ -159,6 +159,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2022.xml b/assets/win2022.xml index eac9414..68078a5 100644 --- a/assets/win2022.xml +++ b/assets/win2022.xml @@ -162,6 +162,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2025-eval.xml b/assets/win2025-eval.xml index 5b92f00..a7221d0 100644 --- a/assets/win2025-eval.xml +++ b/assets/win2025-eval.xml @@ -164,6 +164,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 4 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win2025.xml b/assets/win2025.xml index 2796db6..9dc2616 100644 --- a/assets/win2025.xml +++ b/assets/win2025.xml @@ -167,6 +167,11 @@ pnputil -i -a C:\Windows\Drivers\viogpudo\viogpudo.inf Install VirtIO display driver + + 4 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win7x64-enterprise-eval.xml b/assets/win7x64-enterprise-eval.xml index c3cc15b..3e31417 100644 --- a/assets/win7x64-enterprise-eval.xml +++ b/assets/win7x64-enterprise-eval.xml @@ -148,6 +148,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x64-enterprise.xml b/assets/win7x64-enterprise.xml index b362a9f..f742c8f 100644 --- a/assets/win7x64-enterprise.xml +++ b/assets/win7x64-enterprise.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x64-ultimate.xml b/assets/win7x64-ultimate.xml index 2ee085a..751d771 100644 --- a/assets/win7x64-ultimate.xml +++ b/assets/win7x64-ultimate.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x64.xml b/assets/win7x64.xml index 3769dfd..42a9473 100644 --- a/assets/win7x64.xml +++ b/assets/win7x64.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x86-enterprise.xml b/assets/win7x86-enterprise.xml index 7ac8ef0..69fddab 100644 --- a/assets/win7x86-enterprise.xml +++ b/assets/win7x86-enterprise.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x86-ultimate.xml b/assets/win7x86-ultimate.xml index 419a508..f37c27e 100644 --- a/assets/win7x86-ultimate.xml +++ b/assets/win7x86-ultimate.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win7x86.xml b/assets/win7x86.xml index bae5a8f..52d6494 100644 --- a/assets/win7x86.xml +++ b/assets/win7x86.xml @@ -152,6 +152,15 @@ + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/win81x64-enterprise-eval.xml b/assets/win81x64-enterprise-eval.xml index 745fd9d..17dbf55 100644 --- a/assets/win81x64-enterprise-eval.xml +++ b/assets/win81x64-enterprise-eval.xml @@ -146,6 +146,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win81x64-enterprise.xml b/assets/win81x64-enterprise.xml index a073c38..1e02c74 100644 --- a/assets/win81x64-enterprise.xml +++ b/assets/win81x64-enterprise.xml @@ -149,6 +149,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/win81x64.xml b/assets/win81x64.xml index 6b45785..5ed5ea0 100644 --- a/assets/win81x64.xml +++ b/assets/win81x64.xml @@ -156,6 +156,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\FirstNetwork" /v Category /t REG_DWORD /d 1 /f Set Network Location to Home + + 2 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + diff --git a/assets/winvistax64-enterprise.xml b/assets/winvistax64-enterprise.xml index a3dac19..8594df8 100644 --- a/assets/winvistax64-enterprise.xml +++ b/assets/winvistax64-enterprise.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/winvistax64-ultimate.xml b/assets/winvistax64-ultimate.xml index eb12e60..5bce170 100644 --- a/assets/winvistax64-ultimate.xml +++ b/assets/winvistax64-ultimate.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/winvistax64.xml b/assets/winvistax64.xml index ad2ac70..419f531 100644 --- a/assets/winvistax64.xml +++ b/assets/winvistax64.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/winvistax86-enterprise.xml b/assets/winvistax86-enterprise.xml index 5092331..f88dc0d 100644 --- a/assets/winvistax86-enterprise.xml +++ b/assets/winvistax86-enterprise.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/winvistax86-ultimate.xml b/assets/winvistax86-ultimate.xml index 97ad23e..708b0a6 100644 --- a/assets/winvistax86-ultimate.xml +++ b/assets/winvistax86-ultimate.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/assets/winvistax86.xml b/assets/winvistax86.xml index ade1942..65c6dcb 100644 --- a/assets/winvistax86.xml +++ b/assets/winvistax86.xml @@ -90,6 +90,15 @@ false + + + + 1 + C:\Windows\Drivers\Balloon\blnsvr.exe -i + Install VirtIO Balloon service + + + diff --git a/readme.md b/readme.md index 116e830..a5d258e 100644 --- a/readme.md +++ b/readme.md @@ -170,6 +170,41 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/windows/refs/heads/mas CPU_CORES: "4" ``` +### How do I enable dynamic memory allocation? + + By default, the VM is allocated the full amount of RAM configured via `RAM_SIZE` for its entire lifetime. + + If you want the container to dynamically reclaim unused guest RAM based on host memory pressure, you can enable memory ballooning: + + ```yaml + environment: + BALLOONING: "Y" + ``` + + This requires the VirtIO Balloon service to be installed in the guest. For all supported Windows versions, this happens automatically during unattended installation. If you are using a manual installation or an existing guest that was installed before this feature was added, you need to install it manually by running the following command inside the VM: + + ```bat + C:\Windows\Drivers\Balloon\blnsvr.exe -i + ``` + + The following optional variables allow you to tune the ballooning behaviour: + + | **Variable** | **Default** | **Description** | + |---|---|---| + | `BALLOONING` | _(off)_ | Set to `Y` to enable dynamic memory ballooning | + | `BALLOONING_MIN_MEM` | `33%` | Minimum balloon target, as a percentage of guest max memory (e.g. `33%`) or absolute size (e.g. `2G`) | + | `BALLOONING_RAM_THRESHOLD`| `80.0` | Target host RAM usage percentage; the PI controller aims to keep host usage at or below this value | + | `BALLOONING_RAM_THRESHOLD_HARD`| `90.0` | Host RAM usage percentage above which the balloon target may drop below guest RAM usage, inducing guest memory pressure | + | `BALLOONING_PSI_PRESSURE` | `10.0` | Host PSI `avg10` stall percentage at which the PSI ceiling begins to lower the balloon target | + | `BALLOONING_PSI_PRESSURE_MAX` | `50.0` | Host PSI `avg10` stall percentage at which the PSI ceiling reaches the configured minimum balloon target | + | `BALLOONING_HYSTERESIS` | `128M` | Minimum balloon target change required before a resize is applied, as a percentage (e.g. `2%`) or absolute size (e.g. `256M`) | + | `BALLOONING_KP` | `0.5` | PI controller proportional gain; higher values react faster but may oscillate | + | `BALLOONING_KI` | `0.05` | PI controller integral gain; higher values correct steady-state error faster but risk overshoot | + | `BALLOONING_INTERVAL` | `5` | Polling interval in seconds | + +> [!NOTE] +> Memory ballooning uses Linux PSI (`/proc/pressure/memory`) for progressive pressure detection. Between `BALLOONING_PSI_PRESSURE` and `BALLOONING_PSI_PRESSURE_MAX` the PSI ceiling linearly lowers the maximum balloon target from guest max memory down to the configured minimum. If PSI is unavailable (kernel lacks `CONFIG_PSI`), both thresholds are silently skipped and ballooning continues using host memory usage alone. + ### How do I configure the username and password? By default, a user called `Docker` is created and its password is `admin`. diff --git a/src/entry.sh b/src/entry.sh index 71e939e..e1713f9 100644 --- a/src/entry.sh +++ b/src/entry.sh @@ -24,6 +24,7 @@ cd /run . power.sh # Configure shutdown . memory.sh # Check available memory . config.sh # Configure arguments +. ballooning.sh # Initialize ballooning . finish.sh # Finish initialization trap - ERR