From patchwork Tue Jul 16 20:04:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11046683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB45C6C5 for ; Tue, 16 Jul 2019 20:06:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C87F528632 for ; Tue, 16 Jul 2019 20:06:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBCBE2864B; Tue, 16 Jul 2019 20:06:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BE0F28632 for ; Tue, 16 Jul 2019 20:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728484AbfGPUGm (ORCPT ); Tue, 16 Jul 2019 16:06:42 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:35845 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbfGPUGm (ORCPT ); Tue, 16 Jul 2019 16:06:42 -0400 Received: by mail-io1-f65.google.com with SMTP id o9so42082266iom.3 for ; Tue, 16 Jul 2019 13:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YpPNBtxxgX1u7wA3w0OrLT613m/T+xFEVWs19Z5CKHg=; b=U3KWzp9PeA/RDLZ2yZZTDu4dydzGsIijc/hCFJve3SJ7O7T+ih1wNYGIsnvF+08qEg cEtwTmdEneH/gyNve9FQXNC5XLPAa0NAIqqv4CLYZXzm0bMYi5yIz9Mtslzx3fYxtV/s 6fpFAJLjHCZ0BhmiHj88sCnmPvuthm3JGOWPaDNRVUP4zKbQsfJgtGiZ6WNOmQSvCWJV 2Y8TImA7lRby56JggxpHR+8e1gsILWvGUUIYXtcVUCcrNlRrsD6HNtx5pwdxyFsFGXBH rqRApdgDsuqCIRhTMYnqIVJ7aQtHLqcJwz0jb46TpEkoG+eF9gzYrbSExkh41st2P9gw nsag== 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:mime-version :content-transfer-encoding; bh=YpPNBtxxgX1u7wA3w0OrLT613m/T+xFEVWs19Z5CKHg=; b=unib7PI2hk73Y7/T8E0uRB0ram13I5UbHHgFJTMr05otaxDuWzzCp3hhKFLxNbXCHK uIISMJXzAkB37Wd8OyaCbVQnNmN2FMpjkRAeHRmwSk0ZmkWkg779c3nMaoHKjPa7QYer 0myAVhpMSx7Z6dHu21txQ2EJfZrHu5I7O6Fkw3NToXh36sOam+A0Jq9YtH738a/T2BAp Y+JfeFgPnPCimiUuCKFoT/b4K+Y0B/p8cda+gFZ67HeKlS+tYcdTE/J9uFBEW3nzAUvE 9yu6X1OyJejXDVDXhceSbHmOgZA35vmY5ke436r6/rn5EUv2FK1hpkGroIQby3NFrF6P gOQQ== X-Gm-Message-State: APjAAAUQOYGPyIR/QvF/pR0JQStzZGyB756oc+ca8DiKjmMRPJcz37rb h2t7pnwcCDDRf5YVdvlYQrZchAI= X-Google-Smtp-Source: APXvYqzwSZHNbkK0d5g2NTS5U9Yeb6yNuT31NeLsw3qmXMKwrLMm1L7KBHhbqeZK7Q9b0ztvZqurZw== X-Received: by 2002:a5e:881a:: with SMTP id l26mr8772513ioj.185.1563307601267; Tue, 16 Jul 2019 13:06:41 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id i3sm18393763ion.9.2019.07.16.13.06.40 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 13:06:40 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 1/3] SUNRPC: Replace division by multiplication in calculation of queue length Date: Tue, 16 Jul 2019 16:04:31 -0400 Message-Id: <20190716200433.38758-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When checking whether or not a particular xprt queue length is shorter than the average queue length for all xprts, prefer to use multiplication rather than division for performance reasons. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtmultipath.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 9d66ce53355d..5df4e7adedf0 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -322,7 +322,6 @@ struct rpc_xprt *xprt_iter_next_entry_roundrobin(struct rpc_xprt_iter *xpi) struct rpc_xprt *xprt; unsigned long xprt_queuelen; unsigned long xps_queuelen; - unsigned long xps_avglen; do { xprt = xprt_iter_next_entry_multiple(xpi, @@ -333,8 +332,8 @@ struct rpc_xprt *xprt_iter_next_entry_roundrobin(struct rpc_xprt_iter *xpi) if (xprt_queuelen <= 2) break; xps_queuelen = atomic_long_read(&xps->xps_queuelen); - xps_avglen = DIV_ROUND_UP(xps_queuelen, xps->xps_nactive); - } while (xprt_queuelen > xps_avglen); + /* Exit loop if xprt_queuelen <= average queue length */ + } while (xprt_queuelen * READ_ONCE(xps->xps_nactive) > xps_queuelen); return xprt; } From patchwork Tue Jul 16 20:04:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11046685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5D0A912 for ; Tue, 16 Jul 2019 20:06:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96B7128632 for ; Tue, 16 Jul 2019 20:06:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AADD2864B; Tue, 16 Jul 2019 20:06:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3837528632 for ; Tue, 16 Jul 2019 20:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728575AbfGPUGn (ORCPT ); Tue, 16 Jul 2019 16:06:43 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:44041 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbfGPUGn (ORCPT ); Tue, 16 Jul 2019 16:06:43 -0400 Received: by mail-io1-f66.google.com with SMTP id s7so41936858iob.11 for ; Tue, 16 Jul 2019 13:06:43 -0700 (PDT) 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=J2yoCGOjg3LPsc8qJBhIU19NmVWweLw6hJOioqM/2FY=; b=XGLFgdVgGKJmMki5w+v8kAGcWFGOu3i8nOH4GLlIVnTvAlBbJD2CEkgpoLHYlFgN1w 0wG9q9KIz/g75wvfebIPWazUWw4ja6xMFXKCzCvCULx59dQ/lK1mjid4gX3x6hLN0MPb YUbwUSNyjKpq2TJdriCNgRjS395knGAG9RhL1OfoZ1hD3h0dkSxQOz8+oN88ea00MZCC Ajx5mtczA9LiodGPPTnE1JpfF7IQ8XwG8e7UzmFTyFFxgwt+zld0cZgCC3BQdhDhuevN GIvurk0e8TUK0qA5W4r0e9nDbXir9mzKjBVARvTMl6l8vECteoedB/VcQJzKZLHRK2yH 8dSg== 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=J2yoCGOjg3LPsc8qJBhIU19NmVWweLw6hJOioqM/2FY=; b=ELeUktq/qjz5yJgUBNLUAWy9WiRRWuITOL3XVOJSPkV972VvXLNhd8E5kayLLTLMw7 IG9yYBf1sbZhxBJ/0mcsPMyfeTPa10SBnTQXHR7exxqYDTwm4KcHLFTDmdfhyY9BfjoY CjEy1U66uKWwFev3w47DS+C2ycCmyQl+LY+yOuaYcCedG5yKm4Nz+uzN/JJPlKMmFKZy WpXKnDoFdrJ6gWnKCeBpCVQifc1Q5XFeQk8G1h7Tmy6rt3Ls2WdkslTeJG6zzT9JjRTf t6oE2Nc/6Bf7bwG7r8H/IoHXJOFZCjBGKzD71gCz0YMhdE4lBQUNSuTbTFN7DKwxyuQo 5VNQ== X-Gm-Message-State: APjAAAUo+nvzh6vNe2zYBOS5L3krT0H28DyfkumfvTJGF1ojyO6HObw3 rxpvgR7V2+IyFL2astCpiFfcIpA= X-Google-Smtp-Source: APXvYqzl6bvB/0s2MlrCtWsfxQnC0tKJF7orS1v94L5ScCh3ZJdzuPgo+jkYBtm0TGpU6Mqwj0yTLg== X-Received: by 2002:a6b:b602:: with SMTP id g2mr32349555iof.54.1563307602067; Tue, 16 Jul 2019 13:06:42 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id i3sm18393763ion.9.2019.07.16.13.06.41 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 13:06:41 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] SUNRPC: Skip zero-refcount transports Date: Tue, 16 Jul 2019 16:04:32 -0400 Message-Id: <20190716200433.38758-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190716200433.38758-1-trond.myklebust@hammerspace.com> References: <20190716200433.38758-1-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When looking for the next transport to use for an RPC call, skip those that are in the process of being destroyed and that have a zero refcount. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtmultipath.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 5df4e7adedf0..c12778e1235e 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -193,10 +193,22 @@ void xprt_iter_default_rewind(struct rpc_xprt_iter *xpi) WRITE_ONCE(xpi->xpi_cursor, NULL); } +static +bool xprt_is_active(const struct rpc_xprt *xprt) +{ + return kref_read(&xprt->kref) != 0; +} + static struct rpc_xprt *xprt_switch_find_first_entry(struct list_head *head) { - return list_first_or_null_rcu(head, struct rpc_xprt, xprt_switch); + struct rpc_xprt *pos; + + list_for_each_entry_rcu(pos, head, xprt_switch) { + if (xprt_is_active(pos)) + return pos; + } + return NULL; } static @@ -214,9 +226,12 @@ struct rpc_xprt *xprt_switch_find_current_entry(struct list_head *head, const struct rpc_xprt *cur) { struct rpc_xprt *pos; + bool found = false; list_for_each_entry_rcu(pos, head, xprt_switch) { if (cur == pos) + found = true; + if (found && xprt_is_active(pos)) return pos; } return NULL; @@ -261,9 +276,12 @@ struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head, const struct rpc_xprt *cur) { struct rpc_xprt *pos, *prev = NULL; + bool found = false; list_for_each_entry_rcu(pos, head, xprt_switch) { if (cur == prev) + found = true; + if (found && xprt_is_active(pos)) return pos; prev = pos; } From patchwork Tue Jul 16 20:04:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11046687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 48FEC1510 for ; Tue, 16 Jul 2019 20:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39E3928632 for ; Tue, 16 Jul 2019 20:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DCA12864B; Tue, 16 Jul 2019 20:06:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D908628632 for ; Tue, 16 Jul 2019 20:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728366AbfGPUGo (ORCPT ); Tue, 16 Jul 2019 16:06:44 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:38327 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728781AbfGPUGo (ORCPT ); Tue, 16 Jul 2019 16:06:44 -0400 Received: by mail-io1-f66.google.com with SMTP id j6so9748181ioa.5 for ; Tue, 16 Jul 2019 13:06:43 -0700 (PDT) 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=atThEGgEE9DrVcla4yIbNh7r1fiMhKX/2srXNZ+dEKM=; b=udiWPPpXfZo/G8neCXtUqCvwkxN64QjxvpBe3X1TtU7drVBBAiiW5w7Dz0vxq7wOt6 4M1w2yo0FGW/qDk+1UVyGSgUlt6AXzF+DMMgCM8F06DqS9X/7VTCM0Mlz6T2nbpwX63C yfdPdWHgobYmAOlfnYF0A+TqoGVACxQ1w3Gvvl3f5gm7vFzx7pPLECKcvHzbpaEZSpxa 0sC/IyldnzSNE0qi9WO65eNUI/ehaLfB7bmKfSgGdwuI+XCwhA0DTqIIuayIHAP7Yy8h p/RHVgaZpHXmbSEuKk5QdeustTlkyJ0iEcLe8M4/O81f7h1svHMaFXmMF3pPkT25X6Xi oh4Q== 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=atThEGgEE9DrVcla4yIbNh7r1fiMhKX/2srXNZ+dEKM=; b=VvpOTGrUoG2tOGbmfrVrdM3LbwpPcWDpMl5NkAl1hcxwi/ReOuJFBOKHt2qWRhKKwn wHosYr0C8cl/0LDoB0JU7+9FQ8w5uCC02c591yjbS5ms6cgCg9br2XDsZX0tgjUoAYmS JO+qtZukNEg6mPds5GNq2a5P7U9GFEjomiQ00LzcqMesg1NhCvxQTl1Q9V+GRt4ePM4b tlGOdnmJeuQaxlhsHtW1UNUnmyfYY6nefLA4mVutwZh83mh3B1D09OJqMsulicvRQwQm DS1AQJ3QXkounDAH7LWSK+x18m2+9juDAhstn91j0ev3dsxvMsi00lFoDjuN61kOpH8K 9FnQ== X-Gm-Message-State: APjAAAWBBESI+kPhDH/zyrjwdg8vv0WJJucfGHnm2g5khjKyRIv4ZkbV rVJx7RpLQDAOJ2PLxUIX1QipaSU= X-Google-Smtp-Source: APXvYqybv9Ka3oIvXJmSsRrjiquTHlNFy8gYiRKLYO8M/8QxAhFBr+dWVPQmhd3Mk9snwGy3bavocg== X-Received: by 2002:a02:cb4b:: with SMTP id k11mr36547953jap.109.1563307602833; Tue, 16 Jul 2019 13:06:42 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id i3sm18393763ion.9.2019.07.16.13.06.42 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 13:06:42 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 3/3] SUNRPC: Fix a hang in xprt_switch_set_next_cursor() Date: Tue, 16 Jul 2019 16:04:33 -0400 Message-Id: <20190716200433.38758-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190716200433.38758-2-trond.myklebust@hammerspace.com> References: <20190716200433.38758-1-trond.myklebust@hammerspace.com> <20190716200433.38758-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Apparently we do need the memory barrier. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtmultipath.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index c12778e1235e..852da66cdaec 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -293,18 +293,14 @@ struct rpc_xprt *xprt_switch_set_next_cursor(struct list_head *head, struct rpc_xprt **cursor, xprt_switch_find_xprt_t find_next) { - struct rpc_xprt *cur, *pos, *old; + struct rpc_xprt *pos, *old; - cur = READ_ONCE(*cursor); - for (;;) { - old = cur; + old = READ_ONCE(*cursor); + do { pos = find_next(head, old); if (pos == NULL) break; - cur = cmpxchg_relaxed(cursor, old, pos); - if (cur == old) - break; - } + } while (!try_cmpxchg(cursor, &old, pos)); return pos; }