I am reading < Windows via C/C++ > and here's some quotation.
When a process is created and given its address space, the bulk of this usable address space is free, or unallocated. To use portions of this address space, you must allocate regions within it by calling VirtualAlloc. The act of allocating a region is called reserving.
To use a reserved region of address space, you must allocate physical storage and then map this storage to the reserved region. This process is called committing physical storage.
After you have reserved a region, you need to commit physical storage to the region before you can access the memory addresses contained within it. The system allocates physical storage committed to a region from the system's paging file.
Here are a couple of questions:
Why do we need to follow the reserve-comit paradigm when using memory? i.e. Why do we need to follow this 2-step paradigm instead of allocating some physical memory directly and use it?
If the the physical storage committed to a region is allocated from the system's paging file, why do we need the RAM (sounds ridiculous)? In my opinion, an address space region should be mapped to RAM (through the paging mechanism), and the RAM pages should be backed by the paging file.
Maybe this question could be answered by explaing the following 2 aspects:
What does reserving do?
What does committing do?
It is the following quotation from < Windows via C/C++ 5th edition > that makes me puzzled.
...It is best to think of physical storage as data stored in a paging file on a disk drive. So when an application commits physical storage to a region of address space by calling the VirtualAlloc function, space is actually allocated from a file on the hard disk.
After you have reserved a region, you need to commit physical storage to the region before you can access the memory addresses contained within it. The system allocates physical storage committed to a region from the system's paging file.
So, where is the RAM? What if I configure my machine to have no page file?
reserving memory means reserving virtaul address space for future purposes. it doesn't associated with Physical RAM (mapped to RAM Addresses). where as committed memory means it will be associated with actual RAM so that you can store data in it.
Committed memory is the amount of virtual memory reserved for a process and it appears Windows 10 is more greedy with committed memory than previous versions of windows. The amount of virtual memory available is the sum of physical memory and the pagefile size.
Committed memory is the memory you have in your computer plus the page file. It looks like sometimes programs use too much memory and made windows store some things in the pagefile. The pagefile wasn't big enough to fit all the memory windows was storing in it, so it had to increase its size.
The whole point of reserving pages is to ensure that contiguous address space is available for some task. For example, we want the stack to able to grow to 1MB, but we don't want to commit all of that memory because it won't actually be used yet. So we reserve 1MB of pages, but commit a small amount, like 64kB. By setting up a guard page at the end of the committed region, we can detect when we need to commit more memory.
Committing memory is the act of mapping some kind of storage to a page. This can be located in physical RAM, where it is part of the working set, or in the pagefile. It can also be mapped in or private memory. NtAllocateVirtualMemory/VirtualAlloc can reserve and commit at the same time, for convenience.
EDIT for updated question: When you commit pages, that is charged against the process pagefile quota / system-wide commitment limit. This limit is determined by the amount of physical RAM available and the size of the pagefile. This doesn't actually mean the pages are stored in, or written to the pagefile. They may be if memory is low, but otherwise pages are mostly kept in physical memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With