Skip to content

Properly handle O_DIRECT in io-uring - #8833

Merged
coszio merged 12 commits into
devfrom
proper-odirect-uring
May 5, 2026
Merged

coszio merged 12 commits into
devfrom
proper-odirect-uring

Conversation

@coszio

@coszio coszio commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Instead of allowing short reads when using O_DIRECT (see #8466, #8808), this PR properly handles the flag by generating an aligned buffer, and extracting the requested output from it after it has been filled.

To do this, I added a new IoUringRequest::ODirectRead variant, which holds the extended buffer, and the information to extract the requested items from it.

@coszio
coszio force-pushed the proper-odirect-uring branch from db0afb0 to a50e4e3 Compare April 28, 2026 21:23
@coszio coszio mentioned this pull request Apr 28, 2026
@coderabbitai

This comment was marked as low quality.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as low quality.

@coszio
coszio force-pushed the proper-odirect-uring branch from 3508b67 to 282dfc2 Compare April 29, 2026 13:43
@coszio
coszio marked this pull request as ready for review April 29, 2026 13:49
coderabbitai[bot]

This comment was marked as resolved.

use crate::maybe_uninit;

pub struct IoUringRuntime<'data, T, Meta = u64> {
const KERNEL_PAGE_SIZE: u64 = 4096; // 4 kB

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe

pub fn page_size() -> Option<usize> {
?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Uring is for linux only, so I assumed 4kb to be fine.

If we want to make sure to use the right value which is checked at runtime, Claude says we'd need our own abstraction that uses std::alloc::Layout, with its own Drop impl, along with a bunch of unsafe code.

If we want to be sure without those shenanigans, we can increase the const to 16kb, which covers all cases. We'll use it at 16kb anyways for disk cache 🤷.

@coszio
coszio requested a review from ffuugoo May 4, 2026 12:40
@coszio
coszio requested a review from generall May 5, 2026 14:35
@coszio
coszio merged commit fb05128 into dev May 5, 2026
15 checks passed
@coszio
coszio deleted the proper-odirect-uring branch May 5, 2026 15:07
timvisee pushed a commit that referenced this pull request May 8, 2026
* handle o_direct with custom buffer

* make separate impl

* use correct inner offset

* align buffer

* codespell

* review fixes

* use o_direct in tests

* clippy

* fix simple read impl

* simpler to_vec()

* use router function

* change todo comment
@coderabbitai coderabbitai Bot mentioned this pull request May 14, 2026
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