Re: [PATCH v2 05/10] compat/posix: introduce writev(3p) wrapper
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Mar 5, 2026, 06:39 UTC
- Message-ID
- <7e8b51d1-382d-47f8-be71-74e76f0c9888@kdbg.org>
- In-Reply-To
- <aajnZZI5yqL9CYeR@fruit.crustytoothpaste.net>
Am 05.03.26 um 03:16 schrieb brian m. carlson:
Show 12 quoted lines
> On 2026-03-05 at 00:37:45, Jeff King wrote: >> I like that writev() can work as a drop-in replacement for write() at >> the lowest level. But given that our main use is likely to be pkt-lines, >> I do kind of wonder if we should just try to be more clever in forming >> our buffers. That makes all of the portability and compat questions go >> away (and gives the benefit to platforms that don't even have writev). > > This does work and it is clever, but I think the writev is clearer and > more explicit. In addition, this is literally the kind of use case that > it's designed for and the kernel will have a highly optimized > implementation handling it. I could also see myself making use of > writev in my future work as well,...
Please don't. The use of writev may mislead you to depend on guarantees that a kernel implementation of writev can provide, but a compat/ implementation cannot. (For example, I read something about "the file pointer shall be unchanged" in the case of errors.) Please use simple and stupid functions (write). I highly doubt that you can squeeze out a noticable performance improvement with writev.
-- Hannes