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

Add F_BARRIERFSYNC for Sync operations on MacOS #319

Merged
merged 1 commit into from Feb 7, 2023

Conversation

mrambacher
Copy link
Contributor

This code is an attempt to address facebook/rocksdb#11035.

On MacOS, fsync does not have the same durability guarantees as under Linux. To address this, a f_cntl(F_FULLFSYNC) call was used added in this RocksDB PR. This original PR made every Sync and FSync operation use F_FULLFSYNC if it was available, at a great performance expense.

Apple also has an option "F_BARRIERFSYNC" which it says should be sufficient for most applications. Other useful discussions on full or barrier sync can be found here or here.

This PR introduces a new Make/CMake option FSYNC_MODE. This option does the following:

  • If set to OFF, disables this feature (does not use F_FULLFSYNC or F_BARRIERFSYNC)
  • If set to BARRIER, uses "barrier" for both sync and fsync operations
  • If set to FULL, uses "full for both sync and fsync operations.
  • If set to AUTO, uses "barrier" for sync operations and "full" for fsync operations;

The default is AUTO.

On my Mac, I see the following performance from timed make check runs:
FSYNC_MODE=AUTO make check 2787.87s user 2153.54s system 78% cpu 1:44:32.69 total
FSYNC_MODE=OFF make check 3081.92s user 898.34s system 276% cpu 24:00.67 total
FSYNC_MODE=BARRIER make check 3423.41s user 1437.35s system 160% cpu 50:21.54 total
FSYNC_MODE=FULL make check 4329.64s user 1909.05s system 63% cpu 2:43:40.98 total

Tests for CMake will be forthcoming.

Allow the posix sync code to be based upon BARRIER sync
@mrambacher mrambacher self-assigned this Dec 28, 2022
@mrambacher
Copy link
Contributor Author

Here are the test times via cmake and ctest:

AUTO: ctest -j 8 3636.12s user 1284.08s system 154% cpu 53:01.82 total
FULL: ctest -j 8 4135.67s user 1361.84s system 79% cpu 1:55:51.87 total
OFF: ctest -j 8 3043.81s user 787.98s system 665% cpu 9:36.15 total
BARRIER: ctest -j 8 3400.88s user 1145.65s system 242% cpu 31:14.52 total

@@ -102,6 +102,47 @@ int Madvise(void* addr, size_t len, int advice) {
}

namespace {
IOStatus PosixSync(int fd, const std::string& file_name,
const char* file_type) {
#if defined(HAVE_BARRIERFSYNC)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is code is the same as in the PosixFSync. do a function PosixSync that as parameter you pass if it is fsync or not and then split to the different code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about making one routine for sync/fsync, passing in an argument. But the code is NOT the same:

  • In the non-Mac case, Sync uses fdatasync and FSync uses fsync
  • In the Mac case, Sync prefers BARRIER and FULL prefers FSync but falls back to the other

I thought about merging them, but the code actually ends up more complicated. If you have a code layout that is simpler, I will take it but I could not come up with one.

Copy link
Contributor

@ayulas ayulas Jan 10, 2023

Choose a reason for hiding this comment

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

forget. its not worth the complications. go ahead


IOStatus PosixFSync(int fd, const std::string& file_name,
const char* file_type) {
#if defined(HAVE_FULLFSYNC)
Copy link
Contributor

Choose a reason for hiding this comment

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

the same code as above

#else // HAVE_FULLFSYNC
if (fdatasync(fd_) < 0) {
return IOError("While fdatasync mmapped file", filename_, errno);
IOStatus s = PosixSync(fd_, filename_, "mmapped file");
Copy link
Contributor

Choose a reason for hiding this comment

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

need to call generic PosixSync with fsync false

#else // HAVE_FULLFSYNC
if (fsync(fd_) < 0) {
return IOError("While fsync mmaped file", filename_, errno);
auto s = PosixFSync(fd_, filename_, "mmapped file");
Copy link
Contributor

Choose a reason for hiding this comment

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

need to call generic PosixSync with fsync true

assert(!is_btrfs_);
if (fd_ != -1 && ::fcntl(fd_, F_FULLFSYNC) < 0) {
return IOError("while fcntl(F_FULLFSYNC)", "a directory", errno);
if (fd_ != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as my comment above

@Guyme
Copy link

Guyme commented Jan 18, 2023

@Yuval-Ariel - please run QA.
thanks

@Yuval-Ariel
Copy link
Contributor

@Guyme , the QA per issue is done using the CI.. once the reviewer approves, the QA runs automatically

@Yuval-Ariel
Copy link
Contributor

fuzzer passed manually

@Yuval-Ariel Yuval-Ariel removed their assignment Jan 23, 2023
@Yuval-Ariel
Copy link
Contributor

@mrambacher has this been to performance?

@Yuval-Ariel
Copy link
Contributor

on hold until commit msg is fixed

@Yuval-Ariel Yuval-Ariel merged commit ed180bf into speedb-io:main Feb 7, 2023
ayulas pushed a commit that referenced this pull request Feb 26, 2023
Allow the posix sync code to be based upon BARRIER sync
Yuval-Ariel pushed a commit that referenced this pull request May 1, 2023
Allow the posix sync code to be based upon BARRIER sync
Yuval-Ariel pushed a commit that referenced this pull request May 4, 2023
Allow the posix sync code to be based upon BARRIER sync
udi-speedb pushed a commit that referenced this pull request Nov 13, 2023
Allow the posix sync code to be based upon BARRIER sync
udi-speedb pushed a commit that referenced this pull request Nov 15, 2023
Allow the posix sync code to be based upon BARRIER sync
udi-speedb pushed a commit that referenced this pull request Dec 4, 2023
Allow the posix sync code to be based upon BARRIER sync
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.

None yet

4 participants