59

I understand that memory has to be reserved before being committed. And when it's reserved, no other process can use it. However reserved memory does not count against available RAM. But shouldn't it? Because if no one else can use it, then what good is it being "available"?

Or is there some bigger difference?

5

4 Answers 4

55

In the context of Win32, "reserved" means that the address space is allocated within the process that requested it. This may be used, for example, to reserve space for a large buffer that's not all needed right away, but when it's needed it would need to be contiguous.

Reserving memory does not interact with other processes at all, since each process has its own private address space. So the statement that "when it's reserved, no other process can use it" is meaningless, since processes can't normally allocate memory in the address space of another process anyway.

When the reserved pages are requested to be committed (backing store allocated for them), that operation can potentially fail due to lack of physical memory (or pagefile).

8
  • 1
    "backing store allocated for them": Do you mean when data that's only stored in cache is called reserved, and when it's written to RAM or pagefile it's called committed?
    – idbrii
    Jul 27, 2011 at 20:50
  • 13
    @pydave: No, "cache" and "reserved" are unrelated concepts. Reserving memory is sort of like a property developer claiming land that will later contain houses. There's nothing there yet, but nobody else can build houses there either. Committing is actually building the houses and setting up the infrastructure like electricity and sewer. On the other hand, cache is an optimisation to make CPUs run faster, all data is still stored somewhere in RAM. Jul 27, 2011 at 22:24
  • 3
    So does writing data to a memory page cause that page to be committed? (Then the difference between reserved and committed is that reserved has been allocated, but committed has been used.)
    – idbrii
    Jul 28, 2011 at 1:37
  • 8
    @pydave: In Windows, committing memory is a separate step that must happen before trying to write to the memory (writing to uncommitted pages will generally cause a page fault). See the VirtualAlloc function for more info. Jul 28, 2011 at 1:45
  • 1
    @idbrii No. Reserving and committing have nothing to do with allocation of physical memory, ie RAM - only virtual. The first memory access to a committed page is what causes a page of RAM to be allocated for it and associated with it. This is why committed can be so much larger than the physical usage - many apps commit a lot more than they end up actually using. Jun 23, 2017 at 8:29
16

I like to view Reserved as booking the address space so that no one else can allocate it (but I can't use memory at that address because it is not yet available). And Committed as mapping that address space to the physical memory so that it can be used.

Why would I want to reserve? Why not just get committed memory? There are several reasons I have in mind:

  1. Some application needs a specific address range, say from 0x400000 to 0x600000, but does not need the memory for storing anything. It is used to trap memory access. E.g., if some code accesses such area, it will be caught. (Useful for some reason.)

  2. Some thread needs to store progressively expanding data. And the data needs to be in one contiguous chunk of memory. It is preferred not to commit large physical memory at one go because it is not needed and would be such a waste. The memory can be utilized by some other threads first. The physical memory is committed only on demand.

1
  • 2
    For 2, unless that data is touched, no space is actually allocated (which also includes page table structures such as PTEs) in the working set, however the paging file(s) will grow to guarantee that the memory can be used when required. Which would indeed be quite an inefficient use of disk space. Apr 30, 2019 at 19:35
11

Process Virtual Memory (Address Space ) and Actual RAM are both different. you can have 512MB physical RAM but still your process can address 4GB virtual address space(2GB Userspace) Every address in a process can be thought of as either free, reserved, or committed at any given time.

A process begins with all addresses free, meaning they are free to be committed to memory or reserved for future use.Before any free address may be used, it must first be allocated as reserved OR committed. But doesn't need to be reserved in order for it to be committed.

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.

http://msdn.microsoft.com/en-us/library/ms810627.aspx

1
  • 5
    A quibble: Virtual memory doesn't need to be reserved as a separate step before it's committed. VirtualAlloc can reserve and commit in one call. But the "reserve" does have to be done. Also, committing does not actually "allocate" RAM; only a subsequent page fault does that. I (tried to?) edit "it will be associated" to "it can be associated" accordingly. I would also add the following sentence to the end: "Actual RAM isn't allocated until you access the committed region, and is done on a page-by-page basis." And one other thing: Another way to use free pages is for mapped memory. Jun 23, 2017 at 14:39
0

I think the simplest answer is that:

  • you reserve memory in virtual address space, so that no other part of code within the same process gets it
  • you commit memory to physical RAM/swap so that no other process gets it

So for example if a process has mem limit of 1 GB and does malloc reserve of 1 GB at start it cannot malloc any more even though process memory usage at OS level (commited memory) is nearly 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.