linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Baron <jbaron@akamai.com>
To: Heiher <r@hev.cc>
Cc: linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Davide Libenzi <davidel@xmailserver.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Eric Wong <e@80x24.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roman Penyaev <rpenyaev@suse.de>,
	Sridhar Samudrala <sridhar.samudrala@intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v2] fs/epoll: Remove unnecessary wakeups of nested epoll that in ET mode
Date: Tue, 24 Sep 2019 11:18:46 -0400	[thread overview]
Message-ID: <92a54917-0cdf-89ce-1fb1-f913156a1e0d@akamai.com> (raw)
In-Reply-To: <CAHirt9i42K37J9n8smaudJyigRAiiDhzZBuW+gbyLXHVq98yqQ@mail.gmail.com>



On 9/24/19 10:06 AM, Heiher wrote:
> Hi,
> 
> On Mon, Sep 23, 2019 at 11:34 PM Jason Baron <jbaron@akamai.com> wrote:
>>
>>
>>
>> On 9/20/19 12:00 PM, Jason Baron wrote:
>>> On 9/19/19 5:24 AM, hev wrote:
>>>> From: Heiher <r@hev.cc>
>>>>
>>>> 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
>>>>
>>>> When s0 fires an event, e1 catches the event, and then e0 catches an event from
>>>> e1. After this, There is a thread t0 do epoll_wait() many times on e0, it should
>>>> only get one event in total, because e1 is a dded to e0 in edge-triggered mode.
>>>>
>>>> This patch only allows the wakeup(&ep->poll_wait) in ep_scan_ready_list under
>>>> two conditions:
>>>>
>>>>  1. depth == 0.


What is the point of this condition again? I was thinking we only need
to do #2.

>>>>  2. There have event is added to ep->ovflist during processing.
>>>>
>>>> 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
>>>>
>>>> Cc: Al Viro <viro@ZenIV.linux.org.uk>
>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>> 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: Linus Torvalds <torvalds@linux-foundation.org>
>>>> Cc: Roman Penyaev <rpenyaev@suse.de>
>>>> Cc: Sridhar Samudrala <sridhar.samudrala@intel.com>
>>>> Cc: linux-kernel@vger.kernel.org
>>>> Cc: linux-fsdevel@vger.kernel.org
>>>> Signed-off-by: hev <r@hev.cc>
>>>> ---
>>>>  fs/eventpoll.c | 5 ++++-
>>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/eventpoll.c b/fs/eventpoll.c
>>>> index c4159bcc05d9..fa71468dbd51 100644
>>>> --- a/fs/eventpoll.c
>>>> +++ b/fs/eventpoll.c
>>>> @@ -685,6 +685,9 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep,
>>>>      if (!ep_locked)
>>>>              mutex_lock_nested(&ep->mtx, depth);
>>>>
>>>> +    if (!depth || list_empty_careful(&ep->rdllist))
>>>> +            pwake++;
>>>> +

This is the check I'm wondering why it's needed?

Thanks,


-Jason


  reply	other threads:[~2019-09-24 15:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19  9:24 [PATCH RESEND v2] fs/epoll: Remove unnecessary wakeups of nested epoll that in ET mode hev
2019-09-20 16:00 ` Jason Baron
2019-09-23 15:33   ` Jason Baron
2019-09-24 14:06     ` Heiher
2019-09-24 15:18       ` Jason Baron [this message]
2019-09-25  1:55         ` Heiher

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=92a54917-0cdf-89ce-1fb1-f913156a1e0d@akamai.com \
    --to=jbaron@akamai.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=davidel@xmailserver.org \
    --cc=e@80x24.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=r@hev.cc \
    --cc=rpenyaev@suse.de \
    --cc=sridhar.samudrala@intel.com \
    --cc=torvalds@linux-foundation.org \
    --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).