Aug 3, 2006

Virtual memory, physical memory, page file, and 32bit/64bit limitations

Despite the huge amount of documents available on the Net, there are still the same huge amount of misunderstanding of above concepts.

Physical Memory: This is the easiest to under stand. Read it as RAM
Virtual Memory: Addressible space to the OS. It would be much more accurate if we call it Virtual Space
Page File: Due to the expense of RAM, we use disk space as an extension of physical memory.
Page: The allocation unit for memories
Paging Out: When certain criteria are met, an occupied page in RAM will be written to Page File to make space for other process. For example when a page in RAM occupied by a process has not been accessed for a period of time, and another process requests space while there is not free space, Paging Out happens.
Paging In: When a process refers a page that is not in RAM, the page will be Paging In.
4GB Virtual Memory Limit: All 32bit OS will have 4GB Virtual Memory for its processes
4GB Physical Memory Limit: All 32bit computers can address on 4GB RAM if no other technology, such as PAE, is deployed
32bit Windows OS running on 32bit hardware happen to have same Virtual Memory limit and Physical Memory limit, but they are different limits.
Available Memory: It could be one of three things
- Space that is still not used by process in its Virtual Memory
- Space that is still available in Physical Memory (RAM)
- Space that is still available in RAM+Page File

Most of the time, it means Available Physical Memory. But it could often refer to Available Virtual Memory. This is what becomes confusing.
/3GB Switch: By default, 32bit Windows divide the 4GB Virtual Space into two 2GB spaces, one for kernel mode, one for user mode. For applications, such as Exchange, that need a lot space in user mode, you can specify /3GB switch to increase user mode space by 1GB by reducing kernel mode space. This feature is available only on Windows 2000 Advance Edition and higher
PAE: PAE is a technology to extend the RAM space that can be access by a 32bit CPU. It's similar to LBA in hard disk.

So as you can see, you may use up both Virtual Memory and Physical Memory. It could be very confusing as 1) not everyone understands the memory management completely; 2) not all application/OS reports memory allocation errors clearly. But there are a few things you REALLY need to remember:

- If you use up Virtual Memory(again, really it's a space resource only!), it won't help by adding additional RAM. Imaging that if a city is using up its phone numbers, it won't help to have more phones! The only solution will be either reducing the number of users or increasing the length of phone number system)
- If you use up Physical Memory, you can buy more RAM up to the hardware limit. If you have 4GB already on a 32bit computer, you are not getting better to have another 1GB RAM (if PAE is not used).
- If you use up Physical Memory, do a little troubleshooting before rush for more RAM. More than often this is caused by a poor-coded program that leaks memory.

A few important performance counters:
- Memory, committed Bytes: memory that has been allocated for processes ( either those in RAM or those in page file)
- Memory: Pages Input/Sec: how many pages were read from page file into RAM
- Memory: Pages Output/Sec: see above
- Memory, Available MBytes: how much free RAM
- Prcess, Working Set: The number of pageable memory blocks in a process' address space that were recently referenced (i.e. still in physical RAM). When a process references pageable memory that is not currently in its working set, a page fault occurs.
- Paging File, %pagefile in use: this is an indicator if your pagefile has a proper size. It should be 50-75% used.