From: Davy Durham <pubaddr2@davyandbeth.com>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Willy Tarreau <willy@w.ods.org>,
bert hubert <bert.hubert@netherlabs.nl>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: select() efficiency / epoll
Date: Tue, 23 Aug 2005 17:35:31 -0500 [thread overview]
Message-ID: <430BA4B3.5000502@davyandbeth.com> (raw)
In-Reply-To: <Pine.LNX.4.63.0508232202580.10064@localhost.localdomain>
Davide Libenzi wrote:
>
> There is no known problem in using epoll_ctl() in one thread while
> another does epoll_wait().
> I suggest you to ask Valgrind to take a look at you binary. Since I
> have no clue of what your software does, please create the *minimal*
> code snippet that exploit the eventual problem, and post it.
>
Yes, I have pretty much confirmed this. And unfortunately I tried to
make a minimal code snippet which demonstrates the problem, but wasn't
able to do that before I figured out a work-around. I may still try to
create something for you to test against so you can fix it. But I'm
going to have to continue to work with the existing implementation since
I'm going to be running this code on some production servers where
updating the kernel might not be an option.
The work-around is as follows:
1) I create a queue that can hold operations to perform on the epoll
structure and I protect it with a mutex.
2) Other threads (when needing to modify the epoll) lock the mutex and
enque the operation into the operation queue instead of calling
epoll_ctl itself (i.e. add this socket for reading.. add this socket for
writing, remove this socket.. etc) *and* then cancel the epoll_wait()
I implemented the cancel by having a pipe() always being watched for
read, and write a byte to it when I want to cancel (is there a better way?)
There are several operations that could be supported
(add/remove/modify/change userdata/etc), but I only need two myself.
3) There's only one thread that actually does the epoll_wait(). When
epoll_wait() returns, (I first drain the cancel pipe so it never fills
up) I handle what events need handling, and then lock the operations
queue mutex, perform all the operations in the queue then clear the queue
So, this works for me now.
Thanks for all your guys' info.
-- Davy
P.S. Davide, I still might get you that snipped, but it's not a
trivial snippet as you can imagine... and timing is everything to the
problem :( .. and also the question of WHERE it corrupts memory.. it
seemed to be unpredictable so far.
next prev parent reply other threads:[~2005-08-24 7:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-22 21:18 select() efficiency Davy Durham
2005-07-22 21:24 ` bert hubert
2005-08-23 9:49 ` select() efficiency / epoll Davy Durham
2005-08-23 18:24 ` bert hubert
2005-08-23 11:01 ` Davy Durham
2005-08-23 11:25 ` Davy Durham
2005-08-23 19:12 ` Willy Tarreau
2005-08-23 11:24 ` Davy Durham
2005-08-23 19:45 ` Willy Tarreau
2005-08-23 11:55 ` Davy Durham
2005-08-23 20:20 ` Willy Tarreau
2005-08-23 23:21 ` Davide Libenzi
2005-08-23 17:08 ` Davy Durham
2005-08-24 5:09 ` Davide Libenzi
2005-08-23 22:35 ` Davy Durham [this message]
2005-08-23 19:30 ` Jari Sundell
2005-08-23 11:53 ` Davy Durham
2005-08-23 20:42 ` Jari Sundell
2005-08-23 17:11 ` Davy Durham
2005-08-23 17:40 ` Davy Durham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=430BA4B3.5000502@davyandbeth.com \
--to=pubaddr2@davyandbeth.com \
--cc=bert.hubert@netherlabs.nl \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=willy@w.ods.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox