Search This Blog

2020-05-05

Windows: Optimal Virtual Memory Paging Configuration with Reasoning

roduct: Microsoft Windows
Version: 7, 10, 2016 or higher

As of today, maximum of RAM a Windows machine, or more technically correct is motherboard, that can handle is 1TB.  It is often easy to find a server motherboard that can handle 512GB RAM, while workstation motherboard to support 256GB RAM. For example, CAD$500 ASUS Prime X299-A II with 256GB RAM max, Intel X299 chipset,  supports Intel Core i9 10980XE (18 core CPU).

The virtual memory (pagefile) configuration for Windows remains a question as there are so many old books or even MS online documentation themselves are not updated to show the proper Windows virtual memory configuration with analysis.

Following are the keywords I will use in this post to avoid confusion:
  • RAM - physical memory
  • Pagefile - virtual memory that stores in disk, without the physical RAM portion
  • Virtual memory - combination of RAM + pagefile
  • vRAM - physical memory allocated to the virtual machine. Actual memory allocation is unknown and could resides in physical RAM, VMware disk file, or pagefile
  • Paging - Windows to swap the RAM to/from pagefile which will read/write to the pagefile.sys
This post is mainly to address pagefile configuration and performance for 64-bit Windows.

Recommended Pagefile from Docs

Firstly, let's get the max supported RAM for modern OS to be cleared:

  • Windows 10 Enterprise Edition can support 6TB of RAM
  • Windows Server 2016 can support 24TB

Reference:
MS Memory Limits for Windows:
https://docs.microsoft.com/en-us/windows/win32/memory/memory-limits-for-windows-releases#physical-memory-limits-windows-10

Typical pagefile recommendation from old documentation typically ask to set it to to 1.5x or 3x RAM is so outdated that with above max RAM limit, following will be the "recommended" 1.5x (no, it is not) pagefile setting:

  • Windows 7 - 6TB + 3TB = 9TB
  • Windows Server 2016 - 24 TB + 12TB = 36TB
Let's consider current supported RAM size of 512GB (as 1TB machine is rare/limited), "recommended" (no, it is not) pagesize setting are:
  • Pagesize: 512GB + 256GB = 768GB
Let's list the pagesize for typical home users:
  • 256GB RAM => 384GB pagefile
  • 128GB RAM => 192GB pagefile
  • 64GB RAM => 96GB pagefile
  • 32GB RAM => 48GB pagefile
  • 16GB RAM => 24GB pagefile
Some forums or docs are more "reasonable" to recommend setting the pagefile size to same size as the RAM, which becomes pagefile setting below, which is still too large
  • 256GB RAM => 256GB pagefile
  • 128GB RAM => 128GB pagefile
  • 64GB RAM => 64GB pagefile
  • 32GB RAM => 32GB pagefile
  • 16GB RAM => 16GB pagefile
Above "default" recommendation is from 5 yrs old MS doc for Windows 7, as well as many reputable Windows/Linux forums.  I do not recommend setting pagefile to GB size, except for Windows crash dump purpose.

According to following most recent MS Windows 10 online doc, its most up to date recommendation now is 4GB max, and not RAM size, or 1.5x RAM. This is more reasonable, yet I don't totally agree, except for Windows crash dump purpose.

Title: How to determine the appropriate page file size for 64-bit versions of Windows
Last Update: 2019-08-28
URL: https://docs.microsoft.com/en-us/windows/client-management/determine-appropriate-page-file-size

Understanding of Pagefile Performance Degradation

Performance for me is often a time base performance tuning for same amount of workload.  None of the Windows document, forums, or experts explains the pagefile performance to actual performance degradation in term of time and throughput.  Therefore, all of them are missing the points of performance tuning.
  • How much performance degradation when RAM paging to 1GB of pagefile?
  • How much performance degradation when RAM paging to 1MB of pagefile?
  • How fast to write 1GB of pagefile to disk?
  • How fast to read 1GB of pagefile from disk?
  • How much overhead in term of time to page out 1 virtual memory page into pagefile?
  • How fast the disk?
You will not find the answer to above fundamental questions, yet people start telling to configure pagefile to recommended size of 4GB, 1x RAM, 1.5x RAM, or worst 3x RAM.

Disk paging operation is a random access disk/file I/O operation, and not sequential access. Random access I/O will be much slower than sequential access I/O (easily 90% reduction). File can only be read/written as 1 cluster large each time, which is default to 4KB for NTFS.  Let's take the general home users Seagate BarraCuda 8TB ST8000DM004 with 5400rpm, 190MB/s to illustrate:

Avg 4K random read: 1.3MB/s
Avg 4K random write: 5.2MB/s
Min 4K random read: 0.4MB/s
Min 4K random write: 2.8MB/s
Avg sequential read: 72MB/s
Avg sequential write: 79.2MB/s


As disk paging is only a random 4K read/write operation, I only throw sequential read/write metrics above for comparison as manufactures often only advertise their max read/write performance, which is the peak value for sequential read/write. You are see that Seagate brochure shown the disk can perform 190MB/s, but from testers, the avg sequential read/write is 72/79MB/s.  For pagefile, I will take the avg value of 1.3MB/s read, 5.2MB/s write to further reveal pagefile performance degradation, which is a fair value, and will include its worst performance of 0.4MB/s.

Let's plug above figure into a scenario that Windows is doing paging of 16MB, 128MB, 256MB, 1GB, 4GB, 16GB.  Following is the time it takes for the disk alone, without considering paging overhead time
Page Size Min read time=0.4MB/s Avg read time=1.3MB/s Min write time=2.8MB/s Avg write time=5.2MB/s
16MB 40 12.30769 5.714286 3.076923
128MB 320 98.46154 45.71429 24.61538
256MB 640 196.9231 91.42857 49.23077
1GB 2560 787.6923 365.7143 196.9231
4GB 10240 3150.769 1462.857 787.6923
16GB 40960 12603.08 5851.429 3150.769

Imagine to page 16MB out, the file write to pagefile.sys alone takes 3 - 5.7 sec.  Windows OS has extra overhead to update the kernel which takes several more seconds.  Worst timing for 16MB is 40sec, plus paging overhead time.

Assuming the overhead time of 16MB page size is 1 sec, 1GB page size will introduce 64 sec on top of 196-2560 sec.

Now imagine that Windows OS consistently need to page 16MB in and out that takes 3-40 sec each round.  The application will pause for same amount of time as RAM still writing or reading to pagefile, and application cannot run without RAM.

Without diving further into Windows OS paging overhead that runs on RAM and CPU, you can see that above disk performance alone is unacceptable for desktop applications, and not to mention server applications.

Pagefile with NVMe SSD

This post won't be complete without using the fastest storage technology which is NVMe SSD with PCI card speed of GB/s.

Let's pick Western Digital fastest NVMe SSD WDS200T3XHC

Let's use following benchmark again:

Avg 4K random read: 35.9MB/s
Avg 4K random write: 158MB/s
Min 4K random read: 27.6MB/s
Min 4K random write: 85.5MB/s

Page Size Min read time=27.6MB/s Avg read time=35.9MB/s Min write time=85.5MB/s Avg write time=158MB/s
16MB 0.579710145 0.445682451 0.187134503 0.101265823
128MB 4.637681159 3.56545961 1.497076023 0.810126582
256MB 9.275362319 7.13091922 2.994152047 1.620253165
1GB 37.10144928 28.52367688 11.97660819 6.481012658
4GB 148.4057971 114.0947075 47.90643275 25.92405063
16GB 593.6231884 456.3788301 191.625731 103.6962025

Now you might pick 16MB pagefile and said it is fast, but considering OS paging overhead, this is a couple seconds operation. When you "move" up to 128MB pagefile, the performance is equally not acceptable without paging overhead time put into consideration.  It is completely a joke to have 4GB paging.

I have tried this out with SSD for 16MB paging, and the performance with actual OS paging overhead is just not acceptable for even web browser as it took more than 30 sec.  So it is certainly not acceptable to use for Office, PhotoShop, or server applications.  My test case is using Windows 7 with 2GB RAM, pagefile 16MB max, installed latest Win 7 patch and MS Office.  Open up YouTube in browser will easily used up all RAM, and trigger paging.

Pagefile Virtual Memory Recommendation

With active pagefile size 16MB or larger, I don't see the point of 3-40 seconds pause for any application, as this is unusable.  Pagefile size should not relate to RAM size anymore, and should set to none, or if you skeptical then set to 16MB.  So when OS paging to pagefile, it can page as much as 16MB, and application started to degrade with 3-40 sec delay or longer (typically more than 1 min delay).

I recommend not to enable pagefile at all for Windows OS that you do not need to capture system crash (also known as "bug check," "Stop error," "crash dump).

If you needs to capture system crash, then set max size to 32GB as per above MS link, or if RAM is less than 32GB, then to RAM + 257MB to accomodate complete memory dump.

No comments: