Heiher
339ddb53d3
fs/epoll: remove unnecessary wakeups of nested epoll
Take the case where we have:
t0
| (ew)
e0
| (et)
e1
| (lt)
s0
t0: thread 0
e0: epoll fd 0
e1: epoll fd 1
s0: socket fd 0
ew: epoll_wait
et: edge-trigger
lt: level-trigger
We remove unnecessary wakeups to prevent the nested epoll that working in edge-
triggered mode to waking up continuously.
Test code:
#include <unistd.h>
#include <sys/epoll.h>
#include <sys/socket.h>
int main(int argc, char *argv[])
{
int sfd[2];
int efd[2];
struct epoll_event e;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0)
goto out;
efd[0] = epoll_create(1);
if (efd[0] < 0)
goto out;
efd[1] = epoll_create(1);
if (efd[1] < 0)
goto out;
e.events = EPOLLIN;
if (epoll_ctl(efd[1], EPOLL_CTL_ADD, sfd[0], &e) < 0)
goto out;
e.events = EPOLLIN | EPOLLET;
if (epoll_ctl(efd[0], EPOLL_CTL_ADD, efd[1], &e) < 0)
goto out;
if (write(sfd[1], "w", 1) != 1)
goto out;
if (epoll_wait(efd[0], &e, 1, 0) != 1)
goto out;
if (epoll_wait(efd[0], &e, 1, 0) != 0)
goto out;
close(efd[0]);
close(efd[1]);
close(sfd[0]);
close(sfd[1]);
return 0;
out:
return -1;
}
More tests:
https://github.com/heiher/epoll-wakeup
Link: http://lkml.kernel.org/r/20191009060516.3577-1-r@hev.cc
Signed-off-by: hev <r@hev.cc>
Reviewed-by: Roman Penyaev <rpenyaev@suse.de>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Eric Wong <e@80x24.org>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Sridhar Samudrala <sridhar.samudrala@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-12-04 19:44:13 -08:00
..
2019-09-27 15:10:34 -07:00
2019-07-19 11:33:22 -07:00
2019-11-18 14:26:43 +01:00
2019-11-30 10:57:22 -08:00
2019-10-25 00:03:11 -04:00
2019-08-30 07:27:17 -07:00
2019-08-30 07:27:17 -07:00
2019-12-01 13:46:15 -08:00
2019-05-24 17:27:11 +02:00
2019-12-01 13:46:15 -08:00
2019-12-02 11:51:02 -08:00
2019-09-19 09:42:37 -07:00
2019-11-06 18:36:01 +01:00
2019-11-23 21:44:49 -05:00
2019-11-06 12:34:36 -08:00
2019-11-03 14:03:01 +01:00
2019-09-03 09:30:56 -04:00
2019-07-12 17:37:53 -07:00
2019-12-01 13:46:15 -08:00
2019-07-19 10:42:02 -07:00
2019-08-30 07:27:17 -07:00
2019-11-24 11:02:41 +08:00
2019-11-10 11:56:05 -05:00
2019-11-30 11:16:07 -08:00
2019-12-01 13:46:15 -08:00
2019-12-01 13:46:15 -08:00
2019-10-23 17:23:43 +02:00
2019-08-30 07:27:17 -07:00
2019-07-10 18:43:43 -07:00
2019-12-01 13:46:15 -08:00
2019-12-01 13:46:15 -08:00
2019-05-21 10:50:46 +02:00
2019-07-16 19:23:23 -07:00
2019-05-12 17:52:13 -04:00
2019-10-23 17:23:46 +02:00
2019-12-01 12:59:08 -08:00
2019-11-26 09:28:47 -08:00
2019-09-19 09:42:37 -07:00
2019-11-30 10:53:02 -08:00
2019-11-29 11:29:58 +01:00
2019-09-19 09:42:37 -07:00
2019-11-26 16:02:40 -08:00
2019-07-03 17:52:09 -04:00
2019-08-30 07:27:17 -07:00
2019-11-01 11:03:56 -04:00
2019-05-21 10:50:46 +02:00
2019-09-27 17:00:27 -07:00
2019-10-23 17:23:46 +02:00
2019-05-21 10:50:46 +02:00
2019-12-01 13:46:15 -08:00
2019-09-26 10:10:44 -07:00
2019-12-01 20:36:41 -08:00
2019-08-30 08:11:25 -07:00
2019-07-19 10:42:02 -07:00
2019-09-19 10:21:35 -07:00
2019-09-11 16:11:45 +02:00
2019-12-04 19:44:11 -08:00
2019-10-29 09:43:03 -07:00
2019-08-30 07:27:17 -07:00
2019-08-30 07:27:17 -07:00
2019-11-11 11:06:27 +01:00
2019-09-12 21:05:34 -04:00
2019-11-05 12:25:22 +01:00
2019-09-19 10:06:57 -07:00
2019-09-19 10:06:57 -07:00
2019-07-19 10:42:02 -07:00
2019-08-30 07:27:18 -07:00
2019-10-12 20:49:07 -04:00
2019-11-17 22:22:54 +01:00
2019-09-04 18:19:43 +02:00
2019-09-19 09:42:37 -07:00
2019-09-17 11:48:24 -04:00
2019-08-12 19:33:50 -07:00
2019-12-02 14:46:22 -08:00
2019-12-01 14:00:59 -08:00
2019-07-19 10:42:02 -07:00
2019-08-30 07:27:17 -07:00
2019-05-21 10:50:45 +02:00
2019-11-15 14:38:29 +01:00
2019-11-15 14:38:29 +01:00
2019-05-21 10:50:45 +02:00
2019-07-16 19:23:22 -07:00
2019-07-19 10:42:02 -07:00
2019-05-21 10:50:45 +02:00
2019-11-14 07:44:01 -07:00
2019-12-01 06:29:17 -08:00
2019-05-24 20:50:36 +02:00
2019-11-15 14:38:29 +01:00
2019-12-02 14:46:22 -08:00
2019-06-19 17:09:55 +02:00
2019-08-03 07:02:01 -07:00
2019-08-30 19:31:09 -04:00
2019-11-30 10:44:49 -08:00
2019-10-09 12:46:10 +02:00
2019-05-21 10:50:45 +02:00
2019-12-01 06:29:18 -08:00
2019-05-21 10:50:45 +02:00
2019-12-04 19:44:13 -08:00
2019-12-03 12:20:25 -08:00
2019-10-25 14:28:10 -06:00
2019-08-07 21:51:47 -04:00
2019-08-19 11:00:39 -04:00
2019-11-26 11:34:06 -08:00
2019-02-28 03:29:26 -05:00
2019-09-06 21:28:49 +02:00
2019-09-12 21:06:14 -04:00
2019-07-16 22:52:37 -04:00
2019-05-21 10:50:45 +02:00
2019-11-08 13:37:24 -07:00
2019-07-19 10:42:02 -07:00
2019-09-24 15:54:11 -07:00
2019-07-20 09:15:51 -07:00
2019-12-01 18:26:56 -08:00
2019-11-26 15:02:56 -07:00
2019-11-26 15:02:56 -07:00
2019-12-02 14:46:22 -08:00
2019-10-29 12:43:00 -06:00
2019-06-24 09:16:47 +10:00
2019-10-14 15:04:01 -07:00
2019-09-27 17:00:27 -07:00
2019-10-29 12:43:00 -06:00
2019-05-21 10:50:45 +02:00
2019-07-16 22:52:37 -04:00
2019-07-10 09:00:57 -06:00
2019-10-03 13:59:29 -04:00
2019-10-16 23:15:09 -04:00
2019-05-30 11:26:32 -07:00
2019-05-25 18:00:06 -04:00
2019-11-26 11:34:06 -08:00
2019-11-30 14:12:13 -08:00
2019-06-17 17:36:09 -04:00
2019-05-30 11:29:53 -07:00
2019-05-21 10:50:45 +02:00
2019-09-06 21:28:49 +02:00
2019-08-16 18:43:24 -07:00
2019-10-18 18:41:16 -04:00
2019-11-15 14:38:29 +01:00
2019-08-13 16:06:52 -07:00
2019-04-08 18:21:02 -05:00
2019-11-30 14:12:13 -08:00
2019-05-21 10:50:45 +02:00
2019-10-03 14:21:35 -07:00
2019-10-10 08:16:44 -07:00
2019-05-14 09:47:50 -07:00
2019-11-15 14:38:30 +01:00
2019-12-01 20:36:41 -08:00
2019-11-15 14:38:29 +01:00
2019-05-21 10:50:45 +02:00