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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 72FB3C3F2CD for ; Wed, 4 Mar 2020 13:15:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4AED720838 for ; Wed, 4 Mar 2020 13:15:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rb1sGb7P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388155AbgCDNPU (ORCPT ); Wed, 4 Mar 2020 08:15:20 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41289 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388150AbgCDNPT (ORCPT ); Wed, 4 Mar 2020 08:15:19 -0500 Received: by mail-wr1-f65.google.com with SMTP id v4so2337558wrs.8; Wed, 04 Mar 2020 05:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4UBTK6J3rpVi/KYhKlg8PAB4+/xBpnflvxGLCxGBorc=; b=Rb1sGb7PqahV3DpcK/AKTrC/KysMpDn+NZphw2eb29LNUCKWwuhKTi6qkyKUl6iAcf s/Lf1fMUQDzoWT6RltAKD6StREKLIVLg/m7YZTeTbfeaddT/UPXwyPNANlm+DdoCqG5u ceREQs5zKKfdT4Oxh7ZWveLOoE6V+eAv0L3fJ3VNqg+DWwWQLGjEWnA6OnH+gJJsW1jq nyW0QjN3SP6fAKL0CxznXxJ0UAv7MnNCSV57rXtotU8R9/pcGj19kgJ390LgftjgQ20m 6Vc4AiTdPMewJyv8LWBqryJ5jDyxxdsvJcJx710oQnGC1OJ7TddUn5twZ64oq9x8gql3 iDUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4UBTK6J3rpVi/KYhKlg8PAB4+/xBpnflvxGLCxGBorc=; b=WWJz2frW5IE37JYvKwXd3qJyHr3aWOQ73fxUe0lqqEaBGvkrhVZXaeMXrqDXu2/HLb Gzoje8zoKg6xYJsXIt5W2Mku10gByBakMJ4moPgFvq+KOUg1bfmP0BvQf4BsTimEEPwo qiEjTiGMHeP2zCoUx3fcMlOKTygb9QzX66yPnq7qtUmS+7DpfV/3ip7lmTwWP5DY0k7S uwnUYta0mz7PMKrA0QFijBwabWpain7Joxgu29H4yAd48zcUGVbNvPkQo4eGWPFeJGUI eOvn2V5a56zYmOPaWvONadeBtQZruKyFvN+KSIE/vNaYWkPRdiOalNg3TcYfd2AGvzA9 140Q== X-Gm-Message-State: ANhLgQ2asVTT02S6CabzV5dBpuZKDJZHO235uxjyocD6UpkXfY49OFL4 42IPCH6tCpp/RDgzPLlN+ZMrvOtj X-Google-Smtp-Source: ADFU+vuNWLha8k9dLIwpqU+/2UgVvj6c57vLiCl9DSbhVVQCUisiZQP1Fh6yllpD6rODMNAD0GwKqA== X-Received: by 2002:a5d:494c:: with SMTP id r12mr3853586wrs.50.1583327716460; Wed, 04 Mar 2020 05:15:16 -0800 (PST) Received: from localhost.localdomain ([109.126.130.242]) by smtp.gmail.com with ESMTPSA id c14sm24746746wro.36.2020.03.04.05.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 05:15:16 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] io-wq: optimise out *next_work() double lock Date: Wed, 4 Mar 2020 16:14:11 +0300 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org When executing non-linked hashed work, io_worker_handle_work() will lock-unlock wqe->lock to update hash, and then immediately lock-unlock to get next work. Optimise this case and do lock/unlock only once. Signed-off-by: Pavel Begunkov --- fs/io-wq.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/io-wq.c b/fs/io-wq.c index 473af080470a..82e76011d409 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -474,11 +474,11 @@ static void io_worker_handle_work(struct io_worker *worker) { struct io_wqe *wqe = worker->wqe; struct io_wq *wq = wqe->wq; + unsigned hash = -1U; do { struct io_wq_work *work; - unsigned hash = -1U; - +get_next: /* * If we got some work, mark us as busy. If we didn't, but * the list isn't empty, it means we stalled on hashed work. @@ -524,9 +524,12 @@ static void io_worker_handle_work(struct io_worker *worker) spin_lock_irq(&wqe->lock); wqe->hash_map &= ~BIT_ULL(hash); wqe->flags &= ~IO_WQE_FLAG_STALLED; - spin_unlock_irq(&wqe->lock); /* dependent work is not hashed */ hash = -1U; + /* skip unnecessary unlock-lock wqe->lock */ + if (!work) + goto get_next; + spin_unlock_irq(&wqe->lock); } } while (work); -- 2.24.0