Memory allocation
Posted: 19. Sep 2022, 11:22
Hello folks.
We have observed in a one or two rare cases C++ "std::bad_alloc" in our software. This does not happen when running on the host.
To investigate this issue I am trying to understand memory allocation in Virtual Box and any limitations.
I have the following setup:
Host: Windows 10 Build 19044 with 16 logical processes and 32 GB RAM
Guest: Windows 10 Build 18362
We have a 64-bit test application that allocates blocks of of memory on the heap in a loop. User can decide size of memory block and how many blocks to create. Each byte in memory block is assigned random value.
* Case #1 - Running the guest with 16 GB base memory.
- Execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 25,3 GB of virtual memory (22 GB private memory and 14,8 GB working memory) before throwing a std::bad_alloc exception.
* Case #2 - Running the guest with 16 GB base memory.
- First execute test application to create 4 GB of data in blocks of 1 GB (without any exception)
- Secondly execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 22,1 GB of virtual memory (17,8 GB private memory and 12,1 GB working memory) before throwing a std::bad_alloc exception.
* Case #3 - Running the guest with 4 GB base memory.
- Execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 13,7 GB of virtual memory (9,4 GB private memory and 3,1 GB working memory) before throwing a std::bad_alloc exception.
Questions
1. What is the relationship between "base memory" value and how much memory a process can allocated in the guest OS? Base memory of 4 GB appear to allow a process to allocated 13 GB. Quadrupling the base memory will "only" allowed a process to allocated 25 GB.
2. Comparing #1 and #2 there appears to be a limit to how much memory the OS can allocated. Is that correct? How can I determine this limit?
3. Other posts mention that Virtual Box uses MmAllocateContiguousMemory API. What is the relationship between the value used in this API and "base memory"? How can I determine which value is used in the API?
We have observed in a one or two rare cases C++ "std::bad_alloc" in our software. This does not happen when running on the host.
To investigate this issue I am trying to understand memory allocation in Virtual Box and any limitations.
I have the following setup:
Host: Windows 10 Build 19044 with 16 logical processes and 32 GB RAM
Guest: Windows 10 Build 18362
We have a 64-bit test application that allocates blocks of of memory on the heap in a loop. User can decide size of memory block and how many blocks to create. Each byte in memory block is assigned random value.
* Case #1 - Running the guest with 16 GB base memory.
- Execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 25,3 GB of virtual memory (22 GB private memory and 14,8 GB working memory) before throwing a std::bad_alloc exception.
* Case #2 - Running the guest with 16 GB base memory.
- First execute test application to create 4 GB of data in blocks of 1 GB (without any exception)
- Secondly execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 22,1 GB of virtual memory (17,8 GB private memory and 12,1 GB working memory) before throwing a std::bad_alloc exception.
* Case #3 - Running the guest with 4 GB base memory.
- Execute test application to create 30 GB of data in blocks of 1 GB. The test application is able to allocated 13,7 GB of virtual memory (9,4 GB private memory and 3,1 GB working memory) before throwing a std::bad_alloc exception.
Questions
1. What is the relationship between "base memory" value and how much memory a process can allocated in the guest OS? Base memory of 4 GB appear to allow a process to allocated 13 GB. Quadrupling the base memory will "only" allowed a process to allocated 25 GB.
2. Comparing #1 and #2 there appears to be a limit to how much memory the OS can allocated. Is that correct? How can I determine this limit?
3. Other posts mention that Virtual Box uses MmAllocateContiguousMemory API. What is the relationship between the value used in this API and "base memory"? How can I determine which value is used in the API?