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

Fix problematic fdatasync() call on macOS #102

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

the-real-tokai
Copy link
Contributor

The fdatasync call generates a implicit declaration of function 'fdatasync' is invalid in C99 warning when building for macOS (it's nowhere to be found in the system includes), but linking will eventually work fine because there is an unrelated syscall by the same name (different prototype), so it's not doing what it should. So lets not use it.

The fdatasync call generates a "implicit declaration of function 'fdatasync' is invalid in C99" warning when building for macOS (it's nowhere to be found in the system includes), but linking will eventually work fine because there is an unrelated syscall by the same name (different prototype), so it's not doing what it should. So lets not use it.
@adulau
Copy link
Owner

adulau commented Apr 23, 2024

Thanks for the PR. What about fcntl(pcap_fd, F_FULLSYNC, 0) ?

@the-real-tokai
Copy link
Contributor Author

Not sure it's required? There's a supposedly a noticeable performance impact to this under macOS for the whole system as it forces the disk itself to flush its write caches (I have not tested that) and I don't think logging in ssldump is that system critical, like e.g. cases like making sure the integrity of a database or similar things stay intact. If the log goes lost here in a worst case, maybe not that dramatic?

As far as I understand it: going F_FULLSYNC would be going into the opposite direction of what you were trying with the fdatasync() call (reducing performance impact?), while falling back to fsync() is solving the problem in the middle.

Here's some folks analysing the differences between the sync types and the differences between the systems (macOS vs. Linux) too that may give some insight: https://mjtsai.com/blog/2022/02/17/apple-ssd-benchmarks-and-f_fullsync/

I only once had a problem with a missing sync and that was on a Linux/OpenWRT based router. I made some changes —installed a new dnsmasq— and everything was working fine. Many months later there was a blackout and things booted back up afterwards and my DNS was no longer working because the new dnsmasq had disappeared. In all that time the system didn't had flushed things to disk. Now I always make sure to use sync && echo 3 > /proc/sys/vm/drop_caches and do a reboot cycle to make sure my changes stick (I rarely make changes though, maybe once every 2 years 😄 )

@adulau adulau merged commit d024127 into adulau:master Apr 23, 2024
6 checks passed
@adulau
Copy link
Owner

adulau commented Apr 23, 2024

Thank you for the feedback and the PR!

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