Partager via


Memory Concepts on Windows

Understanding the Memory concepts on Windows is an important part to note performance problems and resolve them.

Many times the term of Physical memory can be confused with the concept of Virtual memory:

Virtual Memory and Physical Memory

The physical memory (RAM) is managed directly by the Windows Memory Manager. Every process has its own memory space and private memory address which can only be accessed by this process. The exception is the shared memory, which can be accessed by many processes.

The physical memory has 3 states: Free, Reserved and Committed. On Free state the memory is free and inaccessible, on a Reserved State the memory is reserved to an specific process, and on a committed state the reserved memory is been used by the process and is been backed up by physical memory. For the memory to be free again, the process needs to free its reserved memory.

Another part of the Physical memory is the page file which is by default located on the system drive. This file (pagefile.sys), is used as RAM memory, so in case a process needs a memory space on RAM and there isn’t availability, the Windows Memory Manager will make some room by moving data that is not in used to the page file, when this data its needed again, a reverse process will take place putting the data from the page file on RAM.

Now, the Virtual Memory is a technique that allows a process to have the impression that is using a contiguous memory space, so if there where fragmentation will be transparent to the process. We can define the used Virtual Memory as the RAM memory + Page File used (always on committed state),

It’s also convenient to talk about Virtual Address Space, each process has a private virtual space of memory also call Virtual Address Space or VAS, this mechanism prevent the processes to steps into each other memory space, and it’s the VAS space that you can overlook when finding memory problems.

VAS is used on a memory mapping mechanism where physical memory (RAM and page file) is map to VAS by the Operating System. This way you can restrict direct access to physical memory and isolate each process.

VAS and technology used:

  • ON 32 bits, VAS is limited to 4Gb on 2 regions of 2GB each: User Mode and Kernel Mode.
  • On Windows on Windows (WoW), which implies as 64 bits Operating System and a 32 bits application, VAS is as big as 4Gb also, however because the kernel is 64 bits it use a different VAS space than the 32 bits applications, this is why  the User Mode is 4Gb on WoW.
  • On 64 bits, VAS is limited to 16 Tb (Terabytes), been 8Tb for Kernel Mode and 8Tb for User Mode (7Tb on IA64)

VAS Components

  • The User mode is the VAS portion the applications process will use, while the Kernel Mode, is the VAS portion that the operating system use to run DLLs, system files and more.
  • The VAS Kernel Mode it’s divided on 4 parts: Paged Pool, Non-Paged Pool, PTEs and system cache for drivers, Operating system kernel, etc.

The kernel mode is an important part when doing a performance analysis on a server; we will see this on future posts.

Memory tweaks

The memory tweaks for 32 bits architectures are: 3GB, PAE and AWE

Usually the 3GB and PAE switch are mistaken, they are both added on the boot.ini (Windows 2003) or the bcdedit command (Windows 2008/R2), but have different behaviors.

  • /3GB is used to modify the VAS User Mode, to make it 3Gb big instead of 2Gb, this implies that the kernel mode will be 1Gb big, this it’s not necessary on WoW, because the User Mode will have the 4Gb for himself.
  • /PAE is used to allow the CPU to address more Physical Memory, and more memory addresses, this is done by allowing 36 bits (2^36=68.719.476.736(64Gb)) pointers instead of 32 bits(2^32=4.294.967.296 (4Gb))  pointers.
  • AWE is commonly used on SQL Server; this allows it to access more than 4Gb of RAM until 64Gb. This works using some specific APIs to address memory using a windowing mechanism. You will need to enable “Lock Pages in Memory” right for the SQL Server account.

These switches are only useful on 32 bits architectures, these switches are not needed on 64 bits architecture.

 

“The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of Microsoft”