-
Notifications
You must be signed in to change notification settings - Fork 2.5k
cmake: detect availability of posix_fallocate(3) #5087
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and is clearly a better solution. Thanks for fixing this @pks-t.
(I do hope there's no such problem as the qsort/_r/_s
conundrum, but I don't recall inconsistent signatures)
On Fri, May 24, 2019 at 07:01:26AM -0700, Etienne Samson wrote:
I do hope there's no such problem as the `qsort/_r/_s`
conundrum, but I don't recall inconsistent signatures)
Well, I'd definitely hope that if a function already has a
`posix_` prefix, that implementers will in fact implement what
POSIX specifies. But you never know ;)
|
Indeed. The GCC builds are complaining about something, though I don't know what that is. |
On Sat, May 25, 2019 at 01:29:16AM -0700, Edward Thomson wrote:
Indeed. The GCC builds are complaining about something, though I don't know what that is.
Huh. For whatever reason, those systems do not detect
`posix_fallocate`, even though they should definitely have it
available:
2019-05-24T11:54:32.6862203Z -- Looking for posix_fallocate
2019-05-24T11:54:32.7131435Z -- Looking for posix_fallocate - not found
Will need to investigate why that is.
|
I've pushed a fixup here. I've ended up doing a check for the posix_fallocate symbol, and if that fails, it'll check if we're on some kind of BSD. This test is "looser" that the original NetBSD preprocessor checks provided by @jacquesg, but if I understood correctly, NetBSD gained (edit I've also made more explicit that it's a BSD-specific implementation) |
FreeBSD has had |
I would also check for it on Solaris, as I believe it is only available from 11 onwards. Version 10 is still in wide-spread use. |
Thanks for the insight. I haven't been able to find a reference about what was supported on Solaris then. If it's the fcntl stuff as the BSDs need it's okay, but if it's not then (I'd really like to not have to implement a "stupid" write zeroes fallback)… |
Here is some guidance on how to implement it for Solaris: https://fossies.org/linux/dpkg/lib/dpkg/fdio.c |
Ok, so it doesn't seem like any version of NetBSD or OpenBSD has
|
This code is still not fully correct. On NetBSD posix_fallocate(2) will report EOPNOTSUPP for frequently used filesystems (we need kernel support for each filesystem) and must have a fallback for the ftruncate(2) function. |
Okay, I've updated my fixup commit to CMake checks all of those, choose the one available, and fallback to |
/rebuild |
Sorry @ethomson, I was not able to find any builds to requeue. |
Gah, the build expired. I'll have to figure out how to remove the build expirations. In the meantime, I queued a new build against this branch manually, and it's still failing, unfortunately. |
@pks-t Do you mind if I take over this one ? I'm responsible for the half-working platform support, have a tentative fix handy which I forgot to point out here (there should be a lone commit I've added to my fork). As you wish, but since it impacts platforms not quite under CI, it feel best to fix it "fast" (maybe) ? |
On Wed, Jun 12, 2019 at 04:33:28AM -0700, Etienne Samson wrote:
@pks-t Do you mind if I take over this one ? I'm responsible
for the half-working platform support, have a tentative fix
handy which I forgot to point out here (there should be a [lone
commit](master...tiennou:pks/cmake-posix-fallocate)
I've added to my fork). As you wish, but since it impacts
platforms not quite under CI, it feel best to fix it "fast"
(maybe) ?
Nope, I'm fine with that. Sorry for not investing more time here,
and thanks for taking over!
|
464d830
to
908e11f
Compare
Updated with @tiennou's changes |
Okay, so the Linux test failed because I have inconsistent semantics, I believe because of the My expectation of whatever POSIX describes as |
908e11f
to
4f717d6
Compare
Hmm, what version of Linux are we building on that's missing |
In any case, yes, I agree that we need to avoid shrinking a file with |
Dunno, but I'd wager it's also filesystem-specific, and we're in crazy vm shenanigans territory, so that could have been the fallback.
Not per se, I could have just added a check to make sure we'd not cause the file to shrink. Would that work better ? It's just that I'm expecting I'll have to juggle offsets, lengths and seek positions to convert "fallocate hole" into "ftruncate complete file but don't make it smaller", and the dumb loop seemed safer… |
Instead of having fragile checks for platform definitions to guess whether posix_fallocate(3) is available or not, let's just use CMake's `CHECK_FUNCTION_EXISTS` to detect that. This is both more accurate and simpler.
@pks-t branch updated again (Xcode's renamer doesn't look inside #ifdefs). Do you have an opinion on the dump-write-loop vs. ftruncate-unless-it-would-shrink approach ? |
4f717d6
to
efb2733
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... this seems mighty complex. And the funny thing is: we don't even use p_fallocate
anywhere except for in our tests for the bigfile emulation. Is it really worth the effort? Shouldn't we just remove p_fallocate
altogether and create a binary blob that explodes to a huge size upon uncompressing it?
#endif | ||
|
||
fallback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get it. Aren't we now always executing the fallback, regardless of whether the platform-specific implementation succeeded or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, true, I seem to have forgot a few returns
when whatever platform-specific version succeeded. IOW, only failures of the (potential) platform fallocate would cause the fallback to run.
#elif defined(GIT_USE_FALLOCATE) | ||
do { | ||
error = fallocate(fd, 0, offset, len); | ||
} while (error < 0 && errno == EINTR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can fallocate
set EAGAIN
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's copy-pasted from #5087 (comment), actually. And isn't EAGAIN
usually async network stuff ? I'm scared now…
#else | ||
return posix_fallocate(fd, offset, len); | ||
goto fallback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just remove the else
block, but that's a matter of taste
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's protecting against an "unused label" warning on macOS case, actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... this seems mighty complex.
God yes. Removing the fallback uncovered another "issue": macOS needs the fallback, because somehow after the call, its fstat size is still 0 (I've added a comment). So if there's any chance to drop that madness, I'm all for it now 😭.
#endif | ||
|
||
fallback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, true, I seem to have forgot a few returns
when whatever platform-specific version succeeded. IOW, only failures of the (potential) platform fallocate would cause the fallback to run.
#else | ||
return posix_fallocate(fd, offset, len); | ||
goto fallback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's protecting against an "unused label" warning on macOS case, actually.
#elif defined(GIT_USE_FALLOCATE) | ||
do { | ||
error = fallocate(fd, 0, offset, len); | ||
} while (error < 0 && errno == EINTR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's copy-pasted from #5087 (comment), actually. And isn't EAGAIN
usually async network stuff ? I'm scared now…
Yeah, seeing how this escalated quickly I'm all for dropping |
+1 |
Closing, this has been fixed via #5114 by removing |
Instead of having fragile checks for platform definitions to
guess whether posix_fallocate(3) is available or not, let's just
use CMake's
CHECK_FUNCTION_EXISTS
to detect that. This is bothmore accurate and simpler.