authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-09-28 18:00:39-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-09-28 18:00:39-07:00
logdd144a19881d94b2060e3596057199c71137cad3
tree68ba65d742bb48d53376798757bf64c82665dffc
parent070294b36ca0922aaffdc0b7c669b189f5f147c1

Threaded.createFileMap: Update comments to reflect Windows prefetch efficacy findings

With a test case that (1) calls createFileMap on a 250MiB text file, and (2) reads every byte in the mapped region looking for `\n`, hard page faults were eliminated in the `populate = true` case. `rammap -Et` is used to clear the relevant Windows cache. ``` > rammap -Et > bench-no-populate.exe .{ .page = 1090, .hard = 0 } // initial count .{ .page = 1112, .hard = 0 } // after createFileMap .{ .page = 1114, .hard = 0 } // after 1s sleep 4194304 newlines in the file .{ .page = 66779, .hard = 255 } > rammap -Et > bench-populate.exe .{ .page = 1093, .hard = 0 } // initial count .{ .page = 1242, .hard = 0 } // after createFileMap .{ .page = 1244, .hard = 0 } // after 1s sleep 4194304 newlines in the file .{ .page = 66782, .hard = 1 } ``` More details are in https://codeberg.org/ziglang/zig/pulls/36964

1 files changed, 6 insertions(+), 4 deletions(-)

lib/std/Io/Threaded.zig+6-4
...@@ -19089,7 +19089,7 @@ fn createFileMap(...@@ -19089,7 +19089,7 @@ fn createFileMap(
19089 page,19089 page,
19090 .{19090 .{
19091 // Required when calling NtCreateSection with a file handle, otherwise19091 // Required when calling NtCreateSection with a file handle, otherwise
19092 // this call will fail with INVALID_PARAMETER. The higher level19092 // this call will fail with INVALID_PARAMETER_6. The higher level
19093 // `CreateFileMapping` function will set this bit for you when it19093 // `CreateFileMapping` function will set this bit for you when it
19094 // calls NtCreateSection.19094 // calls NtCreateSection.
19095 .COMMIT = true,19095 .COMMIT = true,
...@@ -19140,11 +19140,13 @@ fn createFileMap(...@@ -19140,11 +19140,13 @@ fn createFileMap(
19140 .TO_WORKING_SET = false,19140 .TO_WORKING_SET = false,
19141 },19141 },
19142 };19142 };
19143 // It appears that this is effectively a no-op, as it doesn't decrease page/hard faults.19143 // There has been some doubt about the efficacy of this function:
19144 // https://github.com/microsoft/Windows-Dev-Performance/issues/10819144 // https://github.com/microsoft/Windows-Dev-Performance/issues/108
19145 //19145 //
19146 // We still call it, though, to signal the intention of doing something useful.19146 // However, through testing it has been shown that, if the mapped file is not
19147 // It doesn't appear to make anything *worse*, so there's no harm in doing so.19147 // in the cache, calling this function can turn what might otherwise be hard
19148 // faults into soft faults. Either way, it's still good to call it in order to
19149 // accurately reflect our intent.
19148 switch (windows.ntdll.NtSetInformationVirtualMemory(19150 switch (windows.ntdll.NtSetInformationVirtualMemory(
19149 windows.current_process,19151 windows.current_process,
19150 .Prefetch,19152 .Prefetch,