What makes the virtual memory expand and what makes virtual memory contract, if possible?
Trying to understand the uses of virtual memory and what makes it expand and contract in Windows 11
What makes the virtual memory expand and what makes virtual memory contract, if possible?
Trying to understand the uses of virtual memory and what makes it expand and contract in Windows 11
Virtual memory is usually pre-allocated and contiguous on the disk, as it needs to be fast.
Under Windows, the size of virtual memory is defined via the settings of Initial and Maximum. Changing this definition causes the page-file to be reallocated on the disk to the specified Initial size after a reboot.
If more virtual memory was required than is allocated, the page-file may need to be increased, but it cannot be reallocated on the disk to a bigger size because it already contains data, so extensions are added to it which might not be contiguous.
Once Windows is rebooted, its size returns to the Initial size, but not immediately. Windows will keep the extended page-file for some time, and will shrink it back to the Initial size when it decides that a larger file is no longer required.
For a user testimony, see this answer.
In Windows, it's up to the user. The default on install has been to allow the Initial size and Maximum size to differ, so pagefile.sys continually grows and shrinks.
Personally, I prefer to set the pagefile.sys to a constant size to reduce fragmentation by setting Initial size and Maximum size to the same value.
And then there is swapfile.sys, which I believe is set to a fixed size.