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(
1908919089 page,
1909019090 .{
1909119091 // Required when calling NtCreateSection with a file handle, otherwise
19092 // this call will fail with INVALID_PARAMETER. The higher level
19092 // this call will fail with INVALID_PARAMETER_6. The higher level
1909319093 // `CreateFileMapping` function will set this bit for you when it
1909419094 // calls NtCreateSection.
1909519095 .COMMIT = true,
......@@ -19140,11 +19140,13 @@ fn createFileMap(
1914019140 .TO_WORKING_SET = false,
1914119141 },
1914219142 };
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:
1914419144 // https://github.com/microsoft/Windows-Dev-Performance/issues/108
1914519145 //
19146 // We still call it, though, to signal the intention of doing something useful.
19147 // It doesn't appear to make anything *worse*, so there's no harm in doing so.
19146 // However, through testing it has been shown that, if the mapped file is not
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.
1914819150 switch (windows.ntdll.NtSetInformationVirtualMemory(
1914919151 windows.current_process,
1915019152 .Prefetch,