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

Double data copy due to combined header and data buffers #10

Open
asomers opened this issue Sep 5, 2021 · 0 comments
Open

Double data copy due to combined header and data buffers #10

asomers opened this issue Sep 5, 2021 · 0 comments

Comments

@asomers
Copy link
Contributor

asomers commented Sep 5, 2021

Most of the methods of Session create a Vec and copy two slices into it: the fuse_out_header and an opcode-specific response. However, this Vec is short-lived: its contents get copied again by nix::unistd::write to the fuse device.
I suggest eliminating the first data copy by changing the Session::response_sender's type to include separate buffers for the header and the data. Then use nix::unistd::writev to pass them to the kernel. It would look like this:

pub struct Session<'a, FS> {
    ...
    response_sender: UnboundedSender<(fuse_out_header, Vec)>,
    ...
}
impl FuseConnection {
        pub async fn write(&self, response: (fuse_out_header, Vec) -> Result<usize, io::Error> {
            let _guard = self.write.lock().await;

            let header_data = get_bincode_config()
                .serialize(&response.0)
                .unwrap();
            let iovecs = [IoVec::from_slice(&header_data), IoVec::from_slice(&response.1)];
            loop {
                let mut write_guard = self.fd.writable().await?;
                if let Ok(result) = write_guard.try_io(|fd| {
                    unistd::writev(fd.as_raw_fd(), &iovecs).map_err(io::Error::from)
                }) {
                    return result;
                } else {
                    continue;
                }
            }
        }

}
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

No branches or pull requests

1 participant