Hyper-v usage of dynamic memory


I would suggest to use dynamic memory for the vm in hyper-v in order to minimize the impact on the hosted machine.
At this point there is a 2GB penalty in order to use the vm.

Very nice integration with hyper-v.



I tried changing this through Hyper-V manager and I can only say, DON’T TRY THIS :slight_smile: My vm consumed 10GB of ram before I shut it down, this was when running a single alpine linux/nginx container with nothing in it.

I hope this get’s implemented and enabled by default though as it makes a lot of sense.

1 Like

we used to have dynamic memory enabled but as @paxxi mentioned we saw fairly large memory consumption in some cases so we reverted to the safer case of static memory. We may add dynamic memory support at some point in the future


Even when there is “large memory consumption” the host OS and the VM should balance memory needs.

Possible solutions (these may be combined):

  • Set VM Memory Weight to 0, so that all other tasks have higher priority for dynamic memory. get-vm 'MobyLinuxVM' | Set-VMMemory -Priority 0

  • Set VM maximum memory to a fraction of system memory, so that the VM cannot consume more than a fixed share of memory. $mem = gwmi Win32_OperatingSystem | select -ExpandProperty TotalVisibleMemorySize; Get-VM 'MobyLinuxVM' | Set-VMMemory -DynamicMemoryEnabled $true -MaximumBytes (($mem*1024) / 2);

  • Set the host Memory Reserve property in the registry. (I would caution against this, because it affects all virtual machines, or put it behind a toggle, but it’s an option!) Create a MemoryReserve DWORD value under the key HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\ with the number of megabytes to reserve.

I haven’t checked this, but you would also want to make sure MobyLinux is running with all the appropriate Hyper-V kernel modules for dynamic memory. On a working Fedora VM I have, these are what I see under lsmod:

hv_balloon             24576  0
hv_utils               24576  0
hv_netvsc              36864  0
hv_storvsc             24576  3
hv_vmbus              106496  7 hv_balloon,hyperv_keyboard,hv_netvsc,hid_hyperv,hv_utils,hyperv_fb,hv_storvsc
1 Like


After using the tricks listed in this post I was able to to do a modprobe -l which gave the following output:


This implies that we have either statically compiled the hyper-v modules into the kernel (I don’t know if that is possible), or that we are not running the hyper-v modules.

@rneugeba, were these modules enabled when you were testing the MobyLinux distro?

I would love to be able to get this feature working, I have processes that momentarily take more than 8 GB of memory but would rapidly shrink down to a much smaller size at steady state. I would much rather not give my docker VM a full 8 GB of my memory all of the time for a job that would only need it for 5 minutes.

@rneugeba - I think setting a min and max limit would just like on Hyper-v manager make much more sense. Where does enabling dynamic memory rank in your priority list now :slight_smile:

There is a script at C:\Program Files\Docker\Docker\resources\MobyLinux.ps1 that will create and controls this.

Docker team did recieve may such requests to enable dynamic VM size but they marked it as wont fix here https://github.com/docker/for-win/issues/521 and you can see a reason for it

Something to tinker with if we plan to improve memory usage, for development purposes