Page 1 of 1

Lazy Allocates all memory on startup

Posted: 8. Oct 2019, 21:52
by ReddMaxx
I have several Windows 10 Guest vm boxes that I run on a Windows 10 host.

The problem is when I start up a vm it lazy allocates all memory before the box starts instead of only lazy loading what it needs. You can watch the memory slowly be allocated on the host machine. Once it allocates all the memory it starts windows.

I have set VBoxInternal/RamPreAlloc to 1 and it will load the vm a lot faster and in bigger memory chunks, so I don't think this is a RamPreAlloc issue.

Also if I save a vm that has already been started, and start it again, the vm will only use the memory it needs and lazy allocates additional memory only when needed like you would expect. This seems to be only a problem if you are starting the vm for cold instead of from a save point.

Is there any reason why Virtualbox would try and lazy load all memory before windows starts? Or is there a program or service in windows 10 that physical checks all the memory on startup? The only thing I can think of is on a cold start windows actually goes out and does some diagnostic on the ram which causes virtualbox to lazy allocate all the memory at start up.

Thanks
Redd

Re: Lazy Allocates all memory on startup

Posted: 9. Oct 2019, 00:33
by socratis
VirtualBox allocates RAM in a lazy manner, true. Whenever the guest OS touches a memory page, VirtualBox has to allocate it. Windows is notorious for touching almost all the pages at startup.

As for your questions regarding "VBoxInternal/RamPreAlloc", I'll refer you to the response of Ramshankar in the "What happens if I exceed my RAM?" thread. Memory is allocated in contiguous chunks, but not all of it at the launch of the VM (i.e. in a lazy allocated fashion), unless the following has been set:
  • 
    VBoxManage setextradata "<VMname>" "VBoxInternal/RamPreAlloc" 1

Re: Lazy Allocates all memory on startup

Posted: 9. Oct 2019, 21:00
by ReddMaxx
Thanks for the response, I suspected as much that windows was looking at all the ram.

I went back and tested my win7 boxes and they act different than win10. Win7 will startup and continue lazy loading all the memory so the box comes up faster. But win10 wants to touch all the memory before starting up. I tried to disable some services but I think it must be in the core window code that touches the memory.

Since I don't mind if all the memory is allocated at startup the RamPreAlloc will work for me. But if someone needs the lazy allocation I would suggest starting up the box and then saving the vm instead of power off. The next time you start the vm from the save state only the memory it needs will be allocated because you won't be going through whatever code is in windows that needs to touch every page.

Thanks
Redd

Re: Lazy Allocates all memory on startup

Posted: 10. Oct 2019, 02:44
by socratis
ReddMaxx wrote:I would suggest starting up the box and then saving the vm instead of power off
Just remember to not change VirtualBox versions while you have VMs in Saved State, bad things can happen, like your VM not resuming and you'll end up discarding your Saved State along with the contents of the RAM and unsaved documents.