From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6AFDC43603 for ; Thu, 5 Dec 2019 00:52:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8F62224658 for ; Thu, 5 Dec 2019 00:52:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="cyh1wea5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F62224658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3F1676B0DC2; Wed, 4 Dec 2019 19:52:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A5586B0DC4; Wed, 4 Dec 2019 19:52:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 290C06B0DC5; Wed, 4 Dec 2019 19:52:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 11F446B0DC2 for ; Wed, 4 Dec 2019 19:52:18 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id C8E8353B3 for ; Thu, 5 Dec 2019 00:52:17 +0000 (UTC) X-FDA: 76229261514.15.burn27_1401b2bf33048 X-HE-Tag: burn27_1401b2bf33048 X-Filterd-Recvd-Size: 4417 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Dec 2019 00:52:17 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A40724652; Thu, 5 Dec 2019 00:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575507136; bh=n3XHOIb1O1/Fpg8M8Q8fOcbMc776cbFndZJtvcDnXo8=; h=Date:From:To:Subject:In-Reply-To:From; b=cyh1wea5EFvm456OMCgM/7djH6h2hr4TVS5rymZDqrUIB3hsJUrsRNVc0EmuuGBs8 UFa1bo9h27T4+ZLzu/HQl4tMFMuuNgQdf8cElbgIKm77/+7fGaZ8mDkrz/1ZI+bEyq 8LhztLFHz5FjVttyYBijp7j3C3lDopPFOO1ykTes= Date: Wed, 04 Dec 2019 16:52:15 -0800 From: Andrew Morton To: akpm@linux-foundation.org, dave@stgolabs.net, davidel@xmailserver.org, e@80x24.org, jbaron@akamai.com, linux-mm@kvack.org, linux@dominikbrodowski.net, mm-commits@vger.kernel.org, r@hev.cc, rpenyaev@suse.de, sridhar.samudrala@intel.com, torvalds@linux-foundation.org, viro@ZenIV.linux.org.uk Subject: [patch 47/86] fs/epoll: remove unnecessary wakeups of nested epoll Message-ID: <20191205005215.Yl8CZJfsy%akpm@linux-foundation.org> In-Reply-To: <20191204164858.fe4ed8886e34ad9f3b34ea00@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Heiher Subject: fs/epoll: remove unnecessary wakeups of nested epoll 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 Link: http://lkml.kernel.org/r/20191009060516.3577-1-r@hev.cc Signed-off-by: hev Reviewed-by: Roman Penyaev Cc: Al Viro Cc: Davide Libenzi Cc: Davidlohr Bueso Cc: Dominik Brodowski Cc: Eric Wong Cc: Jason Baron Cc: Sridhar Samudrala Signed-off-by: Andrew Morton --- fs/eventpoll.c | 16 ---------------- 1 file changed, 16 deletions(-) --- a/fs/eventpoll.c~fs-epoll-remove-unnecessary-wakeups-of-nested-epoll +++ a/fs/eventpoll.c @@ -666,7 +666,6 @@ static __poll_t ep_scan_ready_list(struc void *priv, int depth, bool ep_locked) { __poll_t res; - int pwake = 0; struct epitem *epi, *nepi; LIST_HEAD(txlist); @@ -733,26 +732,11 @@ static __poll_t ep_scan_ready_list(struc */ 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; } _