Page MenuHomeFreeBSD

pax: Use copy_file_range
Needs ReviewPublic

Authored by des on Jul 26 2026, 12:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 7, 6:33 PM
Unknown Object (File)
Wed, Oct 7, 6:32 PM
Unknown Object (File)
Wed, Oct 7, 6:32 PM
Unknown Object (File)
Tue, Oct 6, 6:29 PM
Unknown Object (File)
Mon, Oct 5, 10:50 PM
Unknown Object (File)
Mon, Oct 5, 9:01 AM
Unknown Object (File)
Sun, Oct 4, 1:04 AM
Unknown Object (File)
Thu, Oct 1, 10:17 AM
Subscribers

Details

Reviewers
None
Group Reviewers
Klara
Summary

Use copy_file_range(2) instead of our own inefficient and unreliable
attempt at detecting holes. If copy_file_range(2) is not available,
which in theory should be never, we fall back to a simple read(2) /
write(2) loop which makes no attempt to copy holes. This should
speed up pax copy mode and cpio passthrough mode significantly.

This includes refactoring much of the existing I/O code to use the
size_t and ssize_t instead of int where appropriate.

MFC after: 1 week
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75144
Build 72027: arc lint + arc unit

Event Timeline

des requested review of this revision.Jul 26 2026, 12:58 PM

Other than the two nits I noted, assuming I did it correctly, this is good.

bin/pax/ar_io.c
598–605

What if write returns a value > 0 but < bsz? (Yes, the old code had that issue too.)

bin/pax/buf_subs.c
763–768

I highly suggest {} when dealing with a nested statement such as that.

obiwac added inline comments.
bin/pax/ar_io.c
587
598–605

that's what's considered a "broken write" as i understand it. it goes through to the switch below

bin/pax/buf_subs.c
756–757

like copy_file_range(), the caller is expected to call again if returned len is smaller than len, this is ok

773

wlen could be uninitialized here if we break out of the while loop early