-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add back io::copy file to pipe optimization #128300
Comments
We never used F_MOVE and it was still a problem. So I'm skeptical it'll work at all but maybe it depends on the direction (from/to pipe).
Those cost extra syscalls, which could be unnecessary overhead for small files. So it probably only makes sense to even try these things for large files. And many of those cases seem rare that it's not worth it. Like who serves e.g. a webserver from a btrfs snapshot? |
Yeah I think we'd only want tohandle sealed file here, I was probably listing too many cases during my brain storming 😂 However, I don't think sealed file is used very often.
Hmm it seems that So the only possible workarond for a really large file and fs supporting reflink would be to use
Agree, if it is small enough, |
I think we might want someway for the user to tell Checking for sealed file, checking for read-only fs, etc is all about niche cases, I think we need application to convey some information about this? |
Also doesn't seem like a common thing.
Yeah. The most common thing where sendfile makes sense is a webserver. And the files might not even be marked read-only there. |
Thanks I missed that one, if so then file seals seems very uncommon |
Agree, the more I look at it, the more I think we need another API like rust-lang/libs-team#202 propose, which will always assume using pub struct ImmutableFile(File); That's the simplest way I can think of, no need for another |
I think we don't want to promise anything that relies on specialization until there's a plan to stabilize specialization or at least parts thereof. |
That makes sense, in that case maybe a dedicated API on impl File {
/// This is similar to [`std::io::copy`], except it will attempt to use `splice` on Linux or `sendfile` on Unix
/// to avoid copying data if possible.
///
/// NOTE that if you change the content of the file after this call, it might also change the data in `writer`.
pub fn copy(&self, writer: &mut W) -> io::Result<u64>
where
W: Write + ?Sized;
} |
That would still require specialization for the writer side. The only way to do this with stable rust is to require both sides to implement all the necessary traits which expose the internal buffers and so on. What |
Yeah but isn't that same as |
We don't guarantee that that happens though, so we can remove it if specialization becomes an issue. |
So...maybe we just add it, saying that we assume the If specialisation is removed, it'd be just a convenient method of |
Except that we'd have to make that distinction very clear to avoid people getting corrupt data. And adding warnings and choosing a different name for something we can't promise probably isn't worth it. |
So to sum up, I think we can add back optimization via:
statfs
F_SEAL_WRITE
(prevent modifying of existing contents, shrinking and appending is allowed) andF_SEAL_SEAL
(not changing of seals), detectable viafcntl(fd, F_GET_SEALS)
/dev/zero
, or from other pseudo fs (e.g. procfs, sysfe), then I think we can assume it's immutableOtherwise, we'd fallback to:
Also, if the file is a named fifo, then just a splice without F_MOVE would work fine.
Originally posted by @NobodyXu in #108283 (comment)
The text was updated successfully, but these errors were encountered: