I tested PrefetchVirtualMemory to minimize page faults when creating a file mapping, and measured the performance (compiler ticks using __rdtsc() intrinsic) and the actual count of page faults (using GetProcessMemoryInfo) when processing files, with and without a call to PrefetchVirtualMemory.
To my surprise, PrefetchVirtualMemory does not work as advertise and does not do it's only job, which was to actually fetch the memory from disk as efficiently as possible to minimize page faults.
I used the following process for testing, loading a range of file sizes (I'll share my results for a ~500MB file):
I opened a file handle, created a memory map and a view of the whole file, then I processed the whole file making sure to touch every page of the allocated view.
Then I repeated the process, and called PrefetchVirtualMemory on the view before processing the file.
I got the exact same page fault count overall in both cases, and to add insult to injury, the performance was slightly worse with PrefetchVirtualMemory, making the whole thing useless as it is its only job.
Windows Build Number
10.0.19044.0
Processor Architecture
AMD64
Memory
16GB
Storage Type, free / capacity
SSD 512GB
Relevant apps installed
Windows
Traces collected via Feedback Hub
N/A
Isssue description
I tested PrefetchVirtualMemory to minimize page faults when creating a file mapping, and measured the performance (compiler ticks using __rdtsc() intrinsic) and the actual count of page faults (using GetProcessMemoryInfo) when processing files, with and without a call to PrefetchVirtualMemory.
To my surprise, PrefetchVirtualMemory does not work as advertise and does not do it's only job, which was to actually fetch the memory from disk as efficiently as possible to minimize page faults.
I used the following process for testing, loading a range of file sizes (I'll share my results for a ~500MB file): I opened a file handle, created a memory map and a view of the whole file, then I processed the whole file making sure to touch every page of the allocated view. Then I repeated the process, and called PrefetchVirtualMemory on the view before processing the file. I got the exact same page fault count overall in both cases, and to add insult to injury, the performance was slightly worse with PrefetchVirtualMemory, making the whole thing useless as it is its only job.
Steps to reproduce
Running the following code on windows:
Expected Behavior
Actual Behavior