Limit in-kernel file copying to 2 GiB blocks at a time (#5039)

This reportedly helps with copying to cifs target where
`copy_file_range()` would sometimes return `EINVAL` for no apparent
reason when copying large files. Extending the limit to `sendfile64()`
to avoid similar issue there, if it exists.

Overall, copying at most 2 GiB at a time will result in more syscalls
but shouldn't affect the performance gain in any noticeable way.
This commit is contained in:
Mike Gelfand 2023-02-25 06:15:17 +03:00 committed by GitHub
parent a42e81efd9
commit 81f8ceb0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -379,7 +379,7 @@ bool tr_sys_path_copy(char const* src_path, char const* dst_path, tr_error** err
while (file_size > 0U)
{
size_t const chunk_size = std::min(file_size, uint64_t{ SSIZE_MAX });
size_t const chunk_size = std::min({ file_size, uint64_t{ SSIZE_MAX }, uint64_t{ INT32_MAX } });
auto const copied = copy_file_range(in, nullptr, out, nullptr, chunk_size, 0);
TR_ASSERT(copied == -1 || copied >= 0); /* -1 for error; some non-negative value otherwise. */
@ -432,7 +432,7 @@ bool tr_sys_path_copy(char const* src_path, char const* dst_path, tr_error** err
{
while (file_size > 0U)
{
size_t const chunk_size = std::min(file_size, uint64_t{ SSIZE_MAX });
size_t const chunk_size = std::min({ file_size, uint64_t{ SSIZE_MAX }, uint64_t{ INT32_MAX } });
auto const copied = sendfile64(out, in, nullptr, chunk_size);
TR_ASSERT(copied == -1 || copied >= 0); /* -1 for error; some non-negative value otherwise. */