-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
socketpair: add eventfd
and use SOCK_NONBLOCK
for socketpair()
#13874
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
b5b4453
to
afef94a
Compare
Currently, we use `pipe` for `wakeup_create`, which requires ***two*** file descriptors. Furthermore, given its complexity inside, `pipe` is a bit heavyweight for just a simple event wait/notify mechanism. `eventfd` would be a more suitable solution for this kind of scenario, kernel also advocates for developers to use `eventfd` instead of `pipe` in some simple use cases: > Applications can use an eventfd file descriptor instead of a pipe (see pipe(2) in all cases where a pipe is used simply to signal events. The kernel overhead of an eventfd file descriptor is much lower than that of a pipe, and only one file descriptor is required (versus the two required for a pipe). This PR adds the new backend of `eventfd` for `wakeup_create` and uses it where available, eliminating the overhead of `pipe`. Also, it optimizes the `wakeup_create` to eliminate the system calls that make file descriptors non-blocking by moving the logic of setting non-blocking flags on file descriptors to `socketpair.c` and using `SOCK_NONBLOCK` for `socketpair(2)`, `EFD_NONBLOCK` for `eventfd(2)`. Ref: https://man7.org/linux/man-pages/man7/pipe.7.html https://man7.org/linux/man-pages/man2/eventfd.2.html https://man7.org/linux/man-pages/man2/socketpair.2.html https://www.gnu.org/software/gnulib/manual/html_node/eventfd.html
Thanks! |
Unfortunately, this breaks |
How did it break? What's the error info? |
I'm investigating this. |
Is this breakage perhaps specific to Windows? I built |
I've run |
Follow-up to 23fe1a5 curl#13874
Follow-up to 23fe1a5 curl#13874 Closes curl#15561
Currently, we use
pipe
forwakeup_create
, which requires two file descriptors. Furthermore, given its complexity inside,pipe
is a bit heavyweight for just a simple event wait/notify mechanism.eventfd
would be a more suitable solution for this kind of scenario, kernel also advocates for developers to useeventfd
instead ofpipe
for some simple use cases:This PR adds the new backend of
eventfd
forwakeup_create
and uses it where available, eliminating the overhead ofpipe
. Also, it optimizes thewakeup_create
to eliminate the system calls that make file descriptors non-blocking by moving the logic of setting non-blocking flags on file descriptors tosocketpair.c
and usingSOCK_NONBLOCK
forsocketpair(2)
,EFD_NONBLOCK
foreventfd(2)
.Ref:
https://man7.org/linux/man-pages/man7/pipe.7.html
https://man7.org/linux/man-pages/man2/eventfd.2.html
https://man7.org/linux/man-pages/man2/socketpair.2.html
https://www.gnu.org/software/gnulib/manual/html_node/eventfd.html