From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19574 invoked from network); 16 Mar 2021 09:30:27 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 16 Mar 2021 09:30:27 -0000 Received: (qmail 7457 invoked by uid 550); 16 Mar 2021 09:30:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7437 invoked from network); 16 Mar 2021 09:30:23 -0000 Date: Tue, 16 Mar 2021 12:30:11 +0300 (MSK) From: Alexander Monakov To: Rich Felker cc: musl@lists.openwall.com, Dominic Chen In-Reply-To: <20210316021325.GH32655@brightrain.aerifal.cx> Message-ID: References: <50e56e3e-d448-c568-b3d8-fbab98939ff8@gmail.com> <20210315215120.GF32655@brightrain.aerifal.cx> <20210315222916.GG32655@brightrain.aerifal.cx> <20210316021325.GH32655@brightrain.aerifal.cx> User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [musl] Issue with fread() and unaligned readv() On Mon, 15 Mar 2021, Rich Felker wrote: > > Thanks. Can musl reduce the first iov tuple by, say, 8 bytes rather than > > 1 byte, to avoid forcing the kernel to perform a misaligned copy? > > Well then you have to do more copy in userspace afterwards, and reduce > the effective buffer size by a bit, going back to kernel slightly more > often or spending extra memory to compensate. Of course, but shouldn't you consider how it balances against the cost to perform a 1K (BUFSIZ) misaligned copy on each read? > There's also no strong > reason to believe one will be aligned and the other won't, except at > beginning of file. The alignment mod 8 depends on file position and > access history, and neither the caller's buffer nor the FILE buffer > have any inherent alignment. The alignment of caller's buffer is another matter, I was talking about misaligned copy into internal FILE buffer (and even then, at least when user buffer was malloc'ed it will be sufficiently aligned). The buffer in FILE obtained from fopen will be aligned to _Alignof(_IO_FILE) in musl thanks to UNGET being 8. If the file has been repositioned, yes, bets are off, but I think with stdio it is quite common to read a file without seeks (could be non-seekable in the first place). Alexander