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

Multi buffer scatter-gather i/o is not atomic on Windows #119

Open
ned14 opened this issue Sep 10, 2015 · 1 comment
Open

Multi buffer scatter-gather i/o is not atomic on Windows #119

ned14 opened this issue Sep 10, 2015 · 1 comment

Comments

@ned14
Copy link
Member

ned14 commented Sep 10, 2015

POSIX guarantees that multi-buffer scatter gather is executed as a single atomic operation. Windows, unless you opened with O_DIRECT, does not.

AFIO needs to emulate the POSIX behaviour using either memcpy to form a single buffer when buffers are small, or byte range locks when the buffers are large.

@ned14
Copy link
Member Author

ned14 commented Oct 26, 2015

Upon reflection, this will need some new file_flags:

  • file_flags::win_scatter_gather_disable_locking - don't byte range lock the region being scatter gathered to emulate POSIX atomicity guarantees. This locking would only happen if the scatter gather amount exceeds maybe 1Mb anyway as otherwise we'll use memcpy.
  • file_flags::win_scatter_gather_atomic_extend - use a zeroed page single append to atomically advance the file extent, then non-atomically perform the gather write over the zeroed section.

Combining these two flags should yield maximum atomic append performance on Windows at the cost of torn reads and writes. For some applications e.g. my transactional database that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant