Commit 55899c2fcb4c9b62f1f7b6dffed8ff961dcad546

Andy Pan 2024-01-14T21:24:37

Use read/write instead of readv/writev for single buffer The `readv`/`writev` functions are designed for scattered I/O optimally, their logic in the kernel is more sophisticated, compared to read/write, which includes extra on-stack `iovec` in the kernel space, importing `iovec` array from user space to kernel space, reading/writing with `iov_iter`, etc. As a result, using `readv`/`writev` on single-segment `iovec` will fall into the special branch in the kernel where it is imported as `ITER_UBUF` differed from `ITER_IOVEC` for multiple-segments `iovec`. Thus, it is just not worth calling `readv`/`writev` for single-segment `iovec`, we should use `read`/`write` instead, to save it from going through the sophisticated yet unnecessary kernel code path, circumvent a waste of kernel on-stack memory, copying `iovec` between user space and kernel space, etc.