-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fdio: Expose glnx_regfile_copy_bytes(), rewrite: GNU style, POSIX errno #44
Conversation
In ostree in a few places we use `g_output_stream_splice()`. I thought this would use `splice()`, but actually it doesn't today. They also, if a cancellable is provided, end up dropping into `poll()` for every read and write. (In addition to copying data to/from userspace). My opinion on this is - for *local files* that's dumb. In the big picture, you really only need cancellation when copying gigabytes. Down the line, we could perhaps add a `glnx_copy_bytes_cancellable()` that only did that check e.g. every gigabyte of copied data. And when we do that we should use `g_cancellable_set_error_if_cancelled()` rather than a `poll()` with the regular file FD, since regular files are *always* readable and writable. For my use case with rpm-ostree though, we don't have gigabyte sized files, and seeing all of the `poll()` calls in strace is annoying. So let's have the non-cancellable file copying API that's modern and uses both reflink and `sendfile()` if available, in that order. My plan at some point once this is tested more is to migrate this code into GLib.
Rather than `g_output_stream_splice()`, where the input is a regular file. See GNOME/libglnx#44 for some more information. I didn't try to measure the performance difference, but seeing the read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me when reading strace. As a bonus, we will again start using reflinks (if available) for `/etc`, which is a regression from the ostreedev#797 changes (which before used `glnx_file_copy_at()`). Also, for the first time we'll use reflinks when doing commits from file-backed content. This happens in `rpm-ostree compose tree` today for example.
Thank you for contributing to libglnx! libglnx uses Bugzilla for code review. If you have never contributed to GNOME before make sure you have read the Otherwise please visit |
Looks sane to me. Note though that flatpak at least will need to be updated on how it handles the return value of |
Good catch on flatpak! I'll submit a PR to update it after this, otherwise we'll forget. |
Rather than `g_output_stream_splice()`, where the input is a regular file. See GNOME/libglnx#44 for some more information. I didn't try to measure the performance difference, but seeing the read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me when reading strace. As a bonus, we will again start using reflinks (if available) for `/etc`, which is a regression from the ostreedev#797 changes (which before used `glnx_file_copy_at()`). Also, for the first time we'll use reflinks when doing commits from file-backed content. This happens in `rpm-ostree compose tree` today for example. Update submodule: libglnx
Rather than `g_output_stream_splice()`, where the input is a regular file. See GNOME/libglnx#44 for some more information. I didn't try to measure the performance difference, but seeing the read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me when reading strace. As a bonus, we will again start using reflinks (if available) for `/etc`, which is a regression from the ostreedev#797 changes (which before used `glnx_file_copy_at()`). Also, for the first time we'll use reflinks when doing commits from file-backed content. This happens in `rpm-ostree compose tree` today for example. Update submodule: libglnx
Rather than `g_output_stream_splice()`, where the input is a regular file. See GNOME/libglnx#44 for some more information. I didn't try to measure the performance difference, but seeing the read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me when reading strace. As a bonus, we will again start using reflinks (if available) for `/etc`, which is a regression from the ostreedev#797 changes (which before used `glnx_file_copy_at()`). Also, for the first time we'll use reflinks when doing commits from file-backed content. This happens in `rpm-ostree compose tree` today for example. Update submodule: libglnx
Rather than `g_output_stream_splice()`, where the input is a regular file. See GNOME/libglnx#44 for some more information. I didn't try to measure the performance difference, but seeing the read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me when reading strace. As a bonus, we will again start using reflinks (if available) for `/etc`, which is a regression from the #797 changes (which before used `glnx_file_copy_at()`). Also, for the first time we'll use reflinks when doing commits from file-backed content. This happens in `rpm-ostree compose tree` today for example. Update submodule: libglnx Closes: #817 Approved by: jlebon
A while ago I copied a version of this code into libglnx, and was recently doing some work on it: GNOME/libglnx#44 While there I noticed that if a maximum size was provided, we could end up doing a zero-sized `sendfile()` call which is obviously pointless. If we have nothing to do at the of the loop, just break out.
In ostree in a few places we use
g_output_stream_splice()
. Ithought this would use
splice()
, but actually it doesn't today.They also, if a cancellable is provided, end up dropping into
poll()
for everyread and write. (In addition to copying data to/from userspace).
My opinion on this is - for local files that's dumb. In the big picture, you
really only need cancellation when copying gigabytes. Down the line, we could
perhaps add a
glnx_copy_bytes_cancellable()
that only did that check e.g.every gigabyte of copied data. And when we do that we should use
g_cancellable_set_error_if_cancelled()
rather than apoll()
with the regularfile FD, since regular files are always readable and writable.
For my use case with rpm-ostree though, we don't have gigabyte sized files, and
seeing all of the
poll()
calls in strace is annoying. So let's have thenon-cancellable file copying API that's modern and uses both reflink and
sendfile()
if available, in that order.My plan at some point once this is tested more is to migrate this code
into GLib.