Page MenuHomeFreeBSD

fix the performance of cp(1) when copying large non-sparse files

Authored by rmacklem on Jan 2 2021, 11:51 PM.
Referenced Files
Unknown Object (File)
Sun, Sep 10, 1:07 PM
Unknown Object (File)
Wed, Sep 6, 3:32 PM
Unknown Object (File)
Tue, Sep 5, 1:39 AM
Unknown Object (File)
Fri, Aug 25, 12:14 PM
Unknown Object (File)
Jul 24 2023, 6:56 AM
Unknown Object (File)
Jun 29 2023, 12:49 PM
Unknown Object (File)
May 23 2023, 3:30 AM
Unknown Object (File)
May 17 2023, 11:32 AM



PR252358 reported a serious performance problem
when copying a large non-sparse file on a UFS file
This problem seems to have been caused by a large
number of SEEK_HOLE operations, with one done
for each copy_file_range(2) call.

This patch modifies cp(1) to use a large (SSIZE_MAX)
len argument, reducing the number of system calls
and resolving the performance issue.

While here, convert the type of the "rcount" from "int"
to "ssize_t" so that it is consistent with that returned
by both read(2) and copy_file_range(2).

Test Plan

Tested by copying both large non-sparse and
large sparse files via cp(1) and timing how long
the copy takes.

The copy of the non-sparse file now completes
20% faster than dd(1) for the same file, for my
test case.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable