gio: bump splice copy buffer size to 1024k

This change increases throughput when copying files for some filesystems

(Modified by Philip Withnall <withnall@endlessm.com> to add more error
handling.)

https://bugzilla.gnome.org/show_bug.cgi?id=791457
This commit is contained in:
Andrés Souto 2017-12-28 17:35:27 +01:00 committed by Philip Withnall
parent 2ffba0e262
commit a5778ef7c5

View File

@ -2999,6 +2999,7 @@ splice_stream_with_progress (GInputStream *in,
GError **error) GError **error)
{ {
int buffer[2] = { -1, -1 }; int buffer[2] = { -1, -1 };
int buffer_size;
gboolean res; gboolean res;
goffset total_size; goffset total_size;
loff_t offset_in; loff_t offset_in;
@ -3011,6 +3012,25 @@ splice_stream_with_progress (GInputStream *in,
if (!g_unix_open_pipe (buffer, FD_CLOEXEC, error)) if (!g_unix_open_pipe (buffer, FD_CLOEXEC, error))
return FALSE; return FALSE;
/* Try a 1MiB buffer for improved throughput. If that fails, use the default
* pipe size. See: https://bugzilla.gnome.org/791457 */
buffer_size = fcntl (buffer[1], F_SETPIPE_SZ, 1024 * 1024);
if (buffer_size <= 0)
{
int errsv;
buffer_size = fcntl (buffer[1], F_GETPIPE_SZ);
errsv = errno;
if (buffer_size <= 0)
{
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Error splicing file: %s"), g_strerror (errsv));
return FALSE;
}
}
g_assert (buffer_size > 0);
total_size = -1; total_size = -1;
/* avoid performance impact of querying total size when it's not needed */ /* avoid performance impact of querying total size when it's not needed */
if (progress_callback) if (progress_callback)
@ -3034,7 +3054,7 @@ splice_stream_with_progress (GInputStream *in,
if (g_cancellable_set_error_if_cancelled (cancellable, error)) if (g_cancellable_set_error_if_cancelled (cancellable, error))
break; break;
if (!do_splice (fd_in, &offset_in, buffer[1], NULL, 1024*64, &n_read, error)) if (!do_splice (fd_in, &offset_in, buffer[1], NULL, buffer_size, &n_read, error))
break; break;
if (n_read == 0) if (n_read == 0)