Skip to content

gofer: pass O_DIRECT through to host FDs - #15873

Draft
ayushr2 wants to merge 1 commit into
gvisor:masterfrom
ayushr2:gofer-odirect
Draft

ayushr2 wants to merge 1 commit into
gvisor:masterfrom
ayushr2:gofer-odirect

Conversation

@ayushr2

@ayushr2 ayushr2 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

O_DIRECT on gofer regular files only bypasses the sentry page cache. I/O
still goes through the dentry's shared host FDs, which are opened without
O_DIRECT, so it is cached by the host.

A regularFileFD opened with O_DIRECT now also opens a per-FD handle with
O_DIRECT. While O_DIRECT is set, reads and writes whose offset, length and
memory are all page-aligned use it. Other I/O may not meet O_DIRECT
alignment requirements, e.g. splice(2) through sentry buffers and its
continuations after short transfers, so it keeps using the shared handles,
as do mmap and fsync; the host keeps both coherent. Clearing O_DIRECT with
fcntl(F_SETFL) switches all I/O back to the shared handles; setting it
later keeps the old behavior. The per-FD handle is only used if the gofer
donates a host FD, since lisafs I/O buffers are not aligned.

Updates #3626

@ayushr2 ayushr2 left a comment

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.

Three correctness issues reproduced in the O_DIRECT handling; details inline.

Comment thread pkg/sentry/fsimpl/gofer/regular_file.go Resolved
Comment thread pkg/sentry/fsimpl/gofer/regular_file.go Resolved
Comment thread pkg/sentry/fsimpl/gofer/save_restore.go Resolved
O_DIRECT on gofer regular files only bypasses the sentry page cache. I/O
still goes through the dentry's shared host FDs, which are opened without
O_DIRECT, so it is cached by the host.

A regularFileFD opened with O_DIRECT now also opens a per-FD handle with
O_DIRECT. While O_DIRECT is set, reads and writes whose offset, length and
memory are all page-aligned use it. Other I/O may not meet O_DIRECT
alignment requirements, e.g. splice(2) through sentry buffers and its
continuations after short transfers, so it keeps using the shared handles,
as do mmap and fsync; the host keeps both coherent. Clearing O_DIRECT with
fcntl(F_SETFL) switches all I/O back to the shared handles; setting it
later keeps the old behavior. The per-FD handle is only used if the gofer
donates a host FD, since lisafs I/O buffers are not aligned.

Updates gvisor#3626

Signed-off-by: Ayush Ranjan <[email protected]>
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.

1 participant