Maximum memory card allocation size?

My system: Physical memory: 3gb
Windows XP Service Pack 3 (32 bit) Paging file size: 30gb

Purpose: to find the maximum possible size of a memory card that I can allocate on my machine.

When I run the following code to place a 2gb memory card file, the call fails.

handle = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE | SEC_COMMIT, 0, INT_MAX, NULL);

I was very puzzled by this, because I can allocate a memory card file up to the size of a 30gb system page file, constantly calling CreateFileMapping with 100mb at a time.

After restarting the computer and restarting the application, which requests a 2gb file with memory mapping in CreateFileMapping, it works and it returns a valid handle. So it bothers me a bit, what the hell is going on under the hood with windows?

So, the situation is this, I can create many small files with memory mapping using the entire system page file (30gb), but when I request one 2gb allocation, the call fails. When you restart the machine and start the same application, the call will be successful!

Some notes:
1) A file with memory mapping is not loaded into the proccess virtual address space, the file is not yet displayed.
2) The OS can allocate small memory files of 100 MB per 30 gb of system page file!

At the moment, I have come to the conclusion that the Windows XP SP3 virtual memory manager (32-bit) cannot successfully reserve the requested 2gb in the system page file, and then crash due to fragmentation of the system memory (it looks like it needs to reserve the continuation of memory allocation, even if the page file is 4kb each). After the reboot, I assume that the fragmentation of the system memory is less, which allows the same call to succeed and allocate a file with a 2 GB memory map.

I conducted several experiments, after starting the machine during the day, I launched a small application that would allocate a file with 300 MB memory and then released it. Then it will increase the size by 1 mb and try again. Finally, he stops at around 700 MB and reports (insufficient system resources). Then I will go through and close each application, and this, in turn, will stop error messages and finally continue to allocate a file with a memory display of 3.5 GB in size!

So my question is: what is going on here? There must be some type of memory fragmentation between the virtual memory manager, since allocating files with 100 MB of memory will consume up to 30 GB of the system page file (commit restriction).

Update
The conclusion is that if you are going to create a large file with memory mapping supported by the system page file with INVALID_HANDLE_VALUE, then the system page file (swap file) must be resized to the required size and be in a fragmented state for large distributions> 2gb ! Although with a heavy load of IO, it can still fail. To get around all these problems, you can create your own file with the required size (I made 1tb) and a memory card for this file.

Final update
I ran the same tests in a Windows 7 window, and, to my surprise, it works every time (up to the size of the system page file) without touching anything. Therefore, I think this is just a mistake, that large memory allocations can fail more often in Windows XP than in Windows 7.

+7
source share
3 answers

The problem is file fragmentation. Physical memory (RAM) is not connected here. In a virtual memory system, “memory” is allocated from the file system. Physical memory is simply an optimization to speed up memory access.

When requesting a file with memory mapping with write access, the system must have a file with adjacent pages. The system’s page file is often fragmented. If your disk is well defragmented, you can create a large file with memory mapping using the file of your choice (rather than the system page file).

So, if you really need a file with 2 GB of memory, you need to create it on disk during installation. This shifts the problem of creating an adjacent 2GB file for installation, but you should be fine after creating it.

+5
source

So my question is: what is going on here? There must be some type of memory between the virtual memory manager, because allocating files with 100 MB of memory will consume up to 30 GB of the system page file (commit restriction).

Sounds right. If you do not need large, continuous chunks of memory, do not ask for them if you can get the same amount of memory in small chunks.

To find the maximum possible size of a memory card, I can select on my machine.

  • Try with size X.
  • If this fails, try with an X / 2 size and try again.

This gives you a piece at runtime, perhaps not the largest possible piece, but 2 times.

+3
source

Allows you to take the position of a Windows developer. Suppose some users follow these steps:

  • Create a memory mapping.
  • Filling some memory with sensitive data
  • Discard from file
  • Continue using memory
  • Windows needs to unload these pages to perform important tasks.

Resolution - The displayed memory must be moved for sharing. But this does not mean that the displayed cards will be replaced.

0
source

All Articles