Windows 11 manages memory by pairing physical random-access memory (RAM) with secondary backing storage on solid-state drives (SSDs) or hard drives through a system file named pagefile.sys. When running memory-intensive workloads such as video rendering, virtual machines, or large machine learning datasets, proper paging file configuration prevents out-of-memory crashes and application freezes. While Windows provides a legacy System Properties GUI for adjustments, managing pagefiles across automated deployments or server instances is far faster via PowerShell.
Understanding Virtual Memory and Pagefile Mechanics
The Windows virtual memory manager moves modified memory pages between physical RAM and disk storage based on access patterns:
- pagefile.sys: The primary hidden system file holding inactive or overflow pages of committed virtual memory.
- System-Managed Sizing: By default, Windows dynamically expands and contracts the pagefile depending on active RAM pressure and available disk volume space.
- Static Pagefile Allocations: For high-performance workstations and gaming PCs, locking the Initial Size and Maximum Size to identical values eliminates disk fragmentation caused by dynamic file resizing.
- Multi-Drive Optimization: Moving the primary pagefile away from your system OS partition onto a secondary high-speed NVMe drive reduces I/O contention on the boot volume.
Inspecting Current Pagefile Usage and Configuration
To inspect your current virtual memory status in an elevated PowerShell session:
- Right-click the Start button on Windows 11 and choose Terminal (Admin) or PowerShell (Admin).
- Confirm the UAC elevation prompt.
- Query the Common Information Model (CIM) for live pagefile usage:
Get-CimInstance Win32_PageFileUsage | Select-Object Name, AllocatedBaseSize, CurrentUsage, PeakUsage - The output displays the file path (e.g.,
C:\pagefile.sys) and the storage sizes measured in megabytes (MB). - To verify whether Windows is currently managing the pagefile automatically:
Get-CimInstance Win32_ComputerSystem | Select-Object AutomaticManagedPagefile
Disabling Automatic Pagefile Management
Before configuring custom minimum and maximum sizes, you must disable the automatic management flag on the computer system:
Set-CimInstance -Query "Select * from Win32_ComputerSystem" -Property @{AutomaticManagedPagefile = $False}
Verify that the command executed cleanly by rerunning the check. The AutomaticManagedPagefile property should now return False.
Setting Custom Initial and Maximum Pagefile Sizes
To establish a static custom pagefile (for example, setting an Initial Size of 4096 MB and a Maximum Size of 8192 MB on the C: drive):
- Configure the
Win32_PageFileSettingclass:Set-CimInstance -Query "Select * from Win32_PageFileSetting where Name like 'C:%'" -Property @{InitialSize = 4096; MaximumSize = 8192} - If no pagefile setting object currently exists on the drive, create a new one:
New-CimInstance -ClassName Win32_PageFileSetting -Property @{Name = "C:\pagefile.sys"; InitialSize = 4096; MaximumSize = 8192} - For dedicated workstations with ample RAM (such as 32 GB or 64 GB), setting identical minimum and maximum values (e.g.,
8192and8192) prevents Windows from repeatedly growing the file under load. - Restart your computer to apply the new memory parameters:
Restart-Computer
Moving the Pagefile to a Secondary High-Speed Drive
To relieve disk I/O on your boot drive by relocating paging to a secondary NVMe drive (e.g., drive D:):
- Create the pagefile definition on the secondary drive:
New-CimInstance -ClassName Win32_PageFileSetting -Property @{Name = "D:\pagefile.sys"; InitialSize = 8192; MaximumSize = 16384} - Delete the old pagefile setting on the
C:drive:Get-CimInstance Win32_PageFileSetting | Where-Object {$_.Name -like "C:*"} | Remove-CimInstance - Reboot the system to instantiate the secondary pagefile.
Restoring Automatic Windows-Managed Paging
If you wish to revert to standard Windows dynamic memory management:
Set-CimInstance -Query "Select * from Win32_ComputerSystem" -Property @{AutomaticManagedPagefile = $True}
Windows automatically cleans up manual settings and manages virtual memory across your drives dynamically.