🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #839

[Bug 301237] vn_io_fault1() calls cloneuio() unconditionally, so single-buffer regular-file reads and writes heap-allocate a uio...

#839
From: bugzilla-noreply
Date: Sat, 28 Nov 2026 16:04
91 lines
5908 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301237

            Bug ID: 301237
           Summary: vn_io_fault1() calls cloneuio() unconditionally, so
                    single-buffer regular-file reads and writes
                    heap-allocate a uio on every call
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

On filesystems setting MNTK_NO_IOPF (UFS, ZFS, NFS client, msdosfs, and
nullfs), every regular-file read(2), pread(2), write(2), and pwrite(2)
enters vn_io_fault1() with uio->uio_iovcnt == 1. In sys/kern/vfs_vnops.c
(main 2534dcb233ad), vn_io_fault1() always heap-clones uio via
cloneuio() and frees it at exit:

        uio_clone = cloneuio(uio);
        ...
        error = vn_io_fault_doio(args, uio, td);
        if (error != EFAULT)
                goto out;
        ...
out:
        freeuio(uio_clone);

cloneuio() calls malloc(sizeof(struct uio) + sizeof(struct iovec),
M_IOV, M_WAITOK) and freeuio() calls free(..., M_IOV) on every single-iov
transfer, including cached UFS VIRF_PGREAD reads that never fault or use
uio_clone.

On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C), timing 300000 cached 64-byte UFS pread(2) calls pinned to one
CPU (ns/op, 10 runs):

cc -O2 -Wall -Wextra -Werror -pthread -o vn_io_fault_bench vn_io_fault_bench.c
for i in $(jot 10); do cpuset -l 2 ./vn_io_fault_bench pread64 1 300000
/var/tmp; done

x base_p64.txt
+ patched_p64.txt
+--------------------------------------------------------------------------+
|    +                                                                  x  |
|   ++                                                                  x  |
|   ++                                                                  xx |
|   ++++               +                                                xxx|
||___M_A_____|                                                          A| |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  10        175.21        175.59        175.29       175.312    0.11242775
+  10        163.64         166.9        163.81       164.126    0.98608316
Difference at 95.0% confidence
        -11.186 +/- 0.659393
        -6.38062% +/- 0.375827%
        (Student's t, pooled s = 0.701783)

Cached 4096-byte UFS pread(2) latency (pread4k 1 300000, N=10) drops
from 198.71 to 189.63 ns/op (-4.57% +/- 0.74% at 95% confidence), and
DTrace fbt::cloneuio:entry and fbt::freeuio:entry counts across 7000
pread(2) calls drop from 7001 to 0. On the iovcnt == 2 preadv(2) control
(where cloneuio() still runs), baseline and patched show no difference
at 95% confidence (227.51 vs 228.44 ns/op). Under debug GENERIC
(INVARIANTS and WITNESS), vn_io_fault_bench verify passes on both UFS
and ZFS (demand-paged > io_hold_cnt reads, partial-fault reads and UFS
IO_UNIT writes, misaligned page-straddling faults, PROT_NONE faults, and
self-mapped file writes), along with the 3 GiB big_unmapped_read test
and Kyua sys/aio and sys/vfs suites.

Storing single-iov clones in a stack struct uio and struct iovec[1] when
uio->uio_iovcnt == 1 (matching zfs_uiocopy() in spl_uio.c) and calling
freeuio() only for heap clones avoids per-call M_IOV allocations.

Source inspection shows the same unconditional cloneuio() call on
stable/15 and stable/14; I have only runtime-tested UFS and ZFS on
16.0-CURRENT amd64 (not NFS client, msdosfs, or nullfs mounts).

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-301237-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301237] vn_io_fault1() calls cloneuio() unconditionally, so
 single-buffer regular-file reads and writes heap-allocate a uio on every call
Date: Sat, 28 Nov 2026 16:04:22 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301237-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="59190"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1795881862;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=rwfSoNGaz7wXi7McRNHeef8+phnqb+A3z65JWV3C6zI=;
	b=cTjUQBKZb0JkxXG20uCONRYmbfDSHuHP32sGvWv0qw5jiIELWzc5/AP54T2x9noDjYgp+p
	0+3lvH9T5vsZEQIKR5NUQXjlvYnt8ZwGStVK4F61U+yChgaxTOX9b5HoMEJ3SctwOO3HrQ
	upFtt/y4JnR/2GLtVe4NcyYKFdsrbjOjO9+fKB3Xku067nnqU+HXeKRdVkoK5huPkFnuH/
	EFlNA1BUI+A7iXNFRGrUxtvb5tOYMUC5WNnDSVs9b6s4IheIrFCwlcvNBGW/Yzn22SFSIF
	lGKYFRuIqpT7PUHo+xaAaPHS7l+y2HfsJhCNfJ4Mb37TGmcDFXUBjUYWHZ6sXA==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes