Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

cgwalters
Copy link
Member

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.

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.
cgwalters added a commit to cgwalters/ostree that referenced this pull request Apr 27, 2017
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.
@gnomesysadmins
Copy link

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
getting started documentation:
http://www.gnome.org/get-involved

Otherwise please visit
https://wiki.gnome.org/Newcomers
and follow the instructions there to upload your change to Bugzilla.

@jlebon
Copy link
Contributor

jlebon commented Apr 28, 2017

Looks sane to me. Note though that flatpak at least will need to be updated on how it handles the return value of glnx_loop_write(): https://github.com/flatpak/flatpak/blob/8b13d3c/common/flatpak-utils.c#L2193. I don't know what other project(s) use libglnx, so I'm not sure how safe the API change is.

@cgwalters
Copy link
Member Author

Good catch on flatpak! I'll submit a PR to update it after this, otherwise we'll forget.

@cgwalters
Copy link
Member Author

flatpak/flatpak#745

cgwalters added a commit to cgwalters/ostree that referenced this pull request May 1, 2017
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
cgwalters added a commit to cgwalters/ostree that referenced this pull request May 1, 2017
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
cgwalters added a commit to cgwalters/ostree that referenced this pull request May 1, 2017
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
rh-atomic-bot pushed a commit to ostreedev/ostree that referenced this pull request May 10, 2017
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
mightysai1997 pushed a commit to mightysai1997/systemd that referenced this pull request Apr 19, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants