Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp415021imm; Thu, 26 Jul 2018 22:36:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfbiNezdXc7Q1M75qugL9+IlrcW2EzGIEU3dklPsqb9uMEpAySJ68JjHLem5S8mbFQxAGCG X-Received: by 2002:a17:902:6684:: with SMTP id e4-v6mr4682820plk.35.1532669777370; Thu, 26 Jul 2018 22:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532669777; cv=none; d=google.com; s=arc-20160816; b=WulH22GoVn5uo8fEey7IapPzhckRgT2I2cBJiQcJBKiaFxFZnyo3ib1OMIjmCF13iC MMwesDtssXhmcolMgVF0Pp0GQETPj/jBLjLshWZvdI33xU6zdCaK89E04XBk/2A3r33i n4p/LWbxMXZVjTJ9BYtvh8qwf2r/3CWrBC3/fCaDp1zxQTHYyq+nxLRfxLhVYcRdEJjd VAVxKROwWoNS4D5MXEFLSX/Dr8EkIWBBnP4dSdgMJ6anOok7zgHs4ABmSufM/f/Jvvao qMQNzE3IOwoLCft44KFIawnHquA0TWxLhKeE94BgsJ8LHVwDSrb8lWyls50DVIVNjp0s e1+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=uujV7i56T68SZrUkQb7flV31Dxm802ZRm10yv7fYWeE=; b=ZO9poh12kK74h8ntgrBNVpSrp1BN/YAqRjjSEZiBCPof8Qi7CpvzRDU5Bo28K8n4fV dmpLJGKCiAKRzMThEu4mEEzoeSPiP5MAaYywCbXMQ0Tg0/9jh0p3JTmeYxtz3S09lup5 0cpvHXeGGhb3tnrbS6xZer54OTnaQIP7XY+ewR6QD/H8h2Bb98mca1z8vxvtQghZVvpq 7LAMd3P84IvoBpzEdtGxfhS78NQPqmyvtLGzp/hLickrB4rXRWj1RLh6cjcO0uaV8ZQg K7xvc5MHDZqHyt2igcyYxu6wJdunw6THn3Xf3HUfabTZYAU4aGwhFCpqaKZ8CKrr5WdP 5ABg== 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 a8-v6si3033221pgl.568.2018.07.26.22.36.00; Thu, 26 Jul 2018 22:36:17 -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 S1729482AbeG0GzL (ORCPT + 99 others); Fri, 27 Jul 2018 02:55:11 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:33835 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725861AbeG0GzK (ORCPT ); Fri, 27 Jul 2018 02:55:10 -0400 Received: from linux-r8p5.suse.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Thu, 26 Jul 2018 23:34:59 -0600 From: Davidlohr Bueso To: akpm@linux-foundation.org Cc: jbaron@akamai.com, viro@zeniv.linux.org.uk, peterz@infradead.org, linux-kernel@vger.kernel.org, dave@stgolabs.net, Davidlohr Bueso Subject: [PATCH 1/2] fs/epoll: loosen irq safety in ep_poll() Date: Thu, 26 Jul 2018 22:34:31 -0700 Message-Id: <20180727053432.16679-2-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180727053432.16679-1-dave@stgolabs.net> References: <20180727053432.16679-1-dave@stgolabs.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to other calls, ep_poll() is not called with interrupts disabled, and we can therefore avoid the irq save/restore dance and just disable local irqs. In fact, the call should never be called in irq context at all, considering that the only path is epoll_wait(2) -> do_epoll_wait() -> ep_poll(). When running on a 2 socket 40-core (ht) IvyBridge a common pipe based epoll_wait(2) microbenchmark, the following performance improvements are seen: # threads vanilla dirty 1 1805587 2106412 2 1854064 2090762 4 1805484 2017436 8 1751222 1974475 16 1725299 1962104 32 1378463 1571233 64 787368 900784 Which is a pretty constantly near 15%. Also add a lockdep check such that we detect any mischief before deadlocking. Signed-off-by: Davidlohr Bueso --- fs/eventpoll.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index b5e43e11f1e3..88473e6271ef 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1746,11 +1746,12 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, int maxevents, long timeout) { int res = 0, eavail, timed_out = 0; - unsigned long flags; u64 slack = 0; wait_queue_entry_t wait; ktime_t expires, *to = NULL; + lockdep_assert_irqs_enabled(); + if (timeout > 0) { struct timespec64 end_time = ep_set_mstimeout(timeout); @@ -1763,7 +1764,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, * caller specified a non blocking operation. */ timed_out = 1; - spin_lock_irqsave(&ep->wq.lock, flags); + spin_lock_irq(&ep->wq.lock); goto check_events; } @@ -1772,7 +1773,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, if (!ep_events_available(ep)) ep_busy_loop(ep, timed_out); - spin_lock_irqsave(&ep->wq.lock, flags); + spin_lock_irq(&ep->wq.lock); if (!ep_events_available(ep)) { /* @@ -1814,11 +1815,11 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, break; } - spin_unlock_irqrestore(&ep->wq.lock, flags); + spin_unlock_irq(&ep->wq.lock); if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS)) timed_out = 1; - spin_lock_irqsave(&ep->wq.lock, flags); + spin_lock_irq(&ep->wq.lock); } __remove_wait_queue(&ep->wq, &wait); @@ -1828,7 +1829,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, /* Is it worth to try to dig for events ? */ eavail = ep_events_available(ep); - spin_unlock_irqrestore(&ep->wq.lock, flags); + spin_unlock_irq(&ep->wq.lock); /* * Try to transfer events to user space. In case we get 0 events and -- 2.16.4