From patchwork Mon Oct 1 14:41:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622255 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 29B551515 for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10852290FE for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04EEF29437; Mon, 1 Oct 2018 14:42:24 +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 E8E28290FE for ; Mon, 1 Oct 2018 14:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728979AbeJAVUa (ORCPT ); Mon, 1 Oct 2018 17:20:30 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:34962 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729412AbeJAVUa (ORCPT ); Mon, 1 Oct 2018 17:20:30 -0400 Received: by mail-it1-f193.google.com with SMTP id p64-v6so4680342itp.0 for ; Mon, 01 Oct 2018 07:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oeW7mAQAuma2z4Ksiuh1ymQUPJ/EAwerpWX/+wfYyVk=; b=WdPhZ3D20b2QtPiC7y2FzzccaCJh0jV86LvGaC803Zf6GONYr82ysC6h8sgZcDWWm+ ZbY9+EQqZ97OJG4Zu/aW21ce6ZV7wIivoZlhWcuetclHuL1TyuV+/W0HhJkkpuIX//7S Yk6VjGhFRysPDYshKkyKnToOHrxS5+oceG8Be9R0HfgeqkLmfPiGsd4TI290IcvJ2zpR m3kWeNe1BjbdO8Hn63b0UWUqT/AFGssOUzuOXvHNfGUCaRNT3IcY9rgOD/ccjKWI8AmJ xoiFrs+gBCWLepKsmuzsUmHnHVRmBnCaOz1jscaiMVE41RKqZQAg8gtDLQnKZAbB4xcX vwEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oeW7mAQAuma2z4Ksiuh1ymQUPJ/EAwerpWX/+wfYyVk=; b=XfNckwqfAdMjOXAqfGdkHrCjTwHYvhn5ejnINiHmSEL0Hbdcm0D2j22W2Q1CHCRx4j Tf56W4/V6V317KIHed/U+FwBjyTVb5zUgyVDz4sKwqt6iyPprST16KvIKG1NsDSTHMDj nhirSpjIewuG8rSyOXzRBzzroGAD41GkzuXe5qtN3LDwFHGrkiJ8xQ8JYzWXNeZ6AFru BevM9oQnenumqkO+wgBaQ85C25zt20iior2c2QBpV9YPysQk18G5/M49VOeKpY2osWA5 n5W+MDUES82Zztl4HRLgYJr4kyfqvmpTqMFRYFjxdiuhEPEnbUOk19Y3A6GUC6oIl5Pc /Z5A== X-Gm-Message-State: ABuFfojyNStI+xbBv2J8VSAZQs2F7pVfitTsSKUOIv8v0tkpp1Wd6d3b wT+daidVXYrMEpbGwiTHqA== X-Google-Smtp-Source: ACcGV60utfQLTJa23Br2Tt0qJyAFhjDho30qx9H2mn+3o5xfQIfftRpGp60PD6XCguxT023ZTpcxxA== X-Received: by 2002:a24:6e90:: with SMTP id w138-v6mr10437920itc.50.1538404940823; Mon, 01 Oct 2018 07:42:20 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:20 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 01/15] SUNRPC: Remove the server 'authtab_lock' and just use RCU Date: Mon, 1 Oct 2018 10:41:43 -0400 Message-Id: <20181001144157.3515-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-1-trond.myklebust@hammerspace.com> References: <20181001144157.3515-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 Module removal is RCU safe by design, so we really have no need to lock the 'authtab[]' array. Signed-off-by: Trond Myklebust --- net/sunrpc/svcauth.c | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c index bb8db3cb8032..f83443856cd1 100644 --- a/net/sunrpc/svcauth.c +++ b/net/sunrpc/svcauth.c @@ -27,12 +27,32 @@ extern struct auth_ops svcauth_null; extern struct auth_ops svcauth_unix; -static DEFINE_SPINLOCK(authtab_lock); -static struct auth_ops *authtab[RPC_AUTH_MAXFLAVOR] = { - [0] = &svcauth_null, - [1] = &svcauth_unix, +static struct auth_ops __rcu *authtab[RPC_AUTH_MAXFLAVOR] = { + [RPC_AUTH_NULL] = (struct auth_ops __force __rcu *)&svcauth_null, + [RPC_AUTH_UNIX] = (struct auth_ops __force __rcu *)&svcauth_unix, }; +static struct auth_ops * +svc_get_auth_ops(rpc_authflavor_t flavor) +{ + struct auth_ops *aops; + + if (flavor >= RPC_AUTH_MAXFLAVOR) + return NULL; + rcu_read_lock(); + aops = rcu_dereference(authtab[flavor]); + if (aops != NULL && !try_module_get(aops->owner)) + aops = NULL; + rcu_read_unlock(); + return aops; +} + +static void +svc_put_auth_ops(struct auth_ops *aops) +{ + module_put(aops->owner); +} + int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp) { @@ -45,14 +65,11 @@ svc_authenticate(struct svc_rqst *rqstp, __be32 *authp) dprintk("svc: svc_authenticate (%d)\n", flavor); - spin_lock(&authtab_lock); - if (flavor >= RPC_AUTH_MAXFLAVOR || !(aops = authtab[flavor]) || - !try_module_get(aops->owner)) { - spin_unlock(&authtab_lock); + aops = svc_get_auth_ops(flavor); + if (aops == NULL) { *authp = rpc_autherr_badcred; return SVC_DENIED; } - spin_unlock(&authtab_lock); rqstp->rq_auth_slack = 0; init_svc_cred(&rqstp->rq_cred); @@ -82,7 +99,7 @@ int svc_authorise(struct svc_rqst *rqstp) if (aops) { rv = aops->release(rqstp); - module_put(aops->owner); + svc_put_auth_ops(aops); } return rv; } @@ -90,13 +107,14 @@ int svc_authorise(struct svc_rqst *rqstp) int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops) { + struct auth_ops *old; int rv = -EINVAL; - spin_lock(&authtab_lock); - if (flavor < RPC_AUTH_MAXFLAVOR && authtab[flavor] == NULL) { - authtab[flavor] = aops; - rv = 0; + + if (flavor < RPC_AUTH_MAXFLAVOR) { + old = cmpxchg((struct auth_ops ** __force)&authtab[flavor], NULL, aops); + if (old == NULL || old == aops) + rv = 0; } - spin_unlock(&authtab_lock); return rv; } EXPORT_SYMBOL_GPL(svc_auth_register); @@ -104,10 +122,8 @@ EXPORT_SYMBOL_GPL(svc_auth_register); void svc_auth_unregister(rpc_authflavor_t flavor) { - spin_lock(&authtab_lock); if (flavor < RPC_AUTH_MAXFLAVOR) - authtab[flavor] = NULL; - spin_unlock(&authtab_lock); + rcu_assign_pointer(authtab[flavor], NULL); } EXPORT_SYMBOL_GPL(svc_auth_unregister); From patchwork Mon Oct 1 14:41:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622257 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 70B1715E8 for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5677A290FE for ; Mon, 1 Oct 2018 14:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ABD429396; Mon, 1 Oct 2018 14:42:24 +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 D50A92921C for ; Mon, 1 Oct 2018 14:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729485AbeJAVUb (ORCPT ); Mon, 1 Oct 2018 17:20:31 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:34964 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729439AbeJAVUb (ORCPT ); Mon, 1 Oct 2018 17:20:31 -0400 Received: by mail-it1-f194.google.com with SMTP id p64-v6so4680427itp.0 for ; Mon, 01 Oct 2018 07:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EyqehmR6Yh9itft/l3clEx2F4fuErUdjxJsQGuOgJws=; b=uYFDQpcF0t59usy12FkCijs3f/i7N0V/9izPylwrgmY66/338rSiV4ntw+sjNAT6u7 QhO1wRorXkcdISGpfoi+ERKU+q+UuPw9lcPCKYj7J+7t4s2Tq3M970cNc/8b78ItR/Cm RW0pLIz/SSx65bzNu2A9pDqCVi/AcNCQuxd92rw8YSoL5Wa7Z7REHO/NnhxxtykRCbu9 tR45P7NhlK6ExClqGO53St/9z1chc0jTh6rJ2pO8ecPt4N2IUziYdY5FqyxGHmqXn7+k CXrJZFoYJy6FdpLA3D8pdPMCoUrpPTlcOOZCRDUQ1CkPvDwzOroqi3yXVUAkzAKzN6bQ 24zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EyqehmR6Yh9itft/l3clEx2F4fuErUdjxJsQGuOgJws=; b=Lz1VVXkfwOhkul5gihgCXzSXX7zBu+63ggZlsX1OcQ11xV3QBWkPTTFlXGGhR7HOPX O21EH+RfliDTfZOie2OluQNv6a7jytn4A8SV5yHjp3Bw8hX6Dv1vb5GoORCArQb6xR1U Zjs/yp0dsaXNN7UZ4aAOL75LXA+dsHgNQWqcuCAYt+ilEcrKaOaM77dyEENNN1fMgDfI yltxsY2rrzQtiCUwQuJNvUT62V5ei1sI1M9IhPcKc3UsZ2Gdhw5nyAJ0pe7FP+sO67mo JaT4kgYpiVb3JTTi50obfTsv6QciI6608v412c7GkOdSRF8zpQVoYa+pLU0Noxp0OLFw XSkw== X-Gm-Message-State: ABuFfoipodfco8IT4Y5jMcQtE+b+9HjmrtJ8zfThjPfvI0XfgJXGM04b MazcXtbd/OlsTX09WmjWlprIBJA= X-Google-Smtp-Source: ACcGV615JDbEgNKDDOZzm8FRzT3Dt3bXF/iuhuVRR/kANV2CMci1KDUqleyoFsmtHo+3xBX8KjgjhA== X-Received: by 2002:a02:b015:: with SMTP id p21-v6mr8456603jah.2.1538404941625; Mon, 01 Oct 2018 07:42:21 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:21 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 02/15] SUNRPC: Add lockless lookup of the server's auth domain Date: Mon, 1 Oct 2018 10:41:44 -0400 Message-Id: <20181001144157.3515-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-2-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-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 Avoid taking the global auth_domain_lock in most lookups of the auth domain by adding an RCU protected lookup. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/svcauth.h | 1 + net/sunrpc/auth_gss/svcauth_gss.c | 9 ++++++++- net/sunrpc/svcauth.c | 22 +++++++++++++++++++--- net/sunrpc/svcauth_unix.c | 10 ++++++++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h index 04e404a07882..3e53a6e2ada7 100644 --- a/include/linux/sunrpc/svcauth.h +++ b/include/linux/sunrpc/svcauth.h @@ -82,6 +82,7 @@ struct auth_domain { struct hlist_node hash; char *name; struct auth_ops *flavour; + struct rcu_head rcu_head; }; /* diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 860f2a1bbb67..87c71fb0f0ea 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -1764,14 +1764,21 @@ svcauth_gss_release(struct svc_rqst *rqstp) } static void -svcauth_gss_domain_release(struct auth_domain *dom) +svcauth_gss_domain_release_rcu(struct rcu_head *head) { + struct auth_domain *dom = container_of(head, struct auth_domain, rcu_head); struct gss_domain *gd = container_of(dom, struct gss_domain, h); kfree(dom->name); kfree(gd); } +static void +svcauth_gss_domain_release(struct auth_domain *dom) +{ + call_rcu(&dom->rcu_head, svcauth_gss_domain_release_rcu); +} + static struct auth_ops svcauthops_gss = { .name = "rpcsec_gss", .owner = THIS_MODULE, diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c index f83443856cd1..775b8c94265b 100644 --- a/net/sunrpc/svcauth.c +++ b/net/sunrpc/svcauth.c @@ -143,10 +143,11 @@ static struct hlist_head auth_domain_table[DN_HASHMAX]; static DEFINE_SPINLOCK(auth_domain_lock); static void auth_domain_release(struct kref *kref) + __releases(&auth_domain_lock) { struct auth_domain *dom = container_of(kref, struct auth_domain, ref); - hlist_del(&dom->hash); + hlist_del_rcu(&dom->hash); dom->flavour->domain_release(dom); spin_unlock(&auth_domain_lock); } @@ -175,7 +176,7 @@ auth_domain_lookup(char *name, struct auth_domain *new) } } if (new) - hlist_add_head(&new->hash, head); + hlist_add_head_rcu(&new->hash, head); spin_unlock(&auth_domain_lock); return new; } @@ -183,6 +184,21 @@ EXPORT_SYMBOL_GPL(auth_domain_lookup); struct auth_domain *auth_domain_find(char *name) { - return auth_domain_lookup(name, NULL); + struct auth_domain *hp; + struct hlist_head *head; + + head = &auth_domain_table[hash_str(name, DN_HASHBITS)]; + + rcu_read_lock(); + hlist_for_each_entry_rcu(hp, head, hash) { + if (strcmp(hp->name, name)==0) { + if (!kref_get_unless_zero(&hp->ref)) + hp = NULL; + rcu_read_unlock(); + return hp; + } + } + rcu_read_unlock(); + return NULL; } EXPORT_SYMBOL_GPL(auth_domain_find); diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index af7f28fb8102..84cf39021a03 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -37,20 +37,26 @@ struct unix_domain { extern struct auth_ops svcauth_null; extern struct auth_ops svcauth_unix; -static void svcauth_unix_domain_release(struct auth_domain *dom) +static void svcauth_unix_domain_release_rcu(struct rcu_head *head) { + struct auth_domain *dom = container_of(head, struct auth_domain, rcu_head); struct unix_domain *ud = container_of(dom, struct unix_domain, h); kfree(dom->name); kfree(ud); } +static void svcauth_unix_domain_release(struct auth_domain *dom) +{ + call_rcu(&dom->rcu_head, svcauth_unix_domain_release_rcu); +} + struct auth_domain *unix_domain_find(char *name) { struct auth_domain *rv; struct unix_domain *new = NULL; - rv = auth_domain_lookup(name, NULL); + rv = auth_domain_find(name); while(1) { if (rv) { if (new && rv != &new->h) From patchwork Mon Oct 1 14:41:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622261 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 41B3015E8 for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26CB629396 for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ADCA29437; Mon, 1 Oct 2018 14:42:27 +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 D8C5B28DDB for ; Mon, 1 Oct 2018 14:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729439AbeJAVUd (ORCPT ); Mon, 1 Oct 2018 17:20:33 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:50876 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729412AbeJAVUd (ORCPT ); Mon, 1 Oct 2018 17:20:33 -0400 Received: by mail-it1-f193.google.com with SMTP id j81-v6so11613807ite.0 for ; Mon, 01 Oct 2018 07:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WYUFncLvX+nJvjh8jIembtBP/JCh93yDdlYuvYybUV4=; b=T9kArwM9mqmjuD+aR7345/bBtvbthyACMhGcYdZykKtPm+C+rDPqHz8K+n3qRUzDBx 26BRj36pGzoR+SjRGDPu3BRtuKwkriwACP7NiHtVafppDEb5jq5wsnpJWF1Px6Iefks1 yi1vfBbyc+a6CROHpEGUPCgrKY4ToNcONCm1Meb+uJQ2WMfLhc88W9+nWroSRVoDSd0K BocEPbJBVllivlALHc34Un1OOlxlEGucKkiplGhanWXxV75IC/rwgykRuYye3H3MOwtH RE1nJHlOIN9mQ6oQw6ZWEgOmHIgFpOdrZLnjudhx8kC5tvh6Y17yDXUrYoeRJdqYsZbB RmKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WYUFncLvX+nJvjh8jIembtBP/JCh93yDdlYuvYybUV4=; b=TdaCZw7i8EvgW9Vxfd0O2n0Zec6JJRPalrjfgf2DglpWeI8FPfsgtTy5iaDS0sImr5 cwK5cU1v4UxR1RgQU28XPme55gQblBEeJvfW2TDtb4HFB8FH3PgXuK869QbDao9JDSqI 2uOqvhpYYLKGdNnko9PfQb74tUhghqSbzQVOVi/5WDAQvWM+q17+rsHIWE6Oinxa1Qhk RDmUUkPnfy/wrrFDFZNjFMRNCjE7jCusLAiwwteL5CMYhZIDfKzCBviXH0XoPE8ZCGyM aYcPqO57gp60Oj17dUFSnqcgenADdRJ/SIT31kiTtLMM9C5UghfY6p9NF9mgWweiUsye G8+w== X-Gm-Message-State: ABuFfojdhEFp9t/bX5oF3R1wpoCxuuSby0dRYAUV9HD5Dpw3UTdOvizA /98t/v6V7J205u/f4qVp8g== X-Google-Smtp-Source: ACcGV63YDysH0B6cA6bqC/8GroAVTz7kM+JXpXM1q74C3v/i5W1bWvGaO/80wfN89p950gJ3J2J+ng== X-Received: by 2002:a02:702:: with SMTP id f2-v6mr8687126jaf.70.1538404942551; Mon, 01 Oct 2018 07:42:22 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:21 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 03/15] SUNRPC: Allow cache lookups to use RCU protection rather than the r/w spinlock Date: Mon, 1 Oct 2018 10:41:45 -0400 Message-Id: <20181001144157.3515-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-3-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-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 Instead of the reader/writer spinlock, allow cache lookups to use RCU for looking up entries. This is more efficient since modifications can occur while other entries are being looked up. Note that for now, we keep the reader/writer spinlock until all users have been converted to use RCU-safe freeing of their cache entries. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/cache.h | 12 ++++ net/sunrpc/cache.c | 122 +++++++++++++++++++++++++++++------ 2 files changed, 114 insertions(+), 20 deletions(-) diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 40d2822f0e2f..cf3e17ee2786 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -167,6 +167,9 @@ extern const struct file_operations cache_file_operations_pipefs; extern const struct file_operations content_file_operations_pipefs; extern const struct file_operations cache_flush_operations_pipefs; +extern struct cache_head * +sunrpc_cache_lookup_rcu(struct cache_detail *detail, + struct cache_head *key, int hash); extern struct cache_head * sunrpc_cache_lookup(struct cache_detail *detail, struct cache_head *key, int hash); @@ -186,6 +189,12 @@ static inline struct cache_head *cache_get(struct cache_head *h) return h; } +static inline struct cache_head *cache_get_rcu(struct cache_head *h) +{ + if (kref_get_unless_zero(&h->ref)) + return h; + return NULL; +} static inline void cache_put(struct cache_head *h, struct cache_detail *cd) { @@ -227,6 +236,9 @@ extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *); extern void *cache_seq_start(struct seq_file *file, loff_t *pos); extern void *cache_seq_next(struct seq_file *file, void *p, loff_t *pos); extern void cache_seq_stop(struct seq_file *file, void *p); +extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos); +extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos); +extern void cache_seq_stop_rcu(struct seq_file *file, void *p); extern void qword_add(char **bpp, int *lp, char *str); extern void qword_addhex(char **bpp, int *lp, char *buf, int blen); diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 109fbe591e7b..7593afed9036 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -54,16 +54,34 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail) h->last_refresh = now; } -struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, - struct cache_head *key, int hash) +static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, + struct cache_head *key, + int hash) { - struct cache_head *new = NULL, *freeme = NULL, *tmp = NULL; - struct hlist_head *head; + struct hlist_head *head = &detail->hash_table[hash]; + struct cache_head *tmp; + + rcu_read_lock(); + hlist_for_each_entry_rcu(tmp, head, cache_list) { + if (detail->match(tmp, key)) { + if (cache_is_expired(detail, tmp)) + continue; + tmp = cache_get_rcu(tmp); + rcu_read_unlock(); + return tmp; + } + } + rcu_read_unlock(); + return NULL; +} - head = &detail->hash_table[hash]; +static struct cache_head *sunrpc_cache_find(struct cache_detail *detail, + struct cache_head *key, int hash) +{ + struct hlist_head *head = &detail->hash_table[hash]; + struct cache_head *tmp; read_lock(&detail->hash_lock); - hlist_for_each_entry(tmp, head, cache_list) { if (detail->match(tmp, key)) { if (cache_is_expired(detail, tmp)) @@ -75,7 +93,15 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, } } read_unlock(&detail->hash_lock); - /* Didn't find anything, insert an empty entry */ + return NULL; +} + +static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, + struct cache_head *key, + int hash) +{ + struct cache_head *new, *tmp, *freeme = NULL; + struct hlist_head *head = &detail->hash_table[hash]; new = detail->alloc(); if (!new) @@ -90,10 +116,10 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, write_lock(&detail->hash_lock); /* check if entry appeared while we slept */ - hlist_for_each_entry(tmp, head, cache_list) { + hlist_for_each_entry_rcu(tmp, head, cache_list) { if (detail->match(tmp, key)) { if (cache_is_expired(detail, tmp)) { - hlist_del_init(&tmp->cache_list); + hlist_del_init_rcu(&tmp->cache_list); detail->entries --; freeme = tmp; break; @@ -105,7 +131,7 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, } } - hlist_add_head(&new->cache_list, head); + hlist_add_head_rcu(&new->cache_list, head); detail->entries++; cache_get(new); write_unlock(&detail->hash_lock); @@ -114,6 +140,31 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, cache_put(freeme, detail); return new; } + +struct cache_head *sunrpc_cache_lookup_rcu(struct cache_detail *detail, + struct cache_head *key, int hash) +{ + struct cache_head *ret; + + ret = sunrpc_cache_find_rcu(detail, key, hash); + if (ret) + return ret; + /* Didn't find anything, insert an empty entry */ + return sunrpc_cache_add_entry(detail, key, hash); +} +EXPORT_SYMBOL_GPL(sunrpc_cache_lookup_rcu); + +struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, + struct cache_head *key, int hash) +{ + struct cache_head *ret; + + ret = sunrpc_cache_find(detail, key, hash); + if (ret) + return ret; + /* Didn't find anything, insert an empty entry */ + return sunrpc_cache_add_entry(detail, key, hash); +} EXPORT_SYMBOL_GPL(sunrpc_cache_lookup); @@ -433,7 +484,7 @@ static int cache_clean(void) if (!cache_is_expired(current_detail, ch)) continue; - hlist_del_init(&ch->cache_list); + hlist_del_init_rcu(&ch->cache_list); current_detail->entries--; rv = 1; break; @@ -504,7 +555,7 @@ void cache_purge(struct cache_detail *detail) for (i = 0; i < detail->hash_size; i++) { head = &detail->hash_table[i]; hlist_for_each_entry_safe(ch, tmp, head, cache_list) { - hlist_del_init(&ch->cache_list); + hlist_del_init_rcu(&ch->cache_list); detail->entries--; set_bit(CACHE_CLEANED, &ch->flags); @@ -1289,21 +1340,19 @@ EXPORT_SYMBOL_GPL(qword_get); * get a header, then pass each real item in the cache */ -void *cache_seq_start(struct seq_file *m, loff_t *pos) - __acquires(cd->hash_lock) +static void *__cache_seq_start(struct seq_file *m, loff_t *pos) { loff_t n = *pos; unsigned int hash, entry; struct cache_head *ch; struct cache_detail *cd = m->private; - read_lock(&cd->hash_lock); if (!n--) return SEQ_START_TOKEN; hash = n >> 32; entry = n & ((1LL<<32) - 1); - hlist_for_each_entry(ch, &cd->hash_table[hash], cache_list) + hlist_for_each_entry_rcu(ch, &cd->hash_table[hash], cache_list) if (!entry--) return ch; n &= ~((1LL<<32) - 1); @@ -1315,9 +1364,19 @@ void *cache_seq_start(struct seq_file *m, loff_t *pos) if (hash >= cd->hash_size) return NULL; *pos = n+1; - return hlist_entry_safe(cd->hash_table[hash].first, + return hlist_entry_safe(rcu_dereference_raw( + hlist_first_rcu(&cd->hash_table[hash])), struct cache_head, cache_list); } + +void *cache_seq_start(struct seq_file *m, loff_t *pos) + __acquires(cd->hash_lock) +{ + struct cache_detail *cd = m->private; + + read_lock(&cd->hash_lock); + return __cache_seq_start(m, pos); +} EXPORT_SYMBOL_GPL(cache_seq_start); void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) @@ -1333,7 +1392,8 @@ void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) *pos += 1LL<<32; } else { ++*pos; - return hlist_entry_safe(ch->cache_list.next, + return hlist_entry_safe(rcu_dereference_raw( + hlist_next_rcu(&ch->cache_list)), struct cache_head, cache_list); } *pos &= ~((1LL<<32) - 1); @@ -1345,7 +1405,8 @@ void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) if (hash >= cd->hash_size) return NULL; ++*pos; - return hlist_entry_safe(cd->hash_table[hash].first, + return hlist_entry_safe(rcu_dereference_raw( + hlist_first_rcu(&cd->hash_table[hash])), struct cache_head, cache_list); } EXPORT_SYMBOL_GPL(cache_seq_next); @@ -1358,6 +1419,27 @@ void cache_seq_stop(struct seq_file *m, void *p) } EXPORT_SYMBOL_GPL(cache_seq_stop); +void *cache_seq_start_rcu(struct seq_file *m, loff_t *pos) + __acquires(RCU) +{ + rcu_read_lock(); + return __cache_seq_start(m, pos); +} +EXPORT_SYMBOL_GPL(cache_seq_start_rcu); + +void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos) +{ + return cache_seq_next(file, p, pos); +} +EXPORT_SYMBOL_GPL(cache_seq_next_rcu); + +void cache_seq_stop_rcu(struct seq_file *m, void *p) + __releases(RCU) +{ + rcu_read_unlock(); +} +EXPORT_SYMBOL_GPL(cache_seq_stop_rcu); + static int c_show(struct seq_file *m, void *p) { struct cache_head *cp = p; @@ -1846,7 +1928,7 @@ void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h) { write_lock(&cd->hash_lock); if (!hlist_unhashed(&h->cache_list)){ - hlist_del_init(&h->cache_list); + hlist_del_init_rcu(&h->cache_list); cd->entries--; write_unlock(&cd->hash_lock); cache_put(h, cd); From patchwork Mon Oct 1 14:41:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622259 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 AE0EE15E8 for ; Mon, 1 Oct 2018 14:42:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9446128DDB for ; Mon, 1 Oct 2018 14:42:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 887F92921C; Mon, 1 Oct 2018 14:42:25 +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 30C6328DDB for ; Mon, 1 Oct 2018 14:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729488AbeJAVUc (ORCPT ); Mon, 1 Oct 2018 17:20:32 -0400 Received: from mail-it1-f175.google.com ([209.85.166.175]:33194 "EHLO mail-it1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729439AbeJAVUc (ORCPT ); Mon, 1 Oct 2018 17:20:32 -0400 Received: by mail-it1-f175.google.com with SMTP id h6-v6so6420234ith.0 for ; Mon, 01 Oct 2018 07:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qVSxRVJ94ZzsO41/UtwA4gQwo9JqzGtPka1D0gFQ700=; b=PY2lKGkFJPdW69jAZCOZQOQO4KfGYKNaYSdAOvrJvpv8SF6tk3j+qWvSTFDgWRXwNI ksdJKDm4OdPyBn4i7Bw4WBW+06WB/kYxOcB9N9BwZ7quwWuKw2o75g1P9T3KgdMblIKb YDS/BypHVs/9WGkXGL7hhUn2/gT7yeyennAUyUS6gbBKCgf+LTHHE91faDadV1axCA2E iOqMQWaf1mhnRkUFutkBrJt4rh/l9r/ts8euwWCJeoGeoHr3quSTVfuX2IbGq5auelbf sLFDBjAbhGQaExqUDJ2B+A/NrGOOLuT9R7tKLoRxxBCWeO0MU9uW+EKXnZe5zqeoE9Ka yYbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qVSxRVJ94ZzsO41/UtwA4gQwo9JqzGtPka1D0gFQ700=; b=iU+TEL2allIEkViC/YtAw7vA+qFucURB51m6O0gul7Phl4e6fyJxNPZVh2QPpfW+cQ FfYjM2KNZw1qdCBF1gjMahZ/9i52DEyvZwZCWA7l/e8xSTx/a8Z3ZDBAYHHKgAHn4Yg1 YudfZ8vnvHPPZfvQJb5vqqVgjDvgt5q/tMR1E/J1BCQ9shdjE3c1mXJlh+xf3BKJQb0p A05IHWG3NocYfJnsT/vHxsG68KNgh3ufonXQQY+1wVOugF3MNZGynZBa0BNWALlolf4l joFxubLJyXYN52OSJAO20fMylmEsDNs1QWxui4I9oUM03saY928NIWU03QdkcWh+x6bf 3PRQ== X-Gm-Message-State: ABuFfojP6yJXQgo9S75JQsoCH8zMt9phez/Gsy60fwrbH7VfGaNy828r sU+1Qh7bCU0d6OEB2kfvdQ== X-Google-Smtp-Source: ACcGV62YyQDCLZGO2++x2hGIpO8w5dO953r0fLb84j826DpvHQCU42MUwhomcTRkrO/B1p4oSZjN0A== X-Received: by 2002:a24:aa41:: with SMTP id y1-v6mr10570954iti.91.1538404943268; Mon, 01 Oct 2018 07:42:23 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:22 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 04/15] SUNRPC: Make server side AUTH_UNIX use lockless lookups Date: Mon, 1 Oct 2018 10:41:46 -0400 Message-Id: <20181001144157.3515-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-4-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-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 Convert structs ip_map and unix_gid to use RCU protected lookups. Signed-off-by: Trond Myklebust --- net/sunrpc/svcauth_unix.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c index 84cf39021a03..fb9041b92f72 100644 --- a/net/sunrpc/svcauth_unix.c +++ b/net/sunrpc/svcauth_unix.c @@ -97,6 +97,7 @@ struct ip_map { char m_class[8]; /* e.g. "nfsd" */ struct in6_addr m_addr; struct unix_domain *m_client; + struct rcu_head m_rcu; }; static void ip_map_put(struct kref *kref) @@ -107,7 +108,7 @@ static void ip_map_put(struct kref *kref) if (test_bit(CACHE_VALID, &item->flags) && !test_bit(CACHE_NEGATIVE, &item->flags)) auth_domain_put(&im->m_client->h); - kfree(im); + kfree_rcu(im, m_rcu); } static inline int hash_ip6(const struct in6_addr *ip) @@ -286,9 +287,9 @@ static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class, strcpy(ip.m_class, class); ip.m_addr = *addr; - ch = sunrpc_cache_lookup(cd, &ip.h, - hash_str(class, IP_HASHBITS) ^ - hash_ip6(addr)); + ch = sunrpc_cache_lookup_rcu(cd, &ip.h, + hash_str(class, IP_HASHBITS) ^ + hash_ip6(addr)); if (ch) return container_of(ch, struct ip_map, h); @@ -418,6 +419,7 @@ struct unix_gid { struct cache_head h; kuid_t uid; struct group_info *gi; + struct rcu_head rcu; }; static int unix_gid_hash(kuid_t uid) @@ -432,7 +434,7 @@ static void unix_gid_put(struct kref *kref) if (test_bit(CACHE_VALID, &item->flags) && !test_bit(CACHE_NEGATIVE, &item->flags)) put_group_info(ug->gi); - kfree(ug); + kfree_rcu(ug, rcu); } static int unix_gid_match(struct cache_head *corig, struct cache_head *cnew) @@ -625,7 +627,7 @@ static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid) struct cache_head *ch; ug.uid = uid; - ch = sunrpc_cache_lookup(cd, &ug.h, unix_gid_hash(uid)); + ch = sunrpc_cache_lookup_rcu(cd, &ug.h, unix_gid_hash(uid)); if (ch) return container_of(ch, struct unix_gid, h); else From patchwork Mon Oct 1 14:41:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622263 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 5D8ED1515 for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44EA828DDB for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38B57290FE; Mon, 1 Oct 2018 14:42:27 +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 243C3290FE for ; Mon, 1 Oct 2018 14:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729412AbeJAVUd (ORCPT ); Mon, 1 Oct 2018 17:20:33 -0400 Received: from mail-it1-f180.google.com ([209.85.166.180]:51338 "EHLO mail-it1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729487AbeJAVUd (ORCPT ); Mon, 1 Oct 2018 17:20:33 -0400 Received: by mail-it1-f180.google.com with SMTP id 74-v6so11616676itw.1 for ; Mon, 01 Oct 2018 07:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W57GNgqkCOpLeo/mUUd3OvI+Mdmz1+HpFNBkxiS7DWk=; b=lZFuiR7DlDkeLouyFc5+nAEo+YdAEhppqr0Q3htcwM/VdrvMZk74tSf/SXwicHTfVm uhQCMAptNvMjuBY75qs9lJ+6EI26v5q9d7vTfKZYwiui1Dyu5owYgXuXT4973RX0tytp uliNar2aud3yGZ5fFwLcTDCKtwA5eaOp3VQs6EXAXqDKbSlO0ghNx7RmoDtkGplhkjyQ FR28wkRr1LJlBzvfgiQfZSmT2tvnG81q7kfedWv24Vcy2VIIxJKd2HIQkC9mh7+2AmFf 5piTCzzy2I7h+t/7p52CpLh+uhwesMQZ3O6uYIASPk5ej1Hsx+wYw6omQoyca9eRxdtg HJ6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W57GNgqkCOpLeo/mUUd3OvI+Mdmz1+HpFNBkxiS7DWk=; b=Uu4YUhPHRz4ssgZDYeuhW7Dg0FYVWCfhyQnijxO8FSmUkB80TnKNeIzQTrGx2T2M9v povX97h2lO2T8Yf8RjEKzCbbzguSvf5X50D/QGZ5Xo9voiAJtpbeSdrGNykuVLCc4RYG pcVhPpJSS2f5UlvA+eXVdJFPAWeeHQkZPF3bm3FWQdVMe29NJYPHR4c3/+DJJFLrNZAs xvExBqFkB+4l9+pQvnqFtk3ABWnAq7bBfR8T2TlRXZfe8xexd+9EXR/D2VcOlFGG4WDA kWsZvL/b828lMexn2Jjg7IegkZmK/l/QjxIcWgc6S1xX6V7fpWNIlEYInzSG14NE52HA +j+Q== X-Gm-Message-State: ABuFfogIVzBDRZMu768ki07BT3kIYkiZ7NoqU3Tjh3MD+5oynm1obU93 dYY6fZibVIk/7pvZ2iT+kHxxjE4= X-Google-Smtp-Source: ACcGV63eV/61VdFq8793b1TygA94liKoGuksWo2+tcIfO3Z9nuNnR8jcJX1xnI8slH1lB5x4POwLRQ== X-Received: by 2002:a24:1049:: with SMTP id 70-v6mr9672745ity.115.1538404944000; Mon, 01 Oct 2018 07:42:24 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:23 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 05/15] knfsd: Allow lockless lookups of the exports Date: Mon, 1 Oct 2018 10:41:47 -0400 Message-Id: <20181001144157.3515-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-5-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-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 Convert structs svc_expkey and svc_export to allow RCU protected lookups. Signed-off-by: Trond Myklebust --- fs/nfsd/export.c | 14 +++++++------- fs/nfsd/export.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index a1143f7c2201..802993d8912f 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -46,7 +46,7 @@ static void expkey_put(struct kref *ref) !test_bit(CACHE_NEGATIVE, &key->h.flags)) path_put(&key->ek_path); auth_domain_put(key->ek_client); - kfree(key); + kfree_rcu(key, ek_rcu); } static void expkey_request(struct cache_detail *cd, @@ -265,7 +265,7 @@ svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *item) struct cache_head *ch; int hash = svc_expkey_hash(item); - ch = sunrpc_cache_lookup(cd, &item->h, hash); + ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash); if (ch) return container_of(ch, struct svc_expkey, h); else @@ -314,7 +314,7 @@ static void svc_export_put(struct kref *ref) auth_domain_put(exp->ex_client); nfsd4_fslocs_free(&exp->ex_fslocs); kfree(exp->ex_uuid); - kfree(exp); + kfree_rcu(exp, ex_rcu); } static void svc_export_request(struct cache_detail *cd, @@ -780,7 +780,7 @@ svc_export_lookup(struct svc_export *exp) struct cache_head *ch; int hash = svc_export_hash(exp); - ch = sunrpc_cache_lookup(exp->cd, &exp->h, hash); + ch = sunrpc_cache_lookup_rcu(exp->cd, &exp->h, hash); if (ch) return container_of(ch, struct svc_export, h); else @@ -1216,9 +1216,9 @@ static int e_show(struct seq_file *m, void *p) } const struct seq_operations nfs_exports_op = { - .start = cache_seq_start, - .next = cache_seq_next, - .stop = cache_seq_stop, + .start = cache_seq_start_rcu, + .next = cache_seq_next_rcu, + .stop = cache_seq_stop_rcu, .show = e_show, }; diff --git a/fs/nfsd/export.h b/fs/nfsd/export.h index c8b74126ddaa..e7daa1f246f0 100644 --- a/fs/nfsd/export.h +++ b/fs/nfsd/export.h @@ -61,6 +61,7 @@ struct svc_export { u32 ex_layout_types; struct nfsd4_deviceid_map *ex_devid_map; struct cache_detail *cd; + struct rcu_head ex_rcu; }; /* an "export key" (expkey) maps a filehandlefragement to an @@ -75,6 +76,7 @@ struct svc_expkey { u32 ek_fsid[6]; struct path ek_path; + struct rcu_head ek_rcu; }; #define EX_ISSYNC(exp) (!((exp)->ex_flags & NFSEXP_ASYNC)) From patchwork Mon Oct 1 14:41:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622265 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 39E1115E8 for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F18A290FE for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 134AB29396; Mon, 1 Oct 2018 14:42:28 +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 041EE2921C for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729493AbeJAVUe (ORCPT ); Mon, 1 Oct 2018 17:20:34 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:37266 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729487AbeJAVUe (ORCPT ); Mon, 1 Oct 2018 17:20:34 -0400 Received: by mail-it1-f196.google.com with SMTP id m9-v6so11756973ita.2 for ; Mon, 01 Oct 2018 07:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r+Gug+c0xMBDhawUH83hv1SalLcTz8PprXfSPSIZcEk=; b=uhoOKNfLuqPIFZ8FL5x99wXyBfpmCPqGHkXxAAnd2vPauKD1/rPCXhVJDeXJPNuW5Y RjveHT5ed3FwT5SNmLB8KP+CknbHuH7dy8EYmw2QmkwNoLmJmkzdkYBeX6hIGbiaygdk HKFg0Vy4+XChL9cxl6guHqO55sXZug7GprrHp9CxOx64hAinjYSopd8aBEaIAXXvHQ/2 t/wnb76CiNQQOVUm12qFYNVzq5OK4ULFnN+oHYlVxgQ+RVSZ7uo60m8uDTS1EAKD3IiE 6cOHi+b7//BXCG6acjV4pvYyeqW246E6JJwG4qZfJ3ulEPk9T+f6Budpo+FvMjdSmwyn 1tqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r+Gug+c0xMBDhawUH83hv1SalLcTz8PprXfSPSIZcEk=; b=kv9Kx13CJrRyiOm0uS6QcE+JFuTijtdZwIzO4Yi/8vQN0hBV13sy44Ypw3BBvRXBFn 4sbqeLVF7icY3aakgfRdWA8Vu5Yq5nvcJZ3Yo5X8nv4NC65jcDbTMzxgmVy9eJDcWqFb 3/X/Lvuc1TQY+Qhx2BqMoZcSItYlkcyvFQNrEjF4upblxksFU1pcuteHWEYiqer4y2Nq S1wwQNE4dpxy97TiKVkWm/3lfaDXd25J00288AkWpVtoWUd7E02uqsUb7Ps83b56IL0r N30KmSfjpkfIWDHjPpmUwgICko2yxjEUPYFsnYdEyVD9XQPWBbQJrxW21gF+sbabL6GH sVYg== X-Gm-Message-State: ABuFfoiGmX8mY1OLxbu36pjm23zOLOLEeDrAGPwk4VOvLfNOxZIw7TRd HMvw2aToLdi1N52cTDr9zQ== X-Google-Smtp-Source: ACcGV61AXXPXeZw6IESdX3aI1cBMQy3wSvJN6iqbV/MT9SUdxkvaz/St/G8v6xNJZNJS3g0Y0uLD+Q== X-Received: by 2002:a24:75ca:: with SMTP id y193-v6mr9414241itc.70.1538404944764; Mon, 01 Oct 2018 07:42:24 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:24 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 06/15] SUNRPC: Lockless server RPCSEC_GSS context lookup Date: Mon, 1 Oct 2018 10:41:48 -0400 Message-Id: <20181001144157.3515-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-6-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-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 Use RCU protection for looking up the RPCSEC_GSS context. Signed-off-by: Trond Myklebust --- net/sunrpc/auth_gss/svcauth_gss.c | 32 +++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index 87c71fb0f0ea..1ece4bc3eb8d 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -76,6 +76,7 @@ struct rsi { struct xdr_netobj in_handle, in_token; struct xdr_netobj out_handle, out_token; int major_status, minor_status; + struct rcu_head rcu_head; }; static struct rsi *rsi_update(struct cache_detail *cd, struct rsi *new, struct rsi *old); @@ -89,13 +90,21 @@ static void rsi_free(struct rsi *rsii) kfree(rsii->out_token.data); } -static void rsi_put(struct kref *ref) +static void rsi_free_rcu(struct rcu_head *head) { - struct rsi *rsii = container_of(ref, struct rsi, h.ref); + struct rsi *rsii = container_of(head, struct rsi, rcu_head); + rsi_free(rsii); kfree(rsii); } +static void rsi_put(struct kref *ref) +{ + struct rsi *rsii = container_of(ref, struct rsi, h.ref); + + call_rcu(&rsii->rcu_head, rsi_free_rcu); +} + static inline int rsi_hash(struct rsi *item) { return hash_mem(item->in_handle.data, item->in_handle.len, RSI_HASHBITS) @@ -282,7 +291,7 @@ static struct rsi *rsi_lookup(struct cache_detail *cd, struct rsi *item) struct cache_head *ch; int hash = rsi_hash(item); - ch = sunrpc_cache_lookup(cd, &item->h, hash); + ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash); if (ch) return container_of(ch, struct rsi, h); else @@ -330,6 +339,7 @@ struct rsc { struct svc_cred cred; struct gss_svc_seq_data seqdata; struct gss_ctx *mechctx; + struct rcu_head rcu_head; }; static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old); @@ -343,12 +353,22 @@ static void rsc_free(struct rsc *rsci) free_svc_cred(&rsci->cred); } +static void rsc_free_rcu(struct rcu_head *head) +{ + struct rsc *rsci = container_of(head, struct rsc, rcu_head); + + kfree(rsci->handle.data); + kfree(rsci); +} + static void rsc_put(struct kref *ref) { struct rsc *rsci = container_of(ref, struct rsc, h.ref); - rsc_free(rsci); - kfree(rsci); + if (rsci->mechctx) + gss_delete_sec_context(&rsci->mechctx); + free_svc_cred(&rsci->cred); + call_rcu(&rsci->rcu_head, rsc_free_rcu); } static inline int @@ -542,7 +562,7 @@ static struct rsc *rsc_lookup(struct cache_detail *cd, struct rsc *item) struct cache_head *ch; int hash = rsc_hash(item); - ch = sunrpc_cache_lookup(cd, &item->h, hash); + ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash); if (ch) return container_of(ch, struct rsc, h); else From patchwork Mon Oct 1 14:41:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622267 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 CEE6B175A for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A3228DDB for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA01129396; Mon, 1 Oct 2018 14:42:28 +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 9DF7C28DDB for ; Mon, 1 Oct 2018 14:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729487AbeJAVUf (ORCPT ); Mon, 1 Oct 2018 17:20:35 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:37266 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729489AbeJAVUe (ORCPT ); Mon, 1 Oct 2018 17:20:34 -0400 Received: by mail-it1-f195.google.com with SMTP id m9-v6so11757022ita.2 for ; Mon, 01 Oct 2018 07:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=exobWiQB0XuVVgroWyhlm2fEEcib1Bp2VkLm7dx40X0=; b=hRvoj9nvBlMkWCKOEHRL/DTie6how3wYOmeFlMR4LFXHIjPAjKtqzKhduvZrtScYtt b78inYthRILi4Fpa38y77Q+E4t54nfrN/uRMqg9HXm8kNpdoQuX6yxcQ+NyNeskVT0FB vG73hK9o5qRSEiAl/jMrNGSpVc8MRMHY+zI7ufCwF1OnBrvvJUPNB40QPj5KY2fuKYxe MLX7Vda/OYth9RJC3bWt2ULzZFfbZuEmDKA+TPwz5UBeVFz4feTEsQfUwcHJOasSADDd 4tLEXxpCVv/8HrDqMZKvQn9KcvRUCrDcQq+Y8+yLhmtccLyDhP6Q3tiKy1W6VZFSp+Q4 8PoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=exobWiQB0XuVVgroWyhlm2fEEcib1Bp2VkLm7dx40X0=; b=He6/+ZYUoSylxdvcRp9eN4rsID2FWuWeClY6OKdo1Nqh9gQdY2v5mxgJQ7FkWq47GH Lg/g0eNTNFI7jzzWuoMyZGnIAwDq1TMID4mAB98V861/6XzJvsY33YxhV5+BVgxlIFx9 p0cRDYcBDvdjIk5OlBrmrf7eD2wfQLdbquiVU1xK664c4PxOGsEjLFuGZpRmG3R/4hF5 vpmZR08YoXLTAp5l/lGK0zrtvOe9jGbibRyLneZvC7CttHYE4cmIwDbb2R402m+5m5Ed z51PyggrTES4/yMc1/zU3JlKff9qEaQgEtNnioYX8nQCFYWV3CCJBNqIhHkpIBx8pe3I fxvQ== X-Gm-Message-State: ABuFfojJ1Nk1H9Q+6Tr0FI7sLm8KrpALpL9D8mymar5hwLQDfZDpBaQM 6Xpz6Qzca574XI9gSydPBw== X-Google-Smtp-Source: ACcGV61k5e9Rh5ReNmsd+3MG475/SUK2vjtPGrTR2BR77sXydSwVn2oA97DL/NFUZTAi1OlKmKJQeA== X-Received: by 2002:a24:9005:: with SMTP id x5-v6mr10396258itd.76.1538404945475; Mon, 01 Oct 2018 07:42:25 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:25 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 07/15] knfsd: Lockless lookup of NFSv4 identities. Date: Mon, 1 Oct 2018 10:41:49 -0400 Message-Id: <20181001144157.3515-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-7-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-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 Enable RCU protected lookups of the NFSv4 idmap. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4idmap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c index a5bb76593ce7..bf137fec33ff 100644 --- a/fs/nfsd/nfs4idmap.c +++ b/fs/nfsd/nfs4idmap.c @@ -65,6 +65,7 @@ struct ent { u32 id; char name[IDMAP_NAMESZ]; char authname[IDMAP_NAMESZ]; + struct rcu_head rcu_head; }; /* Common entry handling */ @@ -89,7 +90,7 @@ static void ent_put(struct kref *ref) { struct ent *map = container_of(ref, struct ent, h.ref); - kfree(map); + kfree_rcu(map, rcu_head); } static struct cache_head * @@ -264,8 +265,8 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen) static struct ent * idtoname_lookup(struct cache_detail *cd, struct ent *item) { - struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h, - idtoname_hash(item)); + struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h, + idtoname_hash(item)); if (ch) return container_of(ch, struct ent, h); else @@ -422,8 +423,8 @@ nametoid_parse(struct cache_detail *cd, char *buf, int buflen) static struct ent * nametoid_lookup(struct cache_detail *cd, struct ent *item) { - struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h, - nametoid_hash(item)); + struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h, + nametoid_hash(item)); if (ch) return container_of(ch, struct ent, h); else From patchwork Mon Oct 1 14:41:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622269 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 13E541515 for ; Mon, 1 Oct 2018 14:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE54428DDB for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E31612921C; Mon, 1 Oct 2018 14:42:28 +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 95BA6290FE for ; Mon, 1 Oct 2018 14:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729496AbeJAVUf (ORCPT ); Mon, 1 Oct 2018 17:20:35 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:38751 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729489AbeJAVUf (ORCPT ); Mon, 1 Oct 2018 17:20:35 -0400 Received: by mail-it1-f193.google.com with SMTP id i76-v6so6171241ita.3 for ; Mon, 01 Oct 2018 07:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0G2bnJBT9neJeBsYsT5N3sx16XxrZfyMnJJSzdPqCu4=; b=P5RD0HsgqqAZ3k2gklLGGyXIo4C3jwADGAYngZKMuCrnER3bHmDgISydm9HJqWZKzk YKTomxOERnjl7JXssa/gUuGXinV974Yv//sFa3TTs5+7Br3oDdaPG72WCfW+Oo6cOLH0 sm4o4yI16vuWxOKS621+bh1hWSaOVVb1ABNIL/+0YAVOFMaWyq4l7kTF/Wcu+xJlK/Xc Sgbg66Xj6lO4qJtOGui9QQGlXsAm3/2hlyF3bo+Nxl7MCzxWe1lE3VXqMHxGoexEyuli UcBqspr2iuoxS4cr8c1QbCfEdPhi9sOObvCwEjvAcATqgpDvhioF+FXtH8Y5B29hQFkX RpMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0G2bnJBT9neJeBsYsT5N3sx16XxrZfyMnJJSzdPqCu4=; b=KhgQTrODVSzx1KMsjsYV5y8GMDm47ysLWXuIc2FbeeInH4KaOARq9X+dtz74UNbwyk PSH3VsL5aEz+W/K1eiv5BMacKUzz8ViYyjPaeOKhBKFV9aEoA7LHwXLAwjjgYrAX8aHf bxoSkFAvBb+6fzUHSaPBaPlf6tMqihRlNEXTAfXfFrSHXbrP3lBtM7O1RdBYkCO6htyj sLMbmuw0c5oBFMA34IBARSU7jTQX33EEDKAKuZTJeSYN4fHMNbWk8GzrkAgQovcSQj5p Sa2Z4V+OS3xNKil8RMHHx3HdgiRpRYa2xjxikLOtXlgnLUjtTaI53iQANmb2ZYcr0y++ qtGw== X-Gm-Message-State: ABuFfohw6czBgGZVJc9v+3REJfydz9euhVu232xun3yYTMUDtcG7gYkb e6AdoP1sCEPLjQv+vod15w== X-Google-Smtp-Source: ACcGV63/ZG5i2ZCoXZAlR8IH+2eWDaTfhpXsgya83zxyCOeurqLtOZNEQZriedrKJni+JnEqvIXpPw== X-Received: by 2002:a24:d703:: with SMTP id y3-v6mr931763itg.154.1538404946508; Mon, 01 Oct 2018 07:42:26 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:25 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 08/15] NFS: Lockless DNS lookups Date: Mon, 1 Oct 2018 10:41:50 -0400 Message-Id: <20181001144157.3515-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-8-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-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 Enable RCU protected lookup in the legacy DNS resolver. Signed-off-by: Trond Myklebust --- fs/nfs/dns_resolve.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c index 060c658eab66..e93a5dc07c8c 100644 --- a/fs/nfs/dns_resolve.c +++ b/fs/nfs/dns_resolve.c @@ -65,6 +65,7 @@ struct nfs_dns_ent { struct sockaddr_storage addr; size_t addrlen; + struct rcu_head rcu_head; }; @@ -101,15 +102,23 @@ static void nfs_dns_ent_init(struct cache_head *cnew, } } -static void nfs_dns_ent_put(struct kref *ref) +static void nfs_dns_ent_free_rcu(struct rcu_head *head) { struct nfs_dns_ent *item; - item = container_of(ref, struct nfs_dns_ent, h.ref); + item = container_of(head, struct nfs_dns_ent, rcu_head); kfree(item->hostname); kfree(item); } +static void nfs_dns_ent_put(struct kref *ref) +{ + struct nfs_dns_ent *item; + + item = container_of(ref, struct nfs_dns_ent, h.ref); + call_rcu(item, nfs_dns_ent_free_rcu); +} + static struct cache_head *nfs_dns_ent_alloc(void) { struct nfs_dns_ent *item = kmalloc(sizeof(*item), GFP_KERNEL); @@ -195,7 +204,7 @@ static struct nfs_dns_ent *nfs_dns_lookup(struct cache_detail *cd, { struct cache_head *ch; - ch = sunrpc_cache_lookup(cd, + ch = sunrpc_cache_lookup_rcu(cd, &key->h, nfs_dns_hash(key)); if (!ch) From patchwork Mon Oct 1 14:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622271 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 B63A91515 for ; Mon, 1 Oct 2018 14:42:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CC3E28DDB for ; Mon, 1 Oct 2018 14:42:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 914852921C; Mon, 1 Oct 2018 14:42:30 +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 0602128DDB for ; Mon, 1 Oct 2018 14:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbeJAVUh (ORCPT ); Mon, 1 Oct 2018 17:20:37 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:55577 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729497AbeJAVUh (ORCPT ); Mon, 1 Oct 2018 17:20:37 -0400 Received: by mail-it1-f193.google.com with SMTP id c23-v6so11592901itd.5 for ; Mon, 01 Oct 2018 07:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KIWS7XTa7HqTkFbNNR3ZFmwRfkid2RjZO1WrsDEDHhI=; b=oAWNd5vVxzlqg9ulc0hhSIvJQJ+JSPbKIYRHlQw4dL8iL2mGLNVITeiGvBIKlg6dbp XFLppjK+0dxKAS+QHX/uPur9A63o7dcW/zcngLknkvWNLkBVatNOqB7l97NAck7fhQ58 i2s8vXfNawpg9WKOOhYrsH7LQIL0tcvKwAoJCYo5Nq23baw3Q8775ayA6Qe2dF9YwTnw OWpS8GR7nnwkyH1aDnn4aSVPG6hs81B8BcDD32QrPNqATRtsQaagOkr/L56kPUh4YBRt 5WGLPzbFGJWglhVhT8IJEIiM9MV0cKXWYmSljUBnWpanhJjiuiZgHPmGNMbzvd+buJTG 5S7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KIWS7XTa7HqTkFbNNR3ZFmwRfkid2RjZO1WrsDEDHhI=; b=VkCtMFoejKdpsoGp0GhC6FnmiUf5Pj87IvrXTQno4tlp0Nr2VTiCAGEXGA7MTFyNvO Xdbdtv1he4ueQ7yF6Mnq21tlkT1oh9oEdHlchV5lRa7LwqrxwOgqVFP+I2F4M4ymAzSK 7Zf96kcPMymTXhbZp6mN3DUZaFvMkH6dKI1yobUrVRa96yRC6961YiZtcSDs90st61bv EUOd5k7fKzo7l8Zi8QahNg+70oI2IbcQmBxsBiH73DT24A3Z7rmSrHfQqyCHrnyITD4q +HD5h5oc7dk1QYYxwDZ1qY+jqOHfmsD2aN2lfVxGC+c3t+9OiXtSH6YugYPWoxSpD9tH JMWQ== X-Gm-Message-State: ABuFfojnLChrxtbZIC4Tcakw2e/zARS2aD1Vt10oRlJ2iJg02D/Oa6by dGTJcmBDRqEb20sHmCtEFhPs+eY= X-Google-Smtp-Source: ACcGV63xmKHzO8IAYqW3WT+XBlmhQmBZTzaQ/xrRwUszz/lrZOYyrph/0GAUl6jzdrB2fHfDWu9AtQ== X-Received: by 2002:a24:e47:: with SMTP id 68-v6mr10977878ite.23.1538404947597; Mon, 01 Oct 2018 07:42:27 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:26 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 09/15] SUNRPC: Remove non-RCU protected lookup Date: Mon, 1 Oct 2018 10:41:51 -0400 Message-Id: <20181001144157.3515-10-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-9-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-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 Clean up the cache code by removing the non-RCU protected lookup. Signed-off-by: Trond Myklebust --- Documentation/filesystems/nfs/rpc-cache.txt | 6 +- include/linux/sunrpc/cache.h | 6 -- net/sunrpc/cache.c | 61 ++------------------- 3 files changed, 7 insertions(+), 66 deletions(-) diff --git a/Documentation/filesystems/nfs/rpc-cache.txt b/Documentation/filesystems/nfs/rpc-cache.txt index ebcaaee21616..c4dac829db0f 100644 --- a/Documentation/filesystems/nfs/rpc-cache.txt +++ b/Documentation/filesystems/nfs/rpc-cache.txt @@ -84,7 +84,7 @@ Creating a Cache A message from user space has arrived to fill out a cache entry. It is in 'buf' of length 'len'. cache_parse should parse this, find the item in the - cache with sunrpc_cache_lookup, and update the item + cache with sunrpc_cache_lookup_rcu, and update the item with sunrpc_cache_update. @@ -95,7 +95,7 @@ Creating a Cache Using a cache ------------- -To find a value in a cache, call sunrpc_cache_lookup passing a pointer +To find a value in a cache, call sunrpc_cache_lookup_rcu passing a pointer to the cache_head in a sample item with the 'key' fields filled in. This will be passed to ->match to identify the target entry. If no entry is found, a new entry will be create, added to the cache, and @@ -116,7 +116,7 @@ item does become valid, the deferred copy of the request will be revisited (->revisit). It is expected that this method will reschedule the request for processing. -The value returned by sunrpc_cache_lookup can also be passed to +The value returned by sunrpc_cache_lookup_rcu can also be passed to sunrpc_cache_update to set the content for the item. A second item is passed which should hold the content. If the item found by _lookup has valid data, then it is discarded and a new item is created. This diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index cf3e17ee2786..c3d67e893430 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -171,9 +171,6 @@ extern struct cache_head * sunrpc_cache_lookup_rcu(struct cache_detail *detail, struct cache_head *key, int hash); extern struct cache_head * -sunrpc_cache_lookup(struct cache_detail *detail, - struct cache_head *key, int hash); -extern struct cache_head * sunrpc_cache_update(struct cache_detail *detail, struct cache_head *new, struct cache_head *old, int hash); @@ -233,9 +230,6 @@ extern void sunrpc_cache_unregister_pipefs(struct cache_detail *); extern void sunrpc_cache_unhash(struct cache_detail *, struct cache_head *); /* Must store cache_detail in seq_file->private if using next three functions */ -extern void *cache_seq_start(struct seq_file *file, loff_t *pos); -extern void *cache_seq_next(struct seq_file *file, void *p, loff_t *pos); -extern void cache_seq_stop(struct seq_file *file, void *p); extern void *cache_seq_start_rcu(struct seq_file *file, loff_t *pos); extern void *cache_seq_next_rcu(struct seq_file *file, void *p, loff_t *pos); extern void cache_seq_stop_rcu(struct seq_file *file, void *p); diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 7593afed9036..593cf8607414 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -75,27 +75,6 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, return NULL; } -static struct cache_head *sunrpc_cache_find(struct cache_detail *detail, - struct cache_head *key, int hash) -{ - struct hlist_head *head = &detail->hash_table[hash]; - struct cache_head *tmp; - - read_lock(&detail->hash_lock); - hlist_for_each_entry(tmp, head, cache_list) { - if (detail->match(tmp, key)) { - if (cache_is_expired(detail, tmp)) - /* This entry is expired, we will discard it. */ - break; - cache_get(tmp); - read_unlock(&detail->hash_lock); - return tmp; - } - } - read_unlock(&detail->hash_lock); - return NULL; -} - static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, struct cache_head *key, int hash) @@ -154,20 +133,6 @@ struct cache_head *sunrpc_cache_lookup_rcu(struct cache_detail *detail, } EXPORT_SYMBOL_GPL(sunrpc_cache_lookup_rcu); -struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, - struct cache_head *key, int hash) -{ - struct cache_head *ret; - - ret = sunrpc_cache_find(detail, key, hash); - if (ret) - return ret; - /* Didn't find anything, insert an empty entry */ - return sunrpc_cache_add_entry(detail, key, hash); -} -EXPORT_SYMBOL_GPL(sunrpc_cache_lookup); - - static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch); static void cache_fresh_locked(struct cache_head *head, time_t expiry, @@ -1369,17 +1334,7 @@ static void *__cache_seq_start(struct seq_file *m, loff_t *pos) struct cache_head, cache_list); } -void *cache_seq_start(struct seq_file *m, loff_t *pos) - __acquires(cd->hash_lock) -{ - struct cache_detail *cd = m->private; - - read_lock(&cd->hash_lock); - return __cache_seq_start(m, pos); -} -EXPORT_SYMBOL_GPL(cache_seq_start); - -void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) +static void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) { struct cache_head *ch = p; int hash = (*pos >> 32); @@ -1411,14 +1366,6 @@ void *cache_seq_next(struct seq_file *m, void *p, loff_t *pos) } EXPORT_SYMBOL_GPL(cache_seq_next); -void cache_seq_stop(struct seq_file *m, void *p) - __releases(cd->hash_lock) -{ - struct cache_detail *cd = m->private; - read_unlock(&cd->hash_lock); -} -EXPORT_SYMBOL_GPL(cache_seq_stop); - void *cache_seq_start_rcu(struct seq_file *m, loff_t *pos) __acquires(RCU) { @@ -1466,9 +1413,9 @@ static int c_show(struct seq_file *m, void *p) } static const struct seq_operations cache_content_op = { - .start = cache_seq_start, - .next = cache_seq_next, - .stop = cache_seq_stop, + .start = cache_seq_start_rcu, + .next = cache_seq_next_rcu, + .stop = cache_seq_stop_rcu, .show = c_show, }; From patchwork Mon Oct 1 14:41:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622273 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 5CC5815E8 for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EC8828DDB for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3341529437; Mon, 1 Oct 2018 14:42:34 +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 9AD2428DDB for ; Mon, 1 Oct 2018 14:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729499AbeJAVUj (ORCPT ); Mon, 1 Oct 2018 17:20:39 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:50904 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729479AbeJAVUi (ORCPT ); Mon, 1 Oct 2018 17:20:38 -0400 Received: by mail-it1-f196.google.com with SMTP id j81-v6so11614404ite.0 for ; Mon, 01 Oct 2018 07:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6wdSFYDL0H8lrZYu6tGcp+y26Tejvmm4eov5tx0DGw4=; b=gNyj0oW8NbCtYpgQP2F9HUvOqJLp+WXaxyBfFX9EnAfgfxldPFZcbc2iMY2tKjx3I3 348d4LdvMKJ0+m/zvRTLNzJ0oIyYI6qhaiwUbeH+2uV3yeNUsfEkE2YW2JZ7Od7lzseA 9xClO0ZvOjATb1EoJd06ZPmiG3qMUvCm4+Wf504Q8KXNv15YL+95eW0mAiczPF41LeWd f2La7KlUhvc12bMg6i1GbpTSsS0+rxleHXNsj5VJRKaEu4xTTVIWQTbegi3zhRqjlRi1 CvYMObtiXARPOyFJzYEr+mBSmJAwxHYVmZ6mPxyzoVu45GgfbswDt41Br0M6oj0GYVNK Poxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6wdSFYDL0H8lrZYu6tGcp+y26Tejvmm4eov5tx0DGw4=; b=q70lEFP1mvSRw65pHc1z7wT/6vHbJx+gO2YC9KKO0WcMDK4yJ/2feZ5oZLYtT/Rt/a Mtrt/ghmwBM2hoFml7eqSjGZFLm0KrzRsrtcCj6WJXOCXAh9hNlGoIa5Ol3ZJHz45jT0 /tO/SvfYl0V/Qz2LL7aIG4kHmJyTllEWHfDe5etO8qqt6IokjQ6TV5GuavI7VJIqbBWm E2uC6kzp/GFFC89EMNpCWZvWSb+nLuug8O/C/KaRXea7V6q36I/hsJUrWtkfAH82iAxp X3tYa8cWWP1zkvPCMXZrk2V6f2M0RH9Scdc3jehf295lnkhTZGfb+vhNk9H2GsXTvyWH B5pw== X-Gm-Message-State: ABuFfohn2a2ATrdtSvp/+5jXEiWBS2Htib00xePE5iB9JcSlttaV0zzM 8s6BQ4JMcuX61GkPcIYHuK9FBtg= X-Google-Smtp-Source: ACcGV60iJyrqk2NdQyN/bktXmW9MD3vwo2saJodO7Iwmqw9o3M2e4SFmUUrZ6gvLyoTevLJKX2nEHw== X-Received: by 2002:a24:2e4e:: with SMTP id i75-v6mr3781345ita.72.1538404948803; Mon, 01 Oct 2018 07:42:28 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:28 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 10/15] SUNRPC: Replace the cache_detail->hash_lock with a regular spinlock Date: Mon, 1 Oct 2018 10:41:52 -0400 Message-Id: <20181001144157.3515-11-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-10-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-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 Now that the reader functions are all RCU protected, use a regular spinlock rather than a reader/writer lock. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/cache.h | 2 +- net/sunrpc/cache.c | 46 ++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index c3d67e893430..5a3e95017fc6 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -67,7 +67,7 @@ struct cache_detail { struct module * owner; int hash_size; struct hlist_head * hash_table; - rwlock_t hash_lock; + spinlock_t hash_lock; char *name; void (*cache_put)(struct kref *); diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 593cf8607414..f96345b1180e 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -92,7 +92,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, cache_init(new, detail); detail->init(new, key); - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); /* check if entry appeared while we slept */ hlist_for_each_entry_rcu(tmp, head, cache_list) { @@ -104,7 +104,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, break; } cache_get(tmp); - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); cache_put(new, detail); return tmp; } @@ -113,7 +113,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, hlist_add_head_rcu(&new->cache_list, head); detail->entries++; cache_get(new); - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); if (freeme) cache_put(freeme, detail); @@ -167,18 +167,18 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, struct cache_head *tmp; if (!test_bit(CACHE_VALID, &old->flags)) { - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); if (!test_bit(CACHE_VALID, &old->flags)) { if (test_bit(CACHE_NEGATIVE, &new->flags)) set_bit(CACHE_NEGATIVE, &old->flags); else detail->update(old, new); cache_fresh_locked(old, new->expiry_time, detail); - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); cache_fresh_unlocked(old, detail); return old; } - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); } /* We need to insert a new entry */ tmp = detail->alloc(); @@ -189,7 +189,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, cache_init(tmp, detail); detail->init(tmp, old); - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); if (test_bit(CACHE_NEGATIVE, &new->flags)) set_bit(CACHE_NEGATIVE, &tmp->flags); else @@ -199,7 +199,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail, cache_get(tmp); cache_fresh_locked(tmp, new->expiry_time, detail); cache_fresh_locked(old, 0, detail); - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); cache_fresh_unlocked(tmp, detail); cache_fresh_unlocked(old, detail); cache_put(old, detail); @@ -239,7 +239,7 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h { int rv; - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); rv = cache_is_valid(h); if (rv == -EAGAIN) { set_bit(CACHE_NEGATIVE, &h->flags); @@ -247,7 +247,7 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h detail); rv = -ENOENT; } - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); cache_fresh_unlocked(h, detail); return rv; } @@ -357,7 +357,7 @@ static struct delayed_work cache_cleaner; void sunrpc_init_cache_detail(struct cache_detail *cd) { - rwlock_init(&cd->hash_lock); + spin_lock_init(&cd->hash_lock); INIT_LIST_HEAD(&cd->queue); spin_lock(&cache_list_lock); cd->nextcheck = 0; @@ -377,11 +377,11 @@ void sunrpc_destroy_cache_detail(struct cache_detail *cd) { cache_purge(cd); spin_lock(&cache_list_lock); - write_lock(&cd->hash_lock); + spin_lock(&cd->hash_lock); if (current_detail == cd) current_detail = NULL; list_del_init(&cd->others); - write_unlock(&cd->hash_lock); + spin_unlock(&cd->hash_lock); spin_unlock(&cache_list_lock); if (list_empty(&cache_list)) { /* module must be being unloaded so its safe to kill the worker */ @@ -438,7 +438,7 @@ static int cache_clean(void) struct hlist_head *head; struct hlist_node *tmp; - write_lock(¤t_detail->hash_lock); + spin_lock(¤t_detail->hash_lock); /* Ok, now to clean this strand */ @@ -455,7 +455,7 @@ static int cache_clean(void) break; } - write_unlock(¤t_detail->hash_lock); + spin_unlock(¤t_detail->hash_lock); d = current_detail; if (!ch) current_index ++; @@ -510,9 +510,9 @@ void cache_purge(struct cache_detail *detail) struct hlist_node *tmp = NULL; int i = 0; - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); if (!detail->entries) { - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); return; } @@ -524,13 +524,13 @@ void cache_purge(struct cache_detail *detail) detail->entries--; set_bit(CACHE_CLEANED, &ch->flags); - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); cache_fresh_unlocked(ch, detail); cache_put(ch, detail); - write_lock(&detail->hash_lock); + spin_lock(&detail->hash_lock); } } - write_unlock(&detail->hash_lock); + spin_unlock(&detail->hash_lock); } EXPORT_SYMBOL_GPL(cache_purge); @@ -1873,13 +1873,13 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs); void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h) { - write_lock(&cd->hash_lock); + spin_lock(&cd->hash_lock); if (!hlist_unhashed(&h->cache_list)){ hlist_del_init_rcu(&h->cache_list); cd->entries--; - write_unlock(&cd->hash_lock); + spin_unlock(&cd->hash_lock); cache_put(h, cd); } else - write_unlock(&cd->hash_lock); + spin_unlock(&cd->hash_lock); } EXPORT_SYMBOL_GPL(sunrpc_cache_unhash); From patchwork Mon Oct 1 14:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622283 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 566C1175A for ; Mon, 1 Oct 2018 14:42:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CD5E28DDB for ; Mon, 1 Oct 2018 14:42:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 311E92936D; Mon, 1 Oct 2018 14:42:37 +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 CCA04290FE for ; Mon, 1 Oct 2018 14:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729527AbeJAVUj (ORCPT ); Mon, 1 Oct 2018 17:20:39 -0400 Received: from mail-it1-f171.google.com ([209.85.166.171]:40293 "EHLO mail-it1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729499AbeJAVUi (ORCPT ); Mon, 1 Oct 2018 17:20:38 -0400 Received: by mail-it1-f171.google.com with SMTP id i191-v6so5961278iti.5 for ; Mon, 01 Oct 2018 07:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Pe2iiJCK/l2GevEicMF1V/5C5n71SNq2fxy/BBwNls=; b=V7phWNsl/PRH3U1Avp24SFN9BSMmRVM3Tuw+IzaUYytyXitnUpzUh2i44m/20o/3Ob v9ur848kKeMOd4QveQEEQgvez0jyZdWv3D9vK9wna6BD2iXB5oT3CNdBzZQPfrbx4j5s jQ0rIwkJFiIsWaxv/zD3Sw4LwScnnIJq7LBe04bBqMkJ5Iq3tDHqUTK1YFE4Zr31DLTr TLaz1PA/kM1MCH0nhz0zDMuNKslbmD3cLQuA3DHOxfIOaw10fpB7lgA6FQEirK/a1xhC TirQbR6g4MldhExDr9WEWviheyksnR+DTpIft1Ulrg4Wq0/xPfRLg4BQdQyon1gFf9OJ zMig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Pe2iiJCK/l2GevEicMF1V/5C5n71SNq2fxy/BBwNls=; b=bdzla0CwnaN9mWDJOH5P7gEjFvmb78VzapvufuwlTmnokgdoK8q1Xs/RhU0w5yoz4V W3Y7cNOYStMSptZIWXbMO7xr+fpin+XqUbk9NAB7FTK9S2ePscDgBC9w9eUBIwayVYeG xngSaVsZYqZsgspQYQwIlrUsMh70m0SByy4TTV1xYXgugJxirzgJfPcd1QUFCxuHVWjE sUvm9isezDS3TOolyX2J/8kgWVBLi0JkA53sS10MWgDa5+qRscxwH0/FuYOu51Qb9wGk IpacNOmbwg2WWxnvipC+7P+n5tWjjFhMAzyWZ4T8hqZoFwLR5ghxC+CqJWeD4ZNA9y/+ hknw== X-Gm-Message-State: ABuFfohf6L3nKNjcfxbNBpp4jCyibCvdD9OQ+OPsoVMheP/LwtgC0ayD FMZqZQxSzgkBWsBPxDh1nF28BK8= X-Google-Smtp-Source: ACcGV61FzJLb95sr+IAURhoDS9oTuk5TgABKX/F3Ds21J5gnVeELW0PB5Mn3Gz2YP1zs79+QSOvG3w== X-Received: by 2002:a24:d4c:: with SMTP id 73-v6mr9975392itx.117.1538404949596; Mon, 01 Oct 2018 07:42:29 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:29 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 11/15] SUNRPC: Simplify TCP receive code Date: Mon, 1 Oct 2018 10:41:53 -0400 Message-Id: <20181001144157.3515-12-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-11-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-trond.myklebust@hammerspace.com> <20181001144157.3515-11-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 Use the fact that the iov iterators already have functionality for skipping a base offset. Signed-off-by: Trond Myklebust --- net/sunrpc/svcsock.c | 53 ++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 5445145e639c..64765f08ae07 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -325,59 +325,34 @@ static int svc_one_sock_name(struct svc_sock *svsk, char *buf, int remaining) /* * Generic recvfrom routine. */ -static int svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, int nr, - int buflen) +static ssize_t svc_recvfrom(struct svc_rqst *rqstp, struct kvec *iov, + unsigned int nr, size_t buflen, unsigned int base) { struct svc_sock *svsk = container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt); - struct msghdr msg = { - .msg_flags = MSG_DONTWAIT, - }; - int len; + struct msghdr msg = { NULL }; + ssize_t len; rqstp->rq_xprt_hlen = 0; clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, iov, nr, buflen); - len = sock_recvmsg(svsk->sk_sock, &msg, msg.msg_flags); + if (base != 0) { + iov_iter_advance(&msg.msg_iter, base); + buflen -= base; + } + len = sock_recvmsg(svsk->sk_sock, &msg, MSG_DONTWAIT); /* If we read a full record, then assume there may be more * data to read (stream based sockets only!) */ if (len == buflen) set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); - dprintk("svc: socket %p recvfrom(%p, %zu) = %d\n", + dprintk("svc: socket %p recvfrom(%p, %zu) = %zd\n", svsk, iov[0].iov_base, iov[0].iov_len, len); return len; } -static int svc_partial_recvfrom(struct svc_rqst *rqstp, - struct kvec *iov, int nr, - int buflen, unsigned int base) -{ - size_t save_iovlen; - void *save_iovbase; - unsigned int i; - int ret; - - if (base == 0) - return svc_recvfrom(rqstp, iov, nr, buflen); - - for (i = 0; i < nr; i++) { - if (iov[i].iov_len > base) - break; - base -= iov[i].iov_len; - } - save_iovlen = iov[i].iov_len; - save_iovbase = iov[i].iov_base; - iov[i].iov_len -= base; - iov[i].iov_base += base; - ret = svc_recvfrom(rqstp, &iov[i], nr - i, buflen); - iov[i].iov_len = save_iovlen; - iov[i].iov_base = save_iovbase; - return ret; -} - /* * Set socket snd and rcv buffer lengths */ @@ -962,7 +937,8 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp) want = sizeof(rpc_fraghdr) - svsk->sk_tcplen; iov.iov_base = ((char *) &svsk->sk_reclen) + svsk->sk_tcplen; iov.iov_len = want; - if ((len = svc_recvfrom(rqstp, &iov, 1, want)) < 0) + len = svc_recvfrom(rqstp, &iov, 1, want, 0); + if (len < 0) goto error; svsk->sk_tcplen += len; @@ -1088,14 +1064,13 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) vec = rqstp->rq_vec; - pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0], - svsk->sk_datalen + want); + pnum = copy_pages_to_kvecs(&vec[0], &rqstp->rq_pages[0], base + want); rqstp->rq_respages = &rqstp->rq_pages[pnum]; rqstp->rq_next_page = rqstp->rq_respages + 1; /* Now receive data */ - len = svc_partial_recvfrom(rqstp, vec, pnum, want, base); + len = svc_recvfrom(rqstp, vec, pnum, base + want, base); if (len >= 0) { svsk->sk_tcplen += len; svsk->sk_datalen += len; From patchwork Mon Oct 1 14:41:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622275 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 CC738175A for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B23FC28DDB for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6CDB29437; Mon, 1 Oct 2018 14:42:34 +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 5CB3D28DDB for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729529AbeJAVUk (ORCPT ); Mon, 1 Oct 2018 17:20:40 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:54897 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729497AbeJAVUj (ORCPT ); Mon, 1 Oct 2018 17:20:39 -0400 Received: by mail-it1-f194.google.com with SMTP id l191-v6so6018553ita.4 for ; Mon, 01 Oct 2018 07:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Isqe5odlcymqI4ojIcRhZVq0alyinkP4/Aup/uBqLXM=; b=huSqVW2Vt5LJM8+Os/M0ceKhPQXo4W/MgMdXC/uH85LZbTCLl3Vv11jSG2sURZfZR5 PNKj37Pvb43/kZlgVk5xCkIJELn/HCf2iwbe/o+Gw1QidPWXZMvFvIBqvw3WOKv2qc4f RLalAoY5Ngt0r0Ks38aA11MIa/UNHyP9HHD96l5cTvlpQc7NJZbIf249FvQryQI1GsOi O2bDhki/5GjxC5QsQJJKrtrnzfavGlzHrrwpYyPr6ZYeuxCuzFBiRu8LZLmrlYpubyLP VvDG8MBdsQUmjjRAVG3h9HTNgnwQSVlYjnPBisM2WrYuL0fDB6gmrmFSdo02QFXwBO8C jLeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Isqe5odlcymqI4ojIcRhZVq0alyinkP4/Aup/uBqLXM=; b=PznQ6UT0X8vTLVI2I0jHXFPSOQII+1UTfOSdkKn+v86TQvRp3cg3ShPCul4vo/notJ NYkbClaSWH7ZhZq1w91b3CElocfHsBZ9EWwgNtKQ6o4gdhw7cxWprBZcODwjcCvZbac3 CuwhzMe7mRmjWxAAHOlH17twHgKAUhIfXyCwq6tCpEPR4eAVjVvDGeuKp9JbR5EzXtpP hd5ndC0eghCXHNl9EQFU72TDfB02rs0XSk5p33ftVDzOXsfrYfai4n4q2gp51YW6P6xi rWT3QIk3jUPflHDakXaDBXKBaG0XsbRLE+Tjaq/fsT0bBMBYQC4RdjjETxH+kWcQCMME y02A== X-Gm-Message-State: ABuFfohMwoGb8q9oQcHo6/x1B/aC7MiYyyxIDQRVxjrkr3d7AnrlAfxl BXCWiteldgF/GjHQEUB4fQ== X-Google-Smtp-Source: ACcGV60tWyaMlsjY9aWcUSRKYYd+AYKHmbBACdr6XbntQwXYfOMqGO8XspojYe6+NXVimUpXZq8L6g== X-Received: by 2002:a24:5e0a:: with SMTP id h10-v6mr10164732itb.43.1538404950272; Mon, 01 Oct 2018 07:42:30 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:29 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 12/15] knfsd: Remove dead code from nfsd_cache_lookup Date: Mon, 1 Oct 2018 10:41:54 -0400 Message-Id: <20181001144157.3515-13-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-12-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-trond.myklebust@hammerspace.com> <20181001144157.3515-11-trond.myklebust@hammerspace.com> <20181001144157.3515-12-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 The preallocated cache entry is always set to type RC_NOCACHE, and that type isn't changed until we later call nfsd_cache_update(). Signed-off-by: Trond Myklebust --- fs/nfsd/nfscache.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index dbdeb9d6af03..cef4686f87ef 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -446,14 +446,6 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) rp->c_csum = csum; lru_put_end(b, rp); - - /* release any buffer */ - if (rp->c_type == RC_REPLBUFF) { - drc_mem_usage -= rp->c_replvec.iov_len; - kfree(rp->c_replvec.iov_base); - rp->c_replvec.iov_base = NULL; - } - rp->c_type = RC_NOCACHE; out: spin_unlock(&b->cache_lock); return rtn; From patchwork Mon Oct 1 14:41:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622277 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 7C2411515 for ; Mon, 1 Oct 2018 14:42:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6033128DDB for ; Mon, 1 Oct 2018 14:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52EF72921C; Mon, 1 Oct 2018 14:42:35 +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 B46072944D for ; Mon, 1 Oct 2018 14:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729182AbeJAVUl (ORCPT ); Mon, 1 Oct 2018 17:20:41 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:39210 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729479AbeJAVUk (ORCPT ); Mon, 1 Oct 2018 17:20:40 -0400 Received: by mail-it1-f193.google.com with SMTP id w200-v6so11735680itc.4 for ; Mon, 01 Oct 2018 07:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=clOqvGBHrepHq9+TvDgQDJT+2NmZ556LWuy6ooxnDMg=; b=bsWnXT9Xn/ZffDVCOH4DfWS9Skj0jhlsq6CuS8blZTFwgAAweREGIGUpyjiryxcZUI Q9fvqwVHkGVcQbwddAQJvei8fZL6WzG7FBj5acCEBqJ3og3aJ50aQl+xX+ykYuMPihBd zz2ns8927B3+Rcd5q6ESpTVhrcIJwGWMlThT3hbBPN/LAngR0GVryZHj25Da9Wh/MlHV 1/4VgongItTiKRzEB1xZ6U2Gv2wSo/kOzksqpT+QIovi+P23xOHXo+45ced/IUdewRhA EK1bSW+jTmOVQbcUTn6+7Z4aEH9aUFI+JUaL3gZRGgksXJCJh8uixPqbZMoEsjdJQiHx cV/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=clOqvGBHrepHq9+TvDgQDJT+2NmZ556LWuy6ooxnDMg=; b=OZ4mNuPdPOc+/P9soC9vQGAJzErJGUvuKEFnFkPxMTWviGx9ETpTcHSFmKfqaFC3wd rmTdOZ4uOs1I6uvgCcQbFBF21xVOlD4xMdFNgFQ9M91CmjtwwsAh4Cf8Jh3PxfnDZBGd sw+O7o0SP1nIvk0MVGf3Gcax+aCS0BgJu0NGhL53JN55hxOmNTF4yo0xx+hDn9RVVCRH Lpns9+W5eQgdTsBWvgw3J27VsxW/CWZg6WXxzmBNNrliJOmCxNKy0R/P8wbFpJ9KAC0u HWTFcn9A72Cy4R7x/Nj4lcC0Z+k+TuBsGbryD6kkkLiLKjG9n+JbXrXKjTaRCP1CJjsz 4y+Q== X-Gm-Message-State: ABuFfohGeS95N+nfJPqdFj//hpVq9Z+omtFyOha8cgq/um4NE5s2TXGC wDcc73lIyzXdFUeEXhGDZg== X-Google-Smtp-Source: ACcGV62/XPtinOdTtO5qlslL7SqLx6qXckwZL2V/E3u1l75tR07ZIbl7hO8y7vwC/4mDuHNd/PJKlg== X-Received: by 2002:a02:1b4f:: with SMTP id l76-v6mr8422953jad.57.1538404951018; Mon, 01 Oct 2018 07:42:31 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:30 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 13/15] knfsd: Simplify NFS duplicate replay cache Date: Mon, 1 Oct 2018 10:41:55 -0400 Message-Id: <20181001144157.3515-14-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-13-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-trond.myklebust@hammerspace.com> <20181001144157.3515-11-trond.myklebust@hammerspace.com> <20181001144157.3515-12-trond.myklebust@hammerspace.com> <20181001144157.3515-13-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 Simplify the duplicate replay cache by initialising the preallocated cache entry, so that we can use it as a key for the cache lookup. Note that the 99.999% case we want to optimise for is still the one where the lookup fails, and we have to add this entry to the cache, so preinitialising should not cause a performance penalty. Signed-off-by: Trond Myklebust --- fs/nfsd/cache.h | 6 +-- fs/nfsd/nfscache.c | 94 ++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 53 deletions(-) diff --git a/fs/nfsd/cache.h b/fs/nfsd/cache.h index b7559c6f2b97..bd77d5f6fe53 100644 --- a/fs/nfsd/cache.h +++ b/fs/nfsd/cache.h @@ -24,13 +24,13 @@ struct svc_cacherep { unsigned char c_state, /* unused, inprog, done */ c_type, /* status, buffer */ c_secure : 1; /* req came from port < 1024 */ - struct sockaddr_in6 c_addr; __be32 c_xid; - u32 c_prot; + __wsum c_csum; u32 c_proc; + u32 c_prot; u32 c_vers; unsigned int c_len; - __wsum c_csum; + struct sockaddr_in6 c_addr; unsigned long c_timestamp; union { struct kvec u_vec; diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index cef4686f87ef..527ce4c65765 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -121,7 +121,7 @@ nfsd_cache_hash(__be32 xid) } static struct svc_cacherep * -nfsd_reply_cache_alloc(void) +nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum) { struct svc_cacherep *rp; @@ -130,6 +130,16 @@ nfsd_reply_cache_alloc(void) rp->c_state = RC_UNUSED; rp->c_type = RC_NOCACHE; INIT_LIST_HEAD(&rp->c_lru); + + rp->c_xid = rqstp->rq_xid; + rp->c_proc = rqstp->rq_proc; + memset(&rp->c_addr, 0, sizeof(rp->c_addr)); + rpc_copy_addr((struct sockaddr *)&rp->c_addr, svc_addr(rqstp)); + rpc_set_port((struct sockaddr *)&rp->c_addr, rpc_get_port(svc_addr(rqstp))); + rp->c_prot = rqstp->rq_prot; + rp->c_vers = rqstp->rq_vers; + rp->c_len = rqstp->rq_arg.len; + rp->c_csum = csum; } return rp; } @@ -141,9 +151,11 @@ nfsd_reply_cache_free_locked(struct svc_cacherep *rp) drc_mem_usage -= rp->c_replvec.iov_len; kfree(rp->c_replvec.iov_base); } - list_del(&rp->c_lru); - atomic_dec(&num_drc_entries); - drc_mem_usage -= sizeof(*rp); + if (rp->c_state != RC_UNUSED) { + list_del(&rp->c_lru); + atomic_dec(&num_drc_entries); + drc_mem_usage -= sizeof(*rp); + } kmem_cache_free(drc_slab, rp); } @@ -319,24 +331,23 @@ nfsd_cache_csum(struct svc_rqst *rqstp) } static bool -nfsd_cache_match(struct svc_rqst *rqstp, __wsum csum, struct svc_cacherep *rp) +nfsd_cache_match(const struct svc_cacherep *key, const struct svc_cacherep *rp) { /* Check RPC XID first */ - if (rqstp->rq_xid != rp->c_xid) + if (key->c_xid != rp->c_xid) return false; /* compare checksum of NFS data */ - if (csum != rp->c_csum) { + if (key->c_csum != rp->c_csum) { ++payload_misses; return false; } /* Other discriminators */ - if (rqstp->rq_proc != rp->c_proc || - rqstp->rq_prot != rp->c_prot || - rqstp->rq_vers != rp->c_vers || - rqstp->rq_arg.len != rp->c_len || - !rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) || - rpc_get_port(svc_addr(rqstp)) != rpc_get_port((struct sockaddr *)&rp->c_addr)) + if (key->c_proc != rp->c_proc || + key->c_prot != rp->c_prot || + key->c_vers != rp->c_vers || + key->c_len != rp->c_len || + memcmp(&key->c_addr, &rp->c_addr, sizeof(key->c_addr)) != 0) return false; return true; @@ -345,19 +356,18 @@ nfsd_cache_match(struct svc_rqst *rqstp, __wsum csum, struct svc_cacherep *rp) /* * Search the request hash for an entry that matches the given rqstp. * Must be called with cache_lock held. Returns the found entry or - * NULL on failure. + * inserts an empty key on failure. */ static struct svc_cacherep * -nfsd_cache_search(struct nfsd_drc_bucket *b, struct svc_rqst *rqstp, - __wsum csum) +nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key) { - struct svc_cacherep *rp, *ret = NULL; + struct svc_cacherep *rp, *ret = key; struct list_head *rh = &b->lru_head; unsigned int entries = 0; list_for_each_entry(rp, rh, c_lru) { ++entries; - if (nfsd_cache_match(rqstp, csum, rp)) { + if (nfsd_cache_match(key, rp)) { ret = rp; break; } @@ -374,6 +384,7 @@ nfsd_cache_search(struct nfsd_drc_bucket *b, struct svc_rqst *rqstp, atomic_read(&num_drc_entries)); } + lru_put_end(b, ret); return ret; } @@ -389,9 +400,6 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) { struct svc_cacherep *rp, *found; __be32 xid = rqstp->rq_xid; - u32 proto = rqstp->rq_prot, - vers = rqstp->rq_vers, - proc = rqstp->rq_proc; __wsum csum; u32 hash = nfsd_cache_hash(xid); struct nfsd_drc_bucket *b = &drc_hashtbl[hash]; @@ -410,52 +418,38 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) * Since the common case is a cache miss followed by an insert, * preallocate an entry. */ - rp = nfsd_reply_cache_alloc(); - spin_lock(&b->cache_lock); - if (likely(rp)) { - atomic_inc(&num_drc_entries); - drc_mem_usage += sizeof(*rp); + rp = nfsd_reply_cache_alloc(rqstp, csum); + if (!rp) { + dprintk("nfsd: unable to allocate DRC entry!\n"); + return rtn; } - /* go ahead and prune the cache */ - prune_bucket(b); - - found = nfsd_cache_search(b, rqstp, csum); - if (found) { - if (likely(rp)) - nfsd_reply_cache_free_locked(rp); + spin_lock(&b->cache_lock); + found = nfsd_cache_insert(b, rp); + if (found != rp) { + nfsd_reply_cache_free_locked(rp); rp = found; goto found_entry; } - if (!rp) { - dprintk("nfsd: unable to allocate DRC entry!\n"); - goto out; - } - nfsdstats.rcmisses++; rqstp->rq_cacherep = rp; rp->c_state = RC_INPROG; - rp->c_xid = xid; - rp->c_proc = proc; - rpc_copy_addr((struct sockaddr *)&rp->c_addr, svc_addr(rqstp)); - rpc_set_port((struct sockaddr *)&rp->c_addr, rpc_get_port(svc_addr(rqstp))); - rp->c_prot = proto; - rp->c_vers = vers; - rp->c_len = rqstp->rq_arg.len; - rp->c_csum = csum; - lru_put_end(b, rp); + atomic_inc(&num_drc_entries); + drc_mem_usage += sizeof(*rp); + + /* go ahead and prune the cache */ + prune_bucket(b); out: spin_unlock(&b->cache_lock); return rtn; found_entry: - nfsdstats.rchits++; /* We found a matching entry which is either in progress or done. */ - lru_put_end(b, rp); - + nfsdstats.rchits++; rtn = RC_DROPIT; + /* Request being processed */ if (rp->c_state == RC_INPROG) goto out; From patchwork Mon Oct 1 14:41:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622279 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 19A82175A for ; Mon, 1 Oct 2018 14:42:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000E528DDB for ; Mon, 1 Oct 2018 14:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E87592936D; Mon, 1 Oct 2018 14:42:35 +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 6E50529437 for ; Mon, 1 Oct 2018 14:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729526AbeJAVUm (ORCPT ); Mon, 1 Oct 2018 17:20:42 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:38772 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729528AbeJAVUl (ORCPT ); Mon, 1 Oct 2018 17:20:41 -0400 Received: by mail-it1-f194.google.com with SMTP id i76-v6so6171739ita.3 for ; Mon, 01 Oct 2018 07:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g0U6HOlluri0FfoG42ZjizuNZ9VtwfEZAjs34rbA6U4=; b=hDRYtqdOBLOHL7YeEjDY2nZ7QlO3GguVzWMsNfHkWzacfugXdI/T8VHyxwVD+kBxqy z4Ze0Jy5UWU29Nbrp/nMKJgorC2qjj2Ie71SYS4huGDWwx9BqfzAsAOh871OzQq/5ph1 y1XrOtcF49DL9oClfnMQMaPeQfkxyUdXxPJO8n/0Z0sZIuY+M1tcvh2U+JSDhhIABpV1 aD7mN0Pq5unN0ln/+eqn2ieTb+HNE2gWtfOra2EvoUB9yH9CXrWel1U/h6n6Ztsaeg5L MBizG1S0xr9sQW+Gl98xTsGmIwrFNoLfrEOoBEzEabW1EdEj7PfTx5frjHiB8ru15C+l IWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g0U6HOlluri0FfoG42ZjizuNZ9VtwfEZAjs34rbA6U4=; b=j61DOQJdHGP6oa6MDByKPx+5i8RspR8G1WmUa20Fdwx8tbHB0hZn3pmeobauxoOLaW syjOo6uCw1iOGVLdCweXELjWSB/QiR5f0PgGg5P3OYLh3q2TaAPwt0jPyZWGdoKgpO4D NzIOwiTTqVUaVToeGaUqM9R+wS+jn8Vpk6kllmo2sAJWsBq6CW34XElh71POk4Y5+ODC xR3ACPQ73XHjpt+UAsrzlbpwfniKO1/rhkJnj61dDJKvJPYF1Is2oRP92TFTVCqqxYoz /McyZOniRaS0LcWW9tEzO9FPgUZ0z+ilzFqJR5enfuk7QB8YP9avuoQe1fCx9QQyHxSP 8mVg== X-Gm-Message-State: ABuFfoiP2yqrQG92KPTwtPzGKa141U04f3IB0zx5MBrOIUGnlsPHJaqw A7zKov2L0lrIf6r5G/LWzQ== X-Google-Smtp-Source: ACcGV63gE/ZL3s6obbAnAf9VlY1+Yw85SqIiYjlNWTcdAneCTHlbW5rNW+zaX/XssWQwi0ySYQZz+A== X-Received: by 2002:a02:602a:: with SMTP id i42-v6mr8693781jac.95.1538404951693; Mon, 01 Oct 2018 07:42:31 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:31 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 14/15] knfsd: Further simplify the cache lookup Date: Mon, 1 Oct 2018 10:41:56 -0400 Message-Id: <20181001144157.3515-15-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-14-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-trond.myklebust@hammerspace.com> <20181001144157.3515-11-trond.myklebust@hammerspace.com> <20181001144157.3515-12-trond.myklebust@hammerspace.com> <20181001144157.3515-13-trond.myklebust@hammerspace.com> <20181001144157.3515-14-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 Order the structure so that the key can be compared using memcmp(). Signed-off-by: Trond Myklebust --- fs/nfsd/cache.h | 18 ++++++++++-------- fs/nfsd/nfscache.c | 45 ++++++++++++++++----------------------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/fs/nfsd/cache.h b/fs/nfsd/cache.h index bd77d5f6fe53..cbcdc15753b7 100644 --- a/fs/nfsd/cache.h +++ b/fs/nfsd/cache.h @@ -19,18 +19,20 @@ * is much larger than a sockaddr_in6. */ struct svc_cacherep { - struct list_head c_lru; + struct { + __be32 k_xid; + __wsum k_csum; + u32 k_proc; + u32 k_prot; + u32 k_vers; + unsigned int k_len; + struct sockaddr_in6 k_addr; + } c_key; + struct list_head c_lru; unsigned char c_state, /* unused, inprog, done */ c_type, /* status, buffer */ c_secure : 1; /* req came from port < 1024 */ - __be32 c_xid; - __wsum c_csum; - u32 c_proc; - u32 c_prot; - u32 c_vers; - unsigned int c_len; - struct sockaddr_in6 c_addr; unsigned long c_timestamp; union { struct kvec u_vec; diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 527ce4c65765..230cc83921ad 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -131,15 +131,15 @@ nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum) rp->c_type = RC_NOCACHE; INIT_LIST_HEAD(&rp->c_lru); - rp->c_xid = rqstp->rq_xid; - rp->c_proc = rqstp->rq_proc; - memset(&rp->c_addr, 0, sizeof(rp->c_addr)); - rpc_copy_addr((struct sockaddr *)&rp->c_addr, svc_addr(rqstp)); - rpc_set_port((struct sockaddr *)&rp->c_addr, rpc_get_port(svc_addr(rqstp))); - rp->c_prot = rqstp->rq_prot; - rp->c_vers = rqstp->rq_vers; - rp->c_len = rqstp->rq_arg.len; - rp->c_csum = csum; + memset(&rp->c_key, 0, sizeof(rp->c_key)); + rp->c_key.k_xid = rqstp->rq_xid; + rp->c_key.k_proc = rqstp->rq_proc; + rpc_copy_addr((struct sockaddr *)&rp->c_key.k_addr, svc_addr(rqstp)); + rpc_set_port((struct sockaddr *)&rp->c_key.k_addr, rpc_get_port(svc_addr(rqstp))); + rp->c_key.k_prot = rqstp->rq_prot; + rp->c_key.k_vers = rqstp->rq_vers; + rp->c_key.k_len = rqstp->rq_arg.len; + rp->c_key.k_csum = csum; } return rp; } @@ -330,27 +330,14 @@ nfsd_cache_csum(struct svc_rqst *rqstp) return csum; } -static bool -nfsd_cache_match(const struct svc_cacherep *key, const struct svc_cacherep *rp) +static int +nfsd_cache_key_cmp(const struct svc_cacherep *key, const struct svc_cacherep *rp) { - /* Check RPC XID first */ - if (key->c_xid != rp->c_xid) - return false; - /* compare checksum of NFS data */ - if (key->c_csum != rp->c_csum) { + if (key->c_key.k_xid == rp->c_key.k_xid && + key->c_key.k_csum != rp->c_key.k_csum) ++payload_misses; - return false; - } - - /* Other discriminators */ - if (key->c_proc != rp->c_proc || - key->c_prot != rp->c_prot || - key->c_vers != rp->c_vers || - key->c_len != rp->c_len || - memcmp(&key->c_addr, &rp->c_addr, sizeof(key->c_addr)) != 0) - return false; - return true; + return memcmp(&key->c_key, &rp->c_key, sizeof(key->c_key)); } /* @@ -367,7 +354,7 @@ nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key) list_for_each_entry(rp, rh, c_lru) { ++entries; - if (nfsd_cache_match(key, rp)) { + if (nfsd_cache_key_cmp(key, rp) == 0) { ret = rp; break; } @@ -510,7 +497,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp) if (!rp) return; - hash = nfsd_cache_hash(rp->c_xid); + hash = nfsd_cache_hash(rp->c_key.k_xid); b = &drc_hashtbl[hash]; len = resv->iov_len - ((char*)statp - (char*)resv->iov_base); From patchwork Mon Oct 1 14:41:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10622281 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 1489D1515 for ; Mon, 1 Oct 2018 14:42:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDD1428DDB for ; Mon, 1 Oct 2018 14:42:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E215129437; Mon, 1 Oct 2018 14:42:36 +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 770A728DDB for ; Mon, 1 Oct 2018 14:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729479AbeJAVUn (ORCPT ); Mon, 1 Oct 2018 17:20:43 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:35002 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729497AbeJAVUm (ORCPT ); Mon, 1 Oct 2018 17:20:42 -0400 Received: by mail-it1-f195.google.com with SMTP id p64-v6so4681425itp.0 for ; Mon, 01 Oct 2018 07:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+pyLrGJku1wer7NJUSW3WVNt5OCy5E4TU2d7kRDDX6A=; b=E1DjH37FbhmQRLCREduG73cMNlbTRP7wxUW3EY+GUBBD4wP3jKbywQRCl6wvuOBA0I w3uVo8EyAPT1KCeVJX75z+FykIliDSr/2NOXDN5+4kpLZb/8p8Bq8nl/2Vz2RiMbED6c jTHEJJQ1SGrCf3HAykROO7n2qWvB7JtcNnVw6oWYJz8BT5LZShHh/JJB24MR2VV54cmW SnOUvUheYm021RuBEwRQFdgojqX+YwsN8zQSgDcmUZQ2GSMcK9CYHbU6w9XjnfQpx5uf Evz3JMz3aWGDqx3sXD7E0v3OhUJwTtVaILRkXBWMxwvh38S4Om8yUclTqVgozhaJsLSx Enbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+pyLrGJku1wer7NJUSW3WVNt5OCy5E4TU2d7kRDDX6A=; b=RkebvDoiouFV3AavtHkyKfP2AQH1oV2fBiiRcXZLTJZPs1cMHIM7ynpNcXqy8zgvhN dkBXPZRzzGIMoe0aReqbOGhyHocgiNGd2rzLdddoqwwcn/RF8qL64bg//4v72LPyLsit l7XvefzN0PWSoB9aOhMi6Cd4ZfnJDXxdtyxigFqTkiQmZcX85NPtZmg4AdDdkZWLzcne +QS7d2Qcd4+HsYaf/0FJeu2R2Os8XDuFsAa+QyXwg9XPURnuDzQ5DPYt+WvoWdGcICfH MfvFzltovgUCFBQH5ysGhxUnCArSMWMfHIVrJPVbS/qtS9Cscaial5URbpivLlH4E/MQ OzDQ== X-Gm-Message-State: ABuFfoi9i0s/T3glgUYB+IkubgmGmBtGFv9WbVvHugZ7e8qNGQKodAOz F5lFfuSCQpYLc1RTc2QCpw== X-Google-Smtp-Source: ACcGV612az8IY0J9bNm+gS/f6hKlNUWmzJ44hSshAKwWux/C2vGqGrdmcTN879z6Rz6OUpppRBgK4g== X-Received: by 2002:a24:dd49:: with SMTP id t70-v6mr10203849itf.109.1538404952432; Mon, 01 Oct 2018 07:42:32 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-40-195-73.hsd1.mi.comcast.net. [68.40.195.73]) by smtp.gmail.com with ESMTPSA id j75-v6sm2055597itj.33.2018.10.01.07.42.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Oct 2018 07:42:31 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 15/15] knfsd: Improve lookup performance in the duplicate reply cache using an rbtree Date: Mon, 1 Oct 2018 10:41:57 -0400 Message-Id: <20181001144157.3515-16-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181001144157.3515-15-trond.myklebust@hammerspace.com> References: <20181001144157.3515-1-trond.myklebust@hammerspace.com> <20181001144157.3515-2-trond.myklebust@hammerspace.com> <20181001144157.3515-3-trond.myklebust@hammerspace.com> <20181001144157.3515-4-trond.myklebust@hammerspace.com> <20181001144157.3515-5-trond.myklebust@hammerspace.com> <20181001144157.3515-6-trond.myklebust@hammerspace.com> <20181001144157.3515-7-trond.myklebust@hammerspace.com> <20181001144157.3515-8-trond.myklebust@hammerspace.com> <20181001144157.3515-9-trond.myklebust@hammerspace.com> <20181001144157.3515-10-trond.myklebust@hammerspace.com> <20181001144157.3515-11-trond.myklebust@hammerspace.com> <20181001144157.3515-12-trond.myklebust@hammerspace.com> <20181001144157.3515-13-trond.myklebust@hammerspace.com> <20181001144157.3515-14-trond.myklebust@hammerspace.com> <20181001144157.3515-15-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 Use an rbtree to ensure the lookup/insert of an entry in a DRC bucket is O(log(N)). Signed-off-by: Trond Myklebust --- fs/nfsd/cache.h | 1 + fs/nfsd/nfscache.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/cache.h b/fs/nfsd/cache.h index cbcdc15753b7..ef1c8aa89ca4 100644 --- a/fs/nfsd/cache.h +++ b/fs/nfsd/cache.h @@ -29,6 +29,7 @@ struct svc_cacherep { struct sockaddr_in6 k_addr; } c_key; + struct rb_node c_node; struct list_head c_lru; unsigned char c_state, /* unused, inprog, done */ c_type, /* status, buffer */ diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 230cc83921ad..e2fe0e9ce0df 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -30,6 +30,7 @@ #define TARGET_BUCKET_SIZE 64 struct nfsd_drc_bucket { + struct rb_root rb_head; struct list_head lru_head; spinlock_t cache_lock; }; @@ -129,6 +130,7 @@ nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum) if (rp) { rp->c_state = RC_UNUSED; rp->c_type = RC_NOCACHE; + RB_CLEAR_NODE(&rp->c_node); INIT_LIST_HEAD(&rp->c_lru); memset(&rp->c_key, 0, sizeof(rp->c_key)); @@ -145,13 +147,14 @@ nfsd_reply_cache_alloc(struct svc_rqst *rqstp, __wsum csum) } static void -nfsd_reply_cache_free_locked(struct svc_cacherep *rp) +nfsd_reply_cache_free_locked(struct nfsd_drc_bucket *b, struct svc_cacherep *rp) { if (rp->c_type == RC_REPLBUFF && rp->c_replvec.iov_base) { drc_mem_usage -= rp->c_replvec.iov_len; kfree(rp->c_replvec.iov_base); } if (rp->c_state != RC_UNUSED) { + rb_erase(&rp->c_node, &b->rb_head); list_del(&rp->c_lru); atomic_dec(&num_drc_entries); drc_mem_usage -= sizeof(*rp); @@ -163,7 +166,7 @@ static void nfsd_reply_cache_free(struct nfsd_drc_bucket *b, struct svc_cacherep *rp) { spin_lock(&b->cache_lock); - nfsd_reply_cache_free_locked(rp); + nfsd_reply_cache_free_locked(b, rp); spin_unlock(&b->cache_lock); } @@ -219,7 +222,7 @@ void nfsd_reply_cache_shutdown(void) struct list_head *head = &drc_hashtbl[i].lru_head; while (!list_empty(head)) { rp = list_first_entry(head, struct svc_cacherep, c_lru); - nfsd_reply_cache_free_locked(rp); + nfsd_reply_cache_free_locked(&drc_hashtbl[i], rp); } } @@ -258,7 +261,7 @@ prune_bucket(struct nfsd_drc_bucket *b) if (atomic_read(&num_drc_entries) <= max_drc_entries && time_before(jiffies, rp->c_timestamp + RC_EXPIRE)) break; - nfsd_reply_cache_free_locked(rp); + nfsd_reply_cache_free_locked(b, rp); freed++; } return freed; @@ -349,17 +352,29 @@ static struct svc_cacherep * nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key) { struct svc_cacherep *rp, *ret = key; - struct list_head *rh = &b->lru_head; + struct rb_node **p = &b->rb_head.rb_node, + *parent = NULL; unsigned int entries = 0; + int cmp; - list_for_each_entry(rp, rh, c_lru) { + while (*p != NULL) { ++entries; - if (nfsd_cache_key_cmp(key, rp) == 0) { + parent = *p; + rp = rb_entry(parent, struct svc_cacherep, c_node); + + cmp = nfsd_cache_key_cmp(key, rp); + if (cmp < 0) + p = &parent->rb_left; + else if (cmp > 0) + p = &parent->rb_right; + else { ret = rp; - break; + goto out; } } - + rb_link_node(&key->c_node, parent, p); + rb_insert_color(&key->c_node, &b->rb_head); +out: /* tally hash chain length stats */ if (entries > longest_chain) { longest_chain = entries; @@ -414,7 +429,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) spin_lock(&b->cache_lock); found = nfsd_cache_insert(b, rp); if (found != rp) { - nfsd_reply_cache_free_locked(rp); + nfsd_reply_cache_free_locked(NULL, rp); rp = found; goto found_entry; } @@ -462,7 +477,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp) break; default: printk(KERN_WARNING "nfsd: bad repcache type %d\n", rp->c_type); - nfsd_reply_cache_free_locked(rp); + nfsd_reply_cache_free_locked(b, rp); } goto out;