2 ms·
Yes, 1,167 pagefaults for the read() version and 66,704 pagefaults for the mmap() version. With MAP_POPULATE it's back down to 1,167 faults and it goes a bit fa
by scaramanga 6y ago
Yes, 1,167 pagefaults for the read() version and 66,704 pagefaults for the mmap() version. With MAP_POPULATE it's back down to 1,167 faults and it goes a bit faster.
My libc is using rep/mov, same as the kernel, however. So I can't conclude that AVX memcpy is the win.
From the profile of readsyscall version I see this:
42.12% fa [kernel.kallsyms] [k] copy_user_enhanced_fast_string
14.45% fa [kernel.kallsyms] [k] syscall_exit_to_user_mode
11.00% fa [kernel.kallsyms] [k] find_get_entry
6.28% fa [kernel.kallsyms] [k] syscall_return_via_sysret
5.14% fa [kernel.kallsyms] [k] entry_SYSCALL_64
nearly 15% of the time is spent on a single verw instruction. Spectre mitigations.
When I reboot with mitigations=off, sure enough, the difference goes away and read() and mmap() perform identically.
What OP has discovered is that spectre mitigations make syscalls enough slower than pagefaults that what used to be a slower way to do things is now faster.
If you want the mmap version to perform faster when spectre mitigations are off, you need to use MAP_POPULATE.