3 ms·
>Further, since it is unsafe to directly dereference user-level pointers (what if they are null — that’ll crash the kernel!) the data referred to by these point
by layoutIfNeeded 6y ago
>Further, since it is unsafe to directly dereference user-level pointers (what if they are null — that’ll crash the kernel!) the data referred to by these pointers must be copied into the kernel.
False. If the file was opened with O_DIRECT, then the kernel uses the user-space buffer directly.
From man write(2):
O_DIRECT (Since Linux 2.4.10)
Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do their own caching. File I/O is done directly to/from user-space buffers. The O_DIRECT flag on its own makes an effort to transfer data synchronously, but does not give the guarantees of the O_SYNC flag that data and necessary metadata are transferred. To guarantee synchronous I/O, O_SYNC must be used in addition to O_DIRECT. See NOTES below for further discussion.
- wtallis 6y agoI don't think O_DIRECT makes any guarantees about zero-copy operation. It merely disallows kernel-level caching of that data. But the kernel may make a private copy that isn't caching.
- layoutIfNeeded 6y agoWho said it was guaranteed to be zero-copy? The original article said that the data must be copied based on some bogus handwavy argument, and I’ve pointed out that the manpage of write(2) contradicts this when it says the following: >File I/O is done directly to/from user-space buffers.