Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp672977ybp; Wed, 9 Oct 2019 02:22:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYO74EJxcGleP1byclZgONO0rB5wS4EVrwd6ccWQWD1X2Vbub/2zn+NnJ6x4CNwqVSTfta X-Received: by 2002:a17:907:365:: with SMTP id rs5mr1810318ejb.121.1570612930860; Wed, 09 Oct 2019 02:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570612930; cv=none; d=google.com; s=arc-20160816; b=vl5TOezh0uUF+TgDZeFesz3kSAQ/qmb71m1dDTaVGeWbDs+fLT45rcOQRPQnCTDRhV OJYunUrbXW+DUmCq/0ZdQ6DaENjUgcPPfKWjBIrRivzVinlLZmcb3r08N6qlwYmWxKFg GHtamij6nLFKet/EZqoSQA61hUUzQ9e5xDVj2+dgmrhqWJlObo1EHfAtpUWtiW5TjeCF pGQclmsPg4KB7wogvSNSbVj6JooFPtwnguLDnnd+nB1Jch7fskENGD7mogwNFP6EzxJn SLJD+Xq46h1xezuK2XN2CZv1RV71Lo0ZPt75dE9TkkEAzZOeab/llzQALea02VAXkIg0 EduA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=PnYkdnss5cSDnIQ2rwjxmO2/RAr80SeZ/xr2vsnl534=; b=TItjC1UKMBlWIfQYp+4cTwYe7QhjvwosPhi6CipPouKXwGGr39A/GlqipAZtPL2IeL QwPlVqvPaFG0rfUPw6Yns3a98Y+HJrqdPKYT40U3+W/DfkNi+u/8jdvt3eEl3SIPbaCg 6OyCJR5PvpBoirr/dihRdbQZKrHbkzhwK3XakaNZQVEBwW/CMRAojUekDjIDSJhU5/GA VsnCfHNWl+/zObl0qcWc+SyReSZ68Fo3DjPDHW6RiZKe9fJirAidyKz/IvNHkXk6rN4J Nk1KfnrrZYrRFWJTrvqn+WKC/wfE7ZmIddcFC2yG/+wMw+NT9mX39GMCE0x6sNv8FL7Z YcMw== ARC-Authentication-Results: i=1; mx.google.com; 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 f23si757306eji.266.2019.10.09.02.21.47; Wed, 09 Oct 2019 02:22:10 -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; 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 S1730217AbfJIJVL (ORCPT + 99 others); Wed, 9 Oct 2019 05:21:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:60082 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725935AbfJIJVL (ORCPT ); Wed, 9 Oct 2019 05:21:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 47633AD00; Wed, 9 Oct 2019 09:21:08 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 09 Oct 2019 11:21:07 +0200 From: Roman Penyaev To: hev Cc: linux-fsdevel@vger.kernel.org, Al Viro , Andrew Morton , Davide Libenzi , Davidlohr Bueso , Dominik Brodowski , Eric Wong , Jason Baron , Linus Torvalds , Sridhar Samudrala , linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND v5] fs/epoll: Remove unnecessary wakeups of nested epoll In-Reply-To: <20191009060516.3577-1-r@hev.cc> References: <20191009060516.3577-1-r@hev.cc> Message-ID: <0911c1130bb79fd8c8e266bc7701b251@suse.de> X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-10-09 08:05, 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 > > We remove unnecessary wakeups to prevent the nested epoll that working > in edge- > triggered mode to waking up continuously. > > 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 | 16 ---------------- > 1 file changed, 16 deletions(-) > > diff --git a/fs/eventpoll.c b/fs/eventpoll.c > index c4159bcc05d9..75fccae100b5 100644 > --- a/fs/eventpoll.c > +++ b/fs/eventpoll.c > @@ -671,7 +671,6 @@ static __poll_t ep_scan_ready_list(struct eventpoll > *ep, > void *priv, int depth, bool ep_locked) > { > __poll_t res; > - int pwake = 0; > struct epitem *epi, *nepi; > LIST_HEAD(txlist); > > @@ -738,26 +737,11 @@ static __poll_t ep_scan_ready_list(struct > eventpoll *ep, > */ > list_splice(&txlist, &ep->rdllist); > __pm_relax(ep->ws); > - > - if (!list_empty(&ep->rdllist)) { > - /* > - * Wake up (if active) both the eventpoll wait list and > - * the ->poll() wait list (delayed after we release the lock). > - */ > - if (waitqueue_active(&ep->wq)) > - wake_up(&ep->wq); > - if (waitqueue_active(&ep->poll_wait)) > - pwake++; > - } > write_unlock_irq(&ep->lock); > > if (!ep_locked) > mutex_unlock(&ep->mtx); > > - /* We have to call this outside the lock */ > - if (pwake) > - ep_poll_safewake(&ep->poll_wait); > - > return res; > } This looks good to me. Heiher, mind to make kselftest out of your test suite? Reviewed-by: Roman Penyaev -- Roman