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

feat: impl Async Read/Write Rent for File #297

Merged
merged 1 commit into from
Sep 14, 2024
Merged

Conversation

Lzzzzzt
Copy link
Collaborator

@Lzzzzzt Lzzzzzt commented Aug 31, 2024

This PR implements AsyncReadRent and AsyncWriteRent for File, completing the following tasks:

  • Updated op::read<T> and op::write<T> to support reading/writing files using the file pointer.
    • Also modified the implementation of read and read_at on Windows:
      • Utilized the OVERLAPPED struct to reduce the number of syscalls.
  • Fixed the bug where readv and writev would always start from the beginning of the file.
  • Removed the incorrect implementation of readv and writev on Windows.
    • Simulated readv and writev by continually calling the read and write functions.
  • Updated the documentation for AsyncWriteRent and AsyncReadRent.
  • Due to the lack of readv/writev-like syscalls on the Windows platform, the structure of src/fs/file.rs was changed for better readability of the implementations on different platforms.
  • Added tests for the changes above.

Other details are shown in the code.

Related Issue
#266
#291

}

async fn write<T: IoBuf>(&mut self, buf: T) -> crate::BufResult<usize, T> {
let op = Op::write(self.fd.clone(), buf).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WriteOp(as well as ReadOp)'s legacy implementation is to directly call pwrite. This is fine for something like TcpStream(eq to send), but for file io this is a blocking action.
To make write be non-blocking, iouring/aio may help. But for legacy path, I think we can do it in an independent thread pool.
A (shared) thread pool can be attached to a runtime if it needs it. We can do blocking syscall with it. If it is not attached, we can do it inplace.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean when the feature "sync" is enabled, use the thread pool to do the syscall, is that right?
If we do this, it may be necessary to change other file-related behavior like create_dir & metadata and ...

monoio/src/driver/op/read.rs Outdated Show resolved Hide resolved
Copy link
Member

@ihciah ihciah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot!

@ihciah ihciah merged commit c3cb780 into bytedance:master Sep 14, 2024
25 checks passed
@Xuanwo
Copy link
Collaborator

Xuanwo commented Sep 14, 2024

Nice!

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