From: Paolo Bonzini <pbonzini@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
mtk.manpages@gmail.com, "Paton J. Lewis" <palewis@adobe.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jason Baron <jbaron@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Paul Holland <pholland@adobe.com>,
Davide Libenzi <davidel@xmailserver.org>,
libc-alpha@sourceware.org, Linux API <linux-api@vger.kernel.org>,
paulmck@linux.vnet.ibm.com
Subject: Re: [PATCH v2] epoll: Support for disabling items, and a self-test app.
Date: Fri, 19 Oct 2012 15:03:29 +0200 [thread overview]
Message-ID: <50814FA1.2050202@redhat.com> (raw)
In-Reply-To: <508044D7.7070005@mit.edu>
Il 18/10/2012 20:05, Andy Lutomirski ha scritto:
>
> Unless something is rather buggy in kernel land (and I don't think it
> is), once EPOLL_CTL_DEL has returned, no call to epoll_wait that starts
> *after* EPOLL_CTL_DEL finishes will return that object. This suggests
> an RCU-like approach: once EPOLL_CTL_DEL has returned and every thread
> has returned from an epoll_wait call that started after the
> EPOLL_CTL_DEL returns, then the data structure can be safely freed.
>
> In pseudocode:
>
> delete(fd, pdata) {
> pdata->dead = true;
> EPOLL_CTL_DEL(fd);
> rcu_call(delete pdata);
> }
>
> wait() {
> epoll_wait;
> for each event pdata {
> if (pdata->gone) continue;
> process the event;
> }
>
> rcu_this_is_a_grace_period();
> }
>
> Of course, these are not normal grace periods and would need to be
> tracked separately. (The optimal data structure to do this without
> killing scalability is not obvious. urcu presumably implements such a
> thing.)
>
> Am I right?
Equip each thread with a) an id or something else that lets each thread
refer to "the next" thread; b) a lists of "items waiting to be deleted".
Then the deleting thread adds the item being deleted to the first
thread's list. Before executing epoll_wait, thread K empties its list
and passes the buck, appending the old contents of its list to that of
thread K+1. This is an O(1) operation no matter how many items are
being deleted; only Thread N, being the last thread, actually has to go
through the list and delete the items.
The lists need to be protected by a mutex, but contention should really
be rare since there are just two writers. Note that each thread only
needs to hold one mutex at a time, and the deletion loop does not need
to happen with the mutex held at all, so there's no worries of
"cascading" waits on the mutexes.
Compared to http://thread.gmane.org/gmane.linux.kernel/1311457, you get
rid of the per-item mutex and the operations that have to be done with
the (now per-thread) mutex held remain pretty trivial.
Paolo
next prev parent reply other threads:[~2012-10-19 13:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 21:15 [PATCH v2] epoll: Support for disabling items, and a self-test app Paton J. Lewis
[not found] ` <1345756535-8372-1-git-send-email-palewis-dv/VyGpifdQAvxtiuMwx3w@public.gmane.org>
2012-10-16 15:12 ` Michael Kerrisk (man-pages)
2012-10-17 23:30 ` Andrew Morton
2012-10-18 18:05 ` Andy Lutomirski
2012-10-19 13:03 ` Paolo Bonzini [this message]
2012-10-19 13:29 ` Paul Holland
[not found] ` <CCA6A06A.10264%pholland-dv/VyGpifdQAvxtiuMwx3w@public.gmane.org>
2012-10-19 13:39 ` Paolo Bonzini
[not found] ` <5085D159.4090703@adobe.com>
2012-10-23 13:26 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkg0R2LwfpF8beCkawTfPu7oj_DDaDxf2VJ+xB6UTgRSaw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-23 17:23 ` Paton J. Lewis
[not found] ` <5086D27F.1000007-dv/VyGpifdQAvxtiuMwx3w@public.gmane.org>
2012-10-23 19:15 ` Andreas Jaeger
2012-10-26 0:25 ` Paton J. Lewis
2012-10-24 1:01 ` Paton J. Lewis
[not found] ` <50873DFA.5010205-dv/VyGpifdQAvxtiuMwx3w@public.gmane.org>
2012-10-25 10:23 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkj=52rPitKT2b4_=dwczpfub6RQojjX4rNhFZQZHecSTA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 21:09 ` Paton J. Lewis
2012-10-26 21:52 ` Matt Helsley
[not found] ` <20121026215242.GB19911-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2012-11-05 3:09 ` Michael Wang
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=50814FA1.2050202@redhat.com \
--to=pbonzini@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=davidel@xmailserver.org \
--cc=jbaron@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mtk.manpages@gmail.com \
--cc=palewis@adobe.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pholland@adobe.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).