Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2986837ybg; Mon, 28 Oct 2019 05:44:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuRvNfgnWaWtyOFdm/icMnzxoxtOT2xz0yNmIVCsrko0/YGnTRsM/2jEKZV2s/cFg4U9GE X-Received: by 2002:aa7:d95a:: with SMTP id l26mr9803624eds.12.1572266646432; Mon, 28 Oct 2019 05:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572266646; cv=none; d=google.com; s=arc-20160816; b=YOZFMAoAhSTB7uKdGbxXVtv1kRyQExV4R7hu44l1I/xDgR/mlVxjiaELjqlopIy6Z/ jEAfh3kAO7GFTclWtGXidTJDEkYOF2Asqu/DJ5qe48uzScyVXGHYX7Mggx28XQFwo4m2 WXMESqg2QO08JEgLY+h3N2n12xnWy4vP5imLN6zupxsvFYBaENEKNBqxVHdIjH7azoCK F63sNzqWXXLo3/a/1aNM0Pmf41dthJE67pCEYM+QPUnw8R/xmc5T3W7RbW+GF4ROpz9f 4QcC6+4aZMIh7XKg/lF50JyJfDVhnmzjzNO9V6i3T1TPwOqOR0wcaJ+hr9I+xPK8dOoE nh3Q== 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=1aMsAP2PxExyB/E1NoTV0dqnnfdxMUwdxPX5EmrFyzA=; b=CgVb9SI7ndnY/ppnHK7ry8Y1Y5u9SJgiM+itNmc6y3qMHogBE+KgywCri3qT5Qnh44 Wg+Ilr0sGAJn0z3dMNiblne6c0R/31iPYUEATpsMYwa4Qwuq1G+/QJlYrXibmTYNCEwl RQJgfzbOCXF18Dv8A9QG2yV6Me0Elf948pCdnv7eqeSnKkVQ2ec+jiGFK+Z9KPsKgQ28 mcpWQXXMzKM/o86tFfgOm3BPNj6Z2M/lWR9IFXb9OBDIjNiQjx8VOvB1UWczzt8Hnnqn ZLNVD9U7lIhEdFk/67KdKAlItwGTZkNhDHTGmXELmwqvUFa2VXAetiqvUdvYI5ffBiMP RITA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hev-cc.20150623.gappssmtp.com header.s=20150623 header.b=O77cxxp0; 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 d38si7674400eda.53.2019.10.28.05.43.38; Mon, 28 Oct 2019 05:44:06 -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=O77cxxp0; 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 S1728779AbfJ1A64 (ORCPT + 99 others); Sun, 27 Oct 2019 20:58:56 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36032 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727051AbfJ1A6z (ORCPT ); Sun, 27 Oct 2019 20:58:55 -0400 Received: by mail-lf1-f65.google.com with SMTP id u16so6481864lfq.3 for ; Sun, 27 Oct 2019 17:58:53 -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=1aMsAP2PxExyB/E1NoTV0dqnnfdxMUwdxPX5EmrFyzA=; b=O77cxxp0TiDbHCipSNxBDPQs6T3YuiXf2d6J838uRz/Yz+afk4zkR4cPIm4g3CsmLU +BQIeATLcLKQ3CnG6y/WT1V6Wder0rgPEQQOcvJLBXyqGsXF44D7R/iyUcHJZdJUnlQ5 +FKKNxPCswaqseS4VUyoitrkxGU/Xg/Mg6Nu6OYsvG4oOjj7V/sH3Aa+VajjKaSI5flC 5RfLygrqux7RvLJcNKY0PfyXkS0784Dgxwvw6BQAJQJgqUJGj4NUukHElgcB73eiWejp Ch8wzrgFhJkDlErFtU7bxaYsLF/DhvBa20f/1dphxEnP9jFGkBzHzVzXqvtA+jPR4iLu jC3A== 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=1aMsAP2PxExyB/E1NoTV0dqnnfdxMUwdxPX5EmrFyzA=; b=Vk4wYUrKuCPsZEzrDGjuAF8iVGZqYKhDD9XGk+xO35UBr6NRiLm/Pgp99nzTEd+PfF 7DjydrwCeWq7TyW5hUgInQs0UlE3UxDzdvKXGEFBrABQ4xPdTZ/85/+elxxjv5a0GRef enPgNVzDU3BdTF6T++7Al1/HpVt2RjBi/zYmvDOfw4MoJro17heMb3gewNgBgrvDP1pB nbfDJiFwlbQ8ynGnJLZiL3ro1cXZZ1nOLAuAzFcvcgco3oiumwIGpG4WY74vIulSKNvR HpDJHQk+y3eqt6fFKUHmSffOztCJ9dCnBHdR4cEVvvZD63p0HKQcfVHSaCs2KMVpgCBr gEWg== X-Gm-Message-State: APjAAAV7ETNEPtfNysv61C2duIIowSX8ge+pHyVdtzGwvjJnqS8fIGRS Oke+RcWaxvVd3Mv6ehNDzdkMkHbG962usNcG3Wj09Q== X-Received: by 2002:a05:6512:146:: with SMTP id m6mr47893lfo.98.1572224332997; Sun, 27 Oct 2019 17:58:52 -0700 (PDT) MIME-Version: 1.0 References: <20191009060516.3577-1-r@hev.cc> <0911c1130bb79fd8c8e266bc7701b251@suse.de> In-Reply-To: <0911c1130bb79fd8c8e266bc7701b251@suse.de> From: Heiher Date: Mon, 28 Oct 2019 08:58:35 +0800 Message-ID: Subject: Re: [PATCH RESEND v5] fs/epoll: Remove unnecessary wakeups of nested epoll To: stable@vger.kernel.org Cc: Roman Penyaev , 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 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 Wed, Oct 9, 2019 at 5:21 PM Roman Penyaev wrote: > > 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 > > > Need to back port this patch to stable branches? -- Best regards! Hev https://hev.cc