]> Cypherpunks repositories - gostls13.git/commit
os: employ sendfile(2) for file-to-file copying on Linux when needed
authorAndy Pan <i@andypan.me>
Tue, 6 Aug 2024 08:36:45 +0000 (16:36 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 7 Aug 2024 17:28:44 +0000 (17:28 +0000)
commit80746f7f2d4b3d1d2ea62878e7c89f5c6c3c2a2a
tree3ecabc9154131e5e4d22538f4ddd35b402b59a85
parentb696250e5f0dcc4cfa863309538c65d30d2ad480
os: employ sendfile(2) for file-to-file copying on Linux when needed

Go utilizes copy_file_range(2) for file-to-file copying only on kernel 5.3+,
but even on 5.3+ this system call can still go wrong for some reason (check
out the comment inside poll.CopyFileRange).

Before Linux 2.6.33, out_fd must refer to a socket, but since Linux 2.6.33
it can be any file. Thus, we can employ sendfile(2) for copy between files
when copy_file_range(2) fails to handle the copy, that way we can still
benefit from the zero-copy technique on kernel <5.3 and wherever
copy_file_range(2) is available but broken.

Change-Id: I3922218c95ad34ee649ccdf3ccfbd1ce692bebcc
Reviewed-on: https://go-review.googlesource.com/c/go/+/603295
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/readfrom_linux_test.go
src/os/writeto_linux_test.go
src/os/zero_copy_linux.go