Understanding and Configuring Private Memory vs Virtual Memory Limits in IIS 7: A Performance Optimization Guide


1 views

When configuring IIS 7 application pools, you'll encounter two critical memory thresholds:

  • Private Memory Limit (Private Bytes):
    The actual physical RAM allocated to the worker process (w3wp.exe), including heap allocations and managed memory in .NET applications. This is measured in KB.
  • Virtual Memory Limit:
    The total address space available to the process (physical RAM + page file), including DLLs, executable code, and memory-mapped files. Also measured in KB.

Private Memory Limit is what you should configure when you want to:



    
    />

Use this when your primary concern is preventing a single application from consuming too much server RAM.

Virtual Memory Limit becomes important when:



    
    />

Configure this when dealing with memory leaks in native code components or when applications use memory-mapped files.

For a .NET web application with known memory requirements:



    

Use Performance Monitor to track these counters:

  • \Process(w3wp#n)\Private Bytes
  • \Process(w3wp#n)\Virtual Bytes

When either limit is reached, IIS will recycle the worker process. Check Windows Event Log for event ID 5117 (private memory) or 5119 (virtual memory).

For comprehensive IIS 7 settings documentation:


When configuring memory limits in IIS 7, it's crucial to understand the distinction between private memory and virtual memory:

  • Private Memory Limit refers to the physical RAM (working set) allocated exclusively to the worker process
  • Virtual Memory Limit includes both physical memory and paged memory (address space including disk-backed pages)

For controlling physical memory consumption, you should set the Private Memory Limit. This directly restricts how much RAM your application can use. The Virtual Memory Limit is better suited for:

  • Preventing memory leaks from consuming all available address space
  • Managing 32-bit applications that might hit the 2GB/3GB address space limit
  • Controlling overall memory footprint including paged memory

Here's how to set these limits in the application pool's configuration file (applicationHost.config):

<system.applicationHost>
    <applicationPools>
        <add name="MyAppPool">
            <recycling>
                <privateMemory limit="400000" /> <!-- 400MB -->
                <virtualMemory limit="1000000" /> <!-- 1000MB -->
            </recycling>
            <processModel privateMemoryLimit="400000" />
        </add>
    </applicationPools>
</system.applicationHost>

After setting these limits, monitor your application's behavior using Performance Monitor:

# Key performance counters to track:
- Process\Private Bytes
- Process\Virtual Bytes
- Process\Working Set
- .NET CLR Memory\# Bytes in all Heaps
  • For modern 64-bit applications, focus primarily on Private Memory Limit
  • Set Virtual Memory Limit about 2-3 times higher than Private Memory Limit
  • Consider using Application Initialization to pre-load memory-intensive applications
  • Regularly review memory usage patterns before setting hard limits

For complete IIS 7 configuration reference: