Skip to content

file: Skip alignment probes for buffered read-only files - #5

Open
ChengyuZhu6 wants to merge 2 commits into
XanClic:mainfrom
ChengyuZhu6:skip-probe
Open

file: Skip alignment probes for buffered read-only files#5
ChengyuZhu6 wants to merge 2 commits into
XanClic:mainfrom
ChengyuZhu6:skip-probe

Conversation

@ChengyuZhu6

Copy link
Copy Markdown

No description provided.

@ChengyuZhu6

Copy link
Copy Markdown
Author

@XanClic

@XanClic XanClic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don’t really follow what the first commit does. (Edit: Sorry, wrote this before I did follow through it. I do follow through it, and it looks good to me, but more explanation would still be nice.)

The commit message is quite sparse, it would be good if it could say more about how it is accomplishing this, and also, why this is safe and good. Also, why do we need to do probing when the file is buffered and R/W? (I know I write the code, but I don’t remember 🙃 — maybe I was trying to be rather safe than sorry.)

Comment thread src/file.rs
///
/// `direct_io` should be `true` if direct I/O was requested, and can be `false` if that status
/// is unknown.
fn new(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This should be either just rephrased, or, if indeed dropped, the /// line above must go as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread src/file.rs
Comment on lines +468 to +471
/// Detect access and direct I/O modes for an externally supplied file.
#[cfg(unix)]
fn detect_open_mode(file: &fs::File) -> (bool, bool) {
// Safe: No argument, returns result.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you add documentation on the return values?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added.

@XanClic

XanClic commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Hmm, there’s still no notes in the commit message, and is there a reason you dropped the second patch? It seemed good to me.

Buffered I/O does not impose alignment restrictions, so probing it only adds fstatfs(), pread(), and pwrite() calls. The pwrite() probe can also grow an empty writable file.

Use byte alignment for buffered files and keep the existing probes for O_DIRECT. Read-only O_DIRECT files still skip the write probe.

Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
@ChengyuZhu6

Copy link
Copy Markdown
Author

Hmm, there’s still no notes in the commit message, and is there a reason you dropped the second patch? It seemed good to me.

@XanClic My bad. Now buffered io now uses byte alignment regardless of whether the file is writable. This also avoids the pwrite probe growing an empty writable file. ro O_DIRECT files still probe read alignment but skip the write probe. I expanded the commit message to explain this.

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.

2 participants