VirtualBox

Opened 9 years ago

Closed 7 years ago

#15195 closed defect (worksforme)

Memory Leak in VirtualBox.exe

Reported by: jgmgmgm Owned by:
Component: GUI Version: VirtualBox 5.0.14
Keywords: memory leak vboxmanager virtualbox.exr Cc:
Guest type: Linux Host type: Windows

Description

After running for a long time the VirtualBox instance for a running VM consumes more and more memory. It starts at only a hundred MB or so and ends up at several GB (private working set). I thought at first this might be the memory the VM is using however after a restart the VM uses a lot of memory immediately (resident) but none of the processes show a usage corresponding with this.

Specifics:

Host: Windows 7 64bit Guest: Debian 7 64bit Other: Shared folder with symlinks enabled. Low process priority set for virtualbox on host. USB2 extension used. No graphics/X11 on guest.

Are there any diagnostic facilities I can use to give a hint at where all of this memory is being used?

Change History (9)

comment:1 by jgmgmgm, 9 years ago

No graphics/X11 on guest. -> not literally, just standard tty.

comment:2 by Frank Mehnert, 9 years ago

How much RAM do you have configured for your guest (where is the VBox.log file?) and how did you determine the memory consumption of the VM?

comment:3 by jgmgmgm, 9 years ago

8GB for the VM.

Straight away when the VM boots and I run applications top shows heavy usage of resident memory. A bit concerning that this never shows directly in Windows. If it is the VM memory usage then it works in a very strange way I am not familiar with and achieves amazing results (some kind of deduplication or optimisation for empty blocks perhaps). However if it's able to do something like defer allocation for zeroed blocks I can't believe that there would be so many for one given the data I would expect to be in RAM and for the other restarting processes within the VM does not help much. If it is deduplicating it is doing remarkably well but there is no way I know of to get metrics on this. In that case the problem may be a weakness in that. I don't see any strong indications that the memory usage of the main process strongly relates to what is happening in the VM.

KiB Mem: 8198436 total, 4269692 used, 3928744 free, 527576 buffers KiB Swap: 0 total, 0 used, 0 free, 719788 cached

CPU is nearly always 100% for the VirtualBox.exe process because I'm running constant data processing in the guest.

The leak appears to be fairly slow. Since I originally reported this the memory usage of the process has roughly doubled to 270MB. It has just gone up to 310MB for some reason.

Last edited 9 years ago by jgmgmgm (previous) (diff)

comment:4 by Frank Mehnert, 9 years ago

You still didn't provide a VBox.log file. If you allocated 8GB to the guest and run a Linux guest then the behavior your described is completely normal:

  • VirtualBox allocates the memory demanded by the guest on demand. That is, the VM process starts with quite a low amount of memory and when the guest touches physical memory then VirtualBox allocates the corresponding memory on the host. Linux guests don't touch the physical memory on the boot, therefore the VM process will grow over the time when the guest starts more processes. A Windows guest will behave differently: The VM will allocate most of the memory at boot time.
  • The memory allocated to the VM process will not be freed until the VM process terminates. This is not a bug but the missing implementation of a feature.

comment:5 by jgmgmgm, 9 years ago

You still didn't provide a VBox.log file.

I would rather check my assertion first and establish what actually is expected behaviour for VirtualBox. The is little that appears particularly relevant to memory in this fashion in the log anyway. What would be superior is to know what in the log related to the initialisation of memory management modes and to know how to have some basic output of statistics or tracking on memory allocations.

I don't usually associate the memory usage of the VirtualBox process with the guest because after booting the VM it's not empty with no services. It very quickly pulls several hundred megabytes of data from databases which are stored inefficiently in memory for high level scripting languages and processed constantly as fast as the network and CPU will allow. I find it very hard to believe that the memory usage of the VM host process corresponds to the memory usage of the guest in this case unless it is doing some impressive deduplication or similar (smaller page size, etc). The guest starts with resident memory usage of over 2GB with another 1.5GB for cache and buffers.

KiB Mem: 8198436 total, 6197632 used, 2000804 free, 692572 buffers KiB Swap: 0 total, 0 used, 0 free, 1100584 cached

The VBox process has gone up to almost 1GB usage.

Deallocating memory in the host has no impact on this:

KiB Mem: 8198436 total, 3190584 used, 5007852 free, 692580 buffers KiB Swap: 0 total, 0 used, 0 free, 1100700 cached

After running for some more time the process is up to 1.2GB with the VM memory usage as:

KiB Mem: 8198436 total, 5216036 used, 2982400 free, 709568 buffers KiB Swap: 0 total, 0 used, 0 free, 1164044 cached

The increase in memory use for the host process is quite slow.

If VirtualBox knows when memory is needed by some mechanism but not when to free it then that could explain the behaviour. It actually makes sense if that is happening. You would potentially need something like TRIM but for memory.

If that is the case it is not a typical memory leak in the normal sense but still is a memory related degradation in performance.

The memory usage after starting a lot of processes is low. I believe the kernel does the same and only allocates memory when actually used.

If it's this it means whatever mechanism VirtualBox uses is far more superior to the kernel of the guest. But ultimately for a long running VM it appears to become useless.

Last edited 9 years ago by jgmgmgm (previous) (diff)

comment:6 by jgmgmgm, 9 years ago

As far as I can tell so far, my original belief is true. The VM's memory does not show up in the process's usage. I've always suspected this because the sum of the private bytes at a glance or a guess doesn't come close to the memory usage windows reports when virtualbox is running.

If you use sysinternals RamMap you can see that the VM only shows its memory usage as driver locked.

It's a shame virtualbox manager doesn't show this.

So there definitely appears to be a memory leak. virtualbox.exe + Driver Locked = 10GB. The highest I've seen would theoretically be 12GB for a VM with 8GB of memory.

comment:7 by jgmgmgm, 9 years ago

memtester shows the memory usage for driver locked corresponds closely to that of the VM. It also demonstrates the lack of a TRIM like capability. That's fine.

Memory leak confirmed.

comment:8 by Frank Mehnert, 9 years ago

I don't see anything confirmed. And you still didn't provide a VBox.log file for such a VM session!

The memory used by the VirtualBox process is not exactly the same as used by normal processes. I already explained above that it's hard to verify the memory consumption on Windows. Even if Windows reports less available memory it does not mean that the memory is assigned to the VM process. Windows uses memory for caching and for disk buffers.

A memory leak of a process means that the memory assigned to this process grows over the lifetime of the process. I explained the behavior of VirtualBox of dynamically allocating memory. You might want to try the following setting:

VBoxManage setextradata VM_NAME "VBoxInternal/RamPreAlloc" 1

This setting will force VirtualBox to allocate the guest memory for the VM process during VM start. The start will take more time, in particular for VMs with a huge amount of guest RAM assigned.

I will not provide further comments until you provided VBox.log files of your VM processes.

comment:9 by Frank Mehnert, 7 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette