Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1892742ybn; Thu, 26 Sep 2019 03:55:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxF5m4Vieu4+PPqlomNWni8syPyB696X+5F1N+w7qTm4VfKtD5Kpo5GY2lzVH9Zg73kbGg X-Received: by 2002:aa7:cb46:: with SMTP id w6mr2969723edt.238.1569495311413; Thu, 26 Sep 2019 03:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569495311; cv=none; d=google.com; s=arc-20160816; b=dMZ+jpvc47IO89tifp/DIeofLctccMw5YhIWWWi1m72IwEYQB1r0GYdzKQYI7gWxNb e9SUVQ2h4E+aKCkeMIj47hf3qLfkmskGNHKZBmAiWCeqafF+02twsEzBkTHYwV0X2UQl 6fGWf75k+w+kS+V97Cu3RN1oLs0H7rgL6aC3/rEhD9z+SkM6ipT7Yt3xL3dzJY0eDWOf 66u5NUktKXkdQTntScveRLVCECzxyfgFYEnakBzT3Hm6LdZJV2vHYmz5h4KPM8B/NtRA lMjsRCrqgZ2R5z2KX5XUmW2bgfrVL9b3jey9JxHaggNfbGGdEc9qo6FB4PHChD8F3SkN 4teQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KnrH0v0z3ukmxZZZVDlP/AkPyborUYw1x3C+Oh0uyjY=; b=cZYB/SbaN68tQ+AWh+dTkrw2IJWVY08S3a96GDilvL2sYIeb6WDNe7IOprAVetqV/X gDwcaT+Hfop3fwcf+wnMGWuag7D31aS/AmjNr8QbEu8rI5mrOEVZOdgEHoahfbdnWBPg xve8Yr2es8nkD20gkpUOtL55ch881CPf+AwqEf5duo/7Ee3N2zJNzKxsl/q//EZog+sD WnJlVD1qXlHs0T/oMrPfKFT6kjkg4KtLKBQKRcUsWxt44Xjo0Q2tI0EoTwT8K/McZxlZ aCxH/24tI0zSLO8QILGFqGOx9oM/g058PdsNi5bRgfEm7sBGPtb65gtqgoL3YaNgyJH3 w7Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hev-cc.20150623.gappssmtp.com header.s=20150623 header.b=1r+7wj1h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b26si801230eju.87.2019.09.26.03.54.47; Thu, 26 Sep 2019 03:55:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@hev-cc.20150623.gappssmtp.com header.s=20150623 header.b=1r+7wj1h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2633668AbfIYBzy (ORCPT + 99 others); Tue, 24 Sep 2019 21:55:54 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:34692 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725812AbfIYBzy (ORCPT ); Tue, 24 Sep 2019 21:55:54 -0400 Received: by mail-lj1-f193.google.com with SMTP id j19so3894462lja.1 for ; Tue, 24 Sep 2019 18:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hev-cc.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KnrH0v0z3ukmxZZZVDlP/AkPyborUYw1x3C+Oh0uyjY=; b=1r+7wj1h669ZQZ1Q36CDW0ti2s5mpg8ivKNi4O4P17FWWogctXLC8Ajf43UHZOLxsy oRIZO0foOlIzl75l0DToQdd6xzLOjT3liWLNo1F/2afK3LeewO+4D3ybWbBaEbHLHf0z pT9DPHZnT8Pls4zYBwXUZx1edeOsk08KqC2i+xvVM4dljvcot8VadAp0L5l/WTaCtf84 t1HGtax9Cn1CZ0nzmpIFO827C4ZaVxc+yMeLDhLcbQok9PXA89q+QfMkvCv7yct5ujRV nc/i7155TaKaIAPIdLnigGHakXOFtBOsbEyVlp5wLEH1WWJpSupZLEgxbS5iJPu7UhtG qahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KnrH0v0z3ukmxZZZVDlP/AkPyborUYw1x3C+Oh0uyjY=; b=kna7jlUKBw4p1xAkYLWOVuXj/dhMuXLAqgVgvedaWuy1Xptn21SJivok2MZOD9SbSF EhV7cn5+nxgnB20t7dOsRgfcaAEWbm69H5+eJbi1QKkQmKZs1FWObjhD6tNqtYF84Uaa 98gsEdnjfY/VsYXShLShwP3aO3PcDK1tbMrG2XNzZ9ZFdUfR6lwsBcoHy2bQCVHxXjKm xlImp6osdND1tm4SR83fBgrDopk5hU/+++Sr5mBgmJEuHjiUffWgILhoJrup7LFRmvoW t2TmxoY+jM226mPTCMRaLIdx/QpnubY75aRkUuPA1LpIknjArpaiRGBxdYppAAeKYVJt xnbA== X-Gm-Message-State: APjAAAWPA3u2xX4TK/YUJCngMx29nI3zycozdLT8xDxAGqBHxz0h2ExQ mJBIJarn9kf1BY/J5l0j6qvcULzfKqWs79THNR7NPA== X-Received: by 2002:a2e:3201:: with SMTP id y1mr4059819ljy.5.1569376551089; Tue, 24 Sep 2019 18:55:51 -0700 (PDT) MIME-Version: 1.0 References: <20190919092413.11141-1-r@hev.cc> <4379abe0-9f81-21b6-11ae-6eb3db79eeff@akamai.com> <5042e1e0-f49a-74c8-61f8-6903288110ac@akamai.com> <92a54917-0cdf-89ce-1fb1-f913156a1e0d@akamai.com> In-Reply-To: <92a54917-0cdf-89ce-1fb1-f913156a1e0d@akamai.com> From: Heiher Date: Wed, 25 Sep 2019 09:55:34 +0800 Message-ID: Subject: Re: [PATCH RESEND v2] fs/epoll: Remove unnecessary wakeups of nested epoll that in ET mode To: Jason Baron Cc: linux-fsdevel@vger.kernel.org, Al Viro , Andrew Morton , Davide Libenzi , Davidlohr Bueso , Dominik Brodowski , Eric Wong , Linus Torvalds , Roman Penyaev , Sridhar Samudrala , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Sep 24, 2019 at 11:19 PM Jason Baron wrote: > > > > On 9/24/19 10:06 AM, Heiher wrote: > > Hi, > > > > On Mon, Sep 23, 2019 at 11:34 PM Jason Baron wrote: > >> > >> > >> > >> On 9/20/19 12:00 PM, Jason Baron wrote: > >>> On 9/19/19 5:24 AM, hev wrote: > >>>> From: Heiher > >>>> > >>>> 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 > >>>> #include > >>>> #include > >>>> > >>>> 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 > >>>> Cc: Andrew Morton > >>>> Cc: Davide Libenzi > >>>> Cc: Davidlohr Bueso > >>>> Cc: Dominik Brodowski > >>>> Cc: Eric Wong > >>>> Cc: Jason Baron > >>>> Cc: Linus Torvalds > >>>> Cc: Roman Penyaev > >>>> Cc: Sridhar Samudrala > >>>> Cc: linux-kernel@vger.kernel.org > >>>> Cc: linux-fsdevel@vger.kernel.org > >>>> Signed-off-by: hev > >>>> --- > >>>> 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? You are right. This is not needed. Initially, I want to keep the original behavior of depth 0 for direct poll() in multi-threads. > > Thanks, > > > -Jason > -- Best regards! Hev https://hev.cc