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);