From patchwork Sun Dec 28 20:23:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 127131 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5BA024BA2E28 for ; Sun, 28 Dec 2025 20:25:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BA024BA2E28 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.a=rsa-sha256 header.s=202505 header.b=gmTTUxFV X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) by sourceware.org (Postfix) with ESMTPS id D10924BA2E24 for ; Sun, 28 Dec 2025 20:23:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D10924BA2E24 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D10924BA2E24 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=139.28.40.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766953421; cv=none; b=iryM5ZLATcH2fJlhUJ68Uas7jKxiNw4bNaguq12+5kF2B/8WHlab7X0GnXFb5Exs5V96WPBlqGiKuUdnbF4jMapV4sdzMi+bRTbbmxHhGgobOgfU7pdI4vJG2eQ7HNVLgqRmaFVvNZkj28Fpbhgj9faW1l3P5T/McvubRHdusTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766953421; c=relaxed/simple; bh=K8J7KRDdCzbc7B6UqeLvYLWSu3TtQ3y3lAkBGdpF5SY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=SZgVLGB2rpghg84msRq2jfmGZ0PFdDlb/BDxhVvlpbTOJfUrWbAGn5ZR4lJZc4Eab1lyMV1dg97ni7t+e1eirTsFX3DQGWUGnWV0ZYxJOe+QZjTFvHDL1qFKjItQ4jadJX5DK8mBzuzfFsz6gumU500BBuFrSgDYRsKjsOuGP7c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D10924BA2E24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202505; t=1766953418; bh=K8J7KRDdCzbc7B6UqeLvYLWSu3TtQ3y3lAkBGdpF5SY=; h=Date:From:To:Subject:From; b=gmTTUxFVTbnsXhUAbMBdemXaE8YvYwwtl8hycKJReSoyWjnEd3PJxXY0v32egSgIz tetsipCaU07xOFAKUqL3GeZ1nYvbObYR/j7bwF3iccVu9jUxHEcXS8NtP7runreXiW /wrjFxsR4kZ0xxd18eHR0WUeaVsWPi8VEVMqDT9Ltt8CmDE6KRrnziaIxjKZ5ReawC /j+C/izgXzwBdZ+SeT2PAiW/XFf7JG/aR50RR0naB5etj3sKYwiN9U2rQ6KsLRRi/u 7bwYv4FVs28n7c8y5U4W371tFhli5O1fbPvS+U6o/Hf2iwa9Katy/JkMAWwgP213U3 WjIoCn7BchByg== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 4B16E11042 for ; Sun, 28 Dec 2025 21:23:38 +0100 (CET) Date: Sun, 28 Dec 2025 21:23:38 +0100 From: =?utf-8?b?0L3QsNCx?= To: libc-alpha@sourceware.org Subject: [PATCH] io: allow filesystem st_blksize-directed buffer sizes up to 128k instead of 8k Message-ID: MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20231221-2-4202cf-dirty X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP, GIT_PATCH_0, KAM_INFOUSMEBIZ, KAM_SOMETLD_ARE_BAD_TLD, PDS_OTHER_BAD_TLD, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The only difference between old and new being setvbuf(input, (char *)malloc(128*1024), _IOFBF, 128*1024); with 128k matching zfs's st_blksize: Benchmark 1: < f out/cmd/head -n 290955 Time (mean ± σ): 153.4 ms ± 3.9 ms [User: 78.0 ms, System: 75.3 ms] Range (min … max): 146.5 ms … 159.2 ms 19 runs Benchmark 2: < f ./head.old -n 290955 Time (mean ± σ): 259.7 ms ± 5.7 ms [User: 86.3 ms, System: 173.3 ms] Range (min … max): 249.1 ms … 269.3 ms 11 runs Summary < f out/cmd/head -n 290955 ran 1.69 ± 0.06 times faster than < f ./head.old -n 290955 (where the output is 290955 lines, 230427757 bytes and the program reduces to a getdelim()/fwrite() loop which reduces to a read()/write() loop). A value around 128k gets us around 60% of the performance back without being so large it should affect the memory pressure. Signed-off-by: Ahelenia Ziemiańska --- libio/filedoalloc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git libio/filedoalloc.c libio/filedoalloc.c index f360d96a9b..3a3d6f52d3 100644 --- libio/filedoalloc.c +++ libio/filedoalloc.c @@ -61,6 +61,13 @@ #include #include +/* nfs/cifs/cephfs request 512k/1M/4M. That is a /lot/ for an iostream. + However, many other filesystems request reasonable values, + and clamping them to BUFSIZ of 8k throws away a lot of performance: + for a getdelim()/fwrite() loop at zfs's requested st_blksize of 128k, + over a 220М file, completes in 60% of the time of when the buffer size is 8k. */ +#define MAX_FS_BUFSIZ (128 * 1024) + /* Allocate a file buffer, or switch to unbuffered I/O. Streams for TTY devices default to line buffered. */ int @@ -84,7 +91,9 @@ _IO_file_doallocate (FILE *fp) fp->_flags |= _IO_LINE_BUF; } #if defined _STATBUF_ST_BLKSIZE - if (st.st_blksize > 0 && st.st_blksize < BUFSIZ) + if (st.st_blksize > MAX_FS_BUFSIZ) + st.st_blksize = MAX_FS_BUFSIZ; + if (st.st_blksize > 0) size = st.st_blksize; #endif }