mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
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:
parent
2ffba0e262
commit
a5778ef7c5
22
gio/gfile.c
22
gio/gfile.c
@ -2999,6 +2999,7 @@ splice_stream_with_progress (GInputStream *in,
|
||||
GError **error)
|
||||
{
|
||||
int buffer[2] = { -1, -1 };
|
||||
int buffer_size;
|
||||
gboolean res;
|
||||
goffset total_size;
|
||||
loff_t offset_in;
|
||||
@ -3011,6 +3012,25 @@ splice_stream_with_progress (GInputStream *in,
|
||||
if (!g_unix_open_pipe (buffer, FD_CLOEXEC, error))
|
||||
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;
|
||||
/* avoid performance impact of querying total size when it's not needed */
|
||||
if (progress_callback)
|
||||
@ -3034,7 +3054,7 @@ splice_stream_with_progress (GInputStream *in,
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
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;
|
||||
|
||||
if (n_read == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user