Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3600514ybl; Mon, 27 Jan 2020 07:01:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwEKc2enlWCH0rCYzHCNJH7AECTUTat6dfz2F+lSu/yettVyukxkPmpV2egjaPy5rRUbX6q X-Received: by 2002:a9d:12cf:: with SMTP id g73mr12187819otg.329.1580137268157; Mon, 27 Jan 2020 07:01:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580137268; cv=none; d=google.com; s=arc-20160816; b=xscAnPmlWyv/S7s/u9ZKMd3pPjl4/rlKWQEUh4mup/u//Z6OUJu8Ayfqist0ERlLvV GXDrRMZPhQ/P6L9C735Rd37FRsEWAFpRmVP9k2/e8sPXhNckV8CD7tm2ewBQ1nsi2VAj J+8WVcvS/uZHNOiriE/b9OIiQ5Em8UoNx/TsFVm4QmGnk2U1z4DBDOe8CJyuastCzN0H x1jAjoyXqRIxbnT1zRzh3u/7t+fAzKK1fu1w7S1Gx5hNQD5+qU4JL8CzqSj2DLP4a15z tlrJ0Ihvl1TBTo5hPBZhz10gG/hqGLI6qUk7INrOR1vtqdISmaGD3jCq964LUAc9+a3h u1Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tCP7XDbwqynjsMWfGGEVx8n6y4Sbr/5RTCXLxam2NFw=; b=atk6J096mxROhKAc5h1Zqs7cEXCSfxOKug+XAcmznwUABz6qR8s414c4lFonHDrn9o 7AwxSeu0pEIzA5kWHT+G4vPZQ4QtLsDQpGNnHuCXrUFTW2bh8aM1a/RWS//HaNlfSNrA Ss69QKNBUkbBJGH1QYHnNfZFz7rsVuEyoqvQfgH64qsvNiHEtE4FymC+iZyiHXdyOEgb n4olALw/9PoBG4t4BMDsVJcH5FOnSllFGTjjzmBsL9PKt7dDNORSD1bByT4N4fan/+3U W3FM7AaSW1eUNvt7i8yzDeZ/7GAXy0M6/Um1sifME24BZwX7fiSdnOFxC53kIFcbJ8CT 8piA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ORV6J7YZ; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si3565855oia.262.2020.01.27.07.00.56; Mon, 27 Jan 2020 07:01:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ORV6J7YZ; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729268AbgA0PAe (ORCPT + 99 others); Mon, 27 Jan 2020 10:00:34 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:40547 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729331AbgA0PAd (ORCPT ); Mon, 27 Jan 2020 10:00:33 -0500 Received: by mail-yw1-f67.google.com with SMTP id i126so4828325ywe.7 for ; Mon, 27 Jan 2020 07:00:33 -0800 (PST) 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=tCP7XDbwqynjsMWfGGEVx8n6y4Sbr/5RTCXLxam2NFw=; b=ORV6J7YZs4kFr2STL8OHs7qRchkdN4A/BOSJcFnFAcVZHTUVcyDk/TXm2o3tzDf8Tr NNky3kUXm+6EUecSl3PVQHj1BVBUnC8Y3MPyQ5/vCkSsRjJf9oVPQ9eYZH0JuaAizOoh 2l+fpGcebznabty90nuOyVtYY0XdVETtqPtmWPQp5vEY38xQgaRfl0ZPowFFpofER3DG 9GjbHbn+LbioVnRPI8eoQdEUnSAC7xnEWL8oB9ay7Vnh1MNmGiezuPlfWhIzTBjMi5A6 tcYnvevPQoFwqN/B2iKcMC0I8OFp9Y0xxsGAXO916UTlNaq1Llm2JxVCNIPuh09mtZ3U XnkQ== 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=tCP7XDbwqynjsMWfGGEVx8n6y4Sbr/5RTCXLxam2NFw=; b=XdjVUclagiPs5XOnE/UFOW8hSxj+h6mI54nREfJmGIDH/cQy3AYZAa0G6sPadUjLaA TZfXLgiLZLcUx4hrQY6UKNuLbOyrOzT2uTTikSDRWDFw4/TofCsIz++IxQa8xCffNOLr ZbKOF1tM6s9RqaxaRjLmGlOLciEZXOgY5+ofZR5n3GDiWLLTgwfQRr3VKe2YOmqofYO6 sEYHVjWDv/HUcLMYZX3fOAXnriDBqwAAz1LsB3H68IZWJAAZofiDVy0TSyy1P9JU0zSp eWb0TKclyUvDZF7QIauTjylq49VU970T8ItQbqxG+bY2SB1wG6Lfh5kQQ/FX1uvsXhuY 2WlA== X-Gm-Message-State: APjAAAURBksCqdRngFLUpUaA1Z1OT0VSgjDzoB35+lJtlZQwc8wdCIUq 0CPD+V3eJn6NHZDrRUhqInrBBnaq6w== X-Received: by 2002:a81:5dc1:: with SMTP id r184mr13157421ywb.433.1580137232840; Mon, 27 Jan 2020 07:00:32 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id d186sm6809096ywe.0.2020.01.27.07.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 07:00:32 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/5] NFSv4: Add accounting for the number of active delegations held Date: Mon, 27 Jan 2020 09:58:18 -0500 Message-Id: <20200127145819.350982-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200127145819.350982-4-trond.myklebust@hammerspace.com> References: <20200127145819.350982-1-trond.myklebust@hammerspace.com> <20200127145819.350982-2-trond.myklebust@hammerspace.com> <20200127145819.350982-3-trond.myklebust@hammerspace.com> <20200127145819.350982-4-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In order to better manage our delegation caching, add a counter to track the number of active delegations. Signed-off-by: Trond Myklebust --- fs/nfs/delegation.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 90e50f32f3e0..a777b3d0e720 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -25,13 +25,29 @@ #include "internal.h" #include "nfs4trace.h" -static void nfs_free_delegation(struct nfs_delegation *delegation) +static atomic_long_t nfs_active_delegations; + +static void __nfs_free_delegation(struct nfs_delegation *delegation) { put_cred(delegation->cred); delegation->cred = NULL; kfree_rcu(delegation, rcu); } +static void nfs_mark_delegation_revoked(struct nfs_delegation *delegation) +{ + if (!test_and_set_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { + delegation->stateid.type = NFS4_INVALID_STATEID_TYPE; + atomic_long_dec(&nfs_active_delegations); + } +} + +static void nfs_free_delegation(struct nfs_delegation *delegation) +{ + nfs_mark_delegation_revoked(delegation); + __nfs_free_delegation(delegation); +} + /** * nfs_mark_delegation_referenced - set delegation's REFERENCED flag * @delegation: delegation to process @@ -343,7 +359,8 @@ nfs_update_inplace_delegation(struct nfs_delegation *delegation, delegation->stateid.seqid = update->stateid.seqid; smp_wmb(); delegation->type = update->type; - clear_bit(NFS_DELEGATION_REVOKED, &delegation->flags); + if (test_and_clear_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) + atomic_long_inc(&nfs_active_delegations); } } @@ -423,6 +440,8 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, rcu_assign_pointer(nfsi->delegation, delegation); delegation = NULL; + atomic_long_inc(&nfs_active_delegations); + trace_nfs4_set_delegation(inode, type); spin_lock(&inode->i_lock); @@ -432,7 +451,7 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, out: spin_unlock(&clp->cl_lock); if (delegation != NULL) - nfs_free_delegation(delegation); + __nfs_free_delegation(delegation); if (freeme != NULL) { nfs_do_return_delegation(inode, freeme, 0); nfs_free_delegation(freeme); @@ -796,13 +815,6 @@ static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *cl rcu_read_unlock(); } -static void nfs_mark_delegation_revoked(struct nfs_server *server, - struct nfs_delegation *delegation) -{ - set_bit(NFS_DELEGATION_REVOKED, &delegation->flags); - delegation->stateid.type = NFS4_INVALID_STATEID_TYPE; -} - static void nfs_revoke_delegation(struct inode *inode, const nfs4_stateid *stateid) { @@ -830,7 +842,7 @@ static void nfs_revoke_delegation(struct inode *inode, } spin_unlock(&delegation->lock); } - nfs_mark_delegation_revoked(NFS_SERVER(inode), delegation); + nfs_mark_delegation_revoked(delegation); ret = true; out: rcu_read_unlock(); @@ -869,7 +881,7 @@ void nfs_delegation_mark_returned(struct inode *inode, delegation->stateid.seqid = stateid->seqid; } - nfs_mark_delegation_revoked(NFS_SERVER(inode), delegation); + nfs_mark_delegation_revoked(delegation); out_clear_returning: clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags); -- 2.24.1