From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B43072095E for ; Sat, 18 Mar 2017 00:56:37 +0000 (UTC) From: Eric Wong To: sleepy-penguin@bogomips.org Subject: [PATCH] epoll: add EPOLLEXCLUSIVE constant and documentation Date: Sat, 18 Mar 2017 00:56:37 +0000 Message-Id: <20170318005637.10191-1-sleepy-penguin@bogomips.org> List-Id: I'm still not convinced this is necessary, but it's in Linux, now, and maybe some folks will want it. My position remains: Never put listen sockets in epoll if you're using threads; instead, dedicate a thread to doing nothing but _blocking_ accept4 + epoll_ctl(.. EPOLL_CTL_ADD). Of course, if you're using something which does not have native thread support but using multiple processes, then yes, EPOLLEXCLUSIVE will prevent multiple processes from turning into a thundering herd. In other words: I would use this with Perl5, but not with Ruby 1.9+ :P --- ext/sleepy_penguin/epoll.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c index 8155c4a..09c4bf7 100644 --- a/ext/sleepy_penguin/epoll.c +++ b/ext/sleepy_penguin/epoll.c @@ -306,6 +306,17 @@ void sleepy_penguin_init_epoll(void) rb_define_const(cEpoll, "WAKEUP", UINT2NUM(EPOLLWAKEUP)); #endif +#ifdef EPOLLEXCLUSIVE + /* + * Sets an exclusive wakeup mode for the epoll object + * that is being attached to the target IO. This + * avoids thundering herd scenarios when the same + * target IO is shared among multiple epoll objects. + * Available since Linux 4.5 + */ + rb_define_const(cEpoll, "EXCLUSIVE", UINT2NUM(EPOLLEXCLUSIVE)); +#endif + /* watch for urgent read(2) data */ rb_define_const(cEpoll, "PRI", UINT2NUM(EPOLLPRI)); -- EW