fix(libkernel): serialize Windows vectored file transfers #5833
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5833"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T12:54:23Z.
What
On Windows,
TransferIovecsreleases the descriptor's shared position lock between iovec chunks. Concurrentwritevcalls through duplicated descriptors can interleave parts of one record;readvcan split a record across readers. On main2aad30682, the regression finds record label 1 mixed with label 256 at byte 64 of an actual file.Hold the existing position lock across the whole vector operation. Extract the native transfer bodies so the scalar wrappers retain their locking and the vector loop can call them while already holding the lock. This also covers
preadv/pwritevand preserves the shared file cursor. The locking reference is POSIX thread interactions with regular file operations; these are reference semantics, not console measurements.Update the existing technical-debt entry to describe serialization across a descriptor's aliases and the remaining limit: independent opens and other processes do not share this lock. Socket and random-device paths keep their existing transfer mechanisms.
The overlapping concurrent
preadv/pwritevphase inguest_file_vectorruns only on Windows, where the shared lock guarantees whole records. Concurrentwritev/readvand the existing sequential positioned-I/O checks continue to run on both platforms.Tested
I validated head
cbb6ddc885c07c8a3c6ff3542505e9c30ff6b51c, based on mainf633042dfdf0d51f4af58fafbade3fa9d47fd169, using real guest file APIs and file contents.Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0, Release, bundled dependencies. Hardware: AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER.
guest_file_vector,guest_posix_scalar_io,guest_positioned_race,guest_kernel_fcntl,guest_filesystem,file_position,file_streams, andguest_shm_open.guest_file_vectorpassed ten consecutive runs, including the overlapping positioned phase. Four threads write and read 1,024 distinct 64-byte records through duplicated descriptors, each split across 32 iovecs. Every record remains whole and appears exactly once; positioned transfers leave the shared cursor unchanged.Ubuntu 24.04.5 LTS x86-64 in VirtualBox, GCC 13.3.0, Release, bundled dependencies. The VM has 8 vCPUs and 8 GB RAM on the same host.
guest_file_vectorpassed ten consecutive runs. The overlapping positioned phase is excluded on Linux.guest_file_vectorConventions and whitespace checks passed. The original Windows defect was reproduced on main
2aad30682withwritev interleaved a record at byte 64: 1 versus 256. No speed improvement is claimed. I did not run a title, the full Linux build or the full hosted CI suite.Integration with open PRs
The agreement with #5831 remains: #5833 lands first, then #5831 rebases onto it. Its append branch belongs in
NativeTransferBuffer, and the gatheredO_APPENDwrite must call that helper while the vector already holds the position lock. Calling the lockingNativeTransferwrapper there would lock the same mutex twice.An exact-head merge preview on main
d92a8dad390af1807cc91622b924252141816a5aalso reproduces the conflict with #5835e4036135e. In the WindowsTransferIovecspath, preserve the archive-read routing beforeFile::LockPositionedTransfer(d), then keep this PR's unlockedNativePositionedTransfer/NativeTransferBuffercalls under that lock. Dropping either side loses archive routing or whole-vector serialization.This #5835 composition was inspected statically; no combined archive/native runtime build or test was run. The archive feature and vector serialization are independent, and their merge order is not yet agreed.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by ahmad3a4 on 2026-10-14T15:11:26Z.
Hi @Ondra97, the overlap comment pairs this with #5831 (atomic
O_APPENDappends on Windows). The two don't overlap in purpose: this one keeps the aliases of one descriptor from interleaving in vectored transfers, and #5831 makesO_APPENDwrites atomic across independent opens withWriteFileat the end-of-file offset.Whichever lands second needs two adjustments:
File::Appendsbranch moves into yourNativeTransferBuffer.writevgathering forO_APPENDcallsNativeTransferBuffer. With this PR,TransferIovecsalready holds the position lock there, so callingNativeTransferwould lock the samestd::mutextwice.I built
main84b01f9cwith this PR and #5831 resolved that way.guest_append_writes,guest_file_vector(with your concurrent records) andguest_kernel_fcntlpass 5 of 5 runs.I'm happy for this one to go first and will rebase #5831 onto it once it's merged. If #5831 lands first instead, the two points above are the whole resolution.
AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T15:23:38Z.
Thanks for testing the combined changes. I'm happy for #5833 to land first and for you to rebase #5831 onto it. Agreed on both adjustments to use NativeTransferBuffer and avoid locking the position mutex twice.
AI-assisted: yes. — Codex
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T11:24:33Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/File/src/Stdio.cppL1075Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestFileVector.cppcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:23:51Z.
Review: CHANGES_REQUESTED
Thanks, the lock change in
TransferIovecslooks right. One problem:core/libs/tests/GuestFileVector.cpp:164: the newguest_file_vectoraborts on Linux (File vector check failed at line 164, 5 of 5 runs). The concurrentpreadvat offset 0 againstpwritevat offset 0 reads torn records: on Linux a buffered read is not atomic against an overlapping write, and the Linux path does not use the Windows lock. The whole-record check on overlappingpreadv/pwritevonly holds with the Windows lock, so it must not run on Linux (guard that phase with_WIN32, or make the readers not overlap the writers), while thewritev/readvphases can stay.Please rerun
guest_file_vectoron Linux after the change.Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-15T13:58:22Z.
Thanks @adriadam10, fixed in
cbb6ddc88. I guarded only the overlapping concurrentpreadv/pwritevphase with_WIN32. The concurrentwritev/readvphases and existing sequential positioned-I/O checks still run on both platforms.I independently reproduced the Linux failure at line 164 in 5/5 runs before the change. After the fix:
guest_file_vectorpassed 10 consecutive runs.guest_file_vectorpassed 10 consecutive runs, including the overlapping positioned phase.Validated against main
f633042df. I updated the PR description with these results.AI-assisted: yes. — Codex
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T14:02:39Z.
Review: APPROVED
Re-checked against
cbb6ddc88: the_WIN32guard on the overlappingpreadv/pwritevphase fixes the Linux abort;guest_file_vectorpasses here on Linux with thewritev/readvphases still running.TransferIovecsholds the position lock and only calls the unlockedNativeTransferBuffer/NativePositionedTransfer, the scalar wrappers keep their lock, and the technical-debt entry matches. Merging once the Windows build is green.