Linux NFS development
 help / color / mirror / Atom feed
From: Anna Schumaker <anna.schumaker@oracle.com>
To: Christoph Hellwig <hch@lst.de>,
	Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH 23/24] NFS: return delegations from the end of a LRU when over the watermark
Date: Thu, 18 Dec 2025 17:02:26 -0500	[thread overview]
Message-ID: <13891f50-73a1-40ee-aaa2-373dba3886e6@oracle.com> (raw)
In-Reply-To: <20251218055633.1532159-24-hch@lst.de>

Hi Christoph,

On 12/18/25 12:56 AM, Christoph Hellwig wrote:
> Directly returning delegations on close when over the watermark is
> rather suboptimal as these delegations are much more likely to be reused
> than those that have been unused for a long time.  Switch to returning
> unused delegations from a new LRU list when we are above the threshold and
> there are reclaimable delegations instead.
> 
> Pass over referenced delegations during the first pass to give delegations
> that aren't in active used by frequently used for stat() or similar another
> chance to not be instantly reclaimed.  This scheme works the same as the
> referenced flags in the VFS inode and dentry caches.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I'm seeing fstests hang on generic/013 after applying this patch and running
with NFS v4.0. Other versions of NFS still seem to work just fine. Have you
seen anything like this in your testing?

Thanks,
Anna

> ---
>  fs/nfs/client.c           |  1 +
>  fs/nfs/delegation.c       | 61 +++++++++++++++++++++++++++++++++++++--
>  include/linux/nfs_fs_sb.h |  1 +
>  3 files changed, 60 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/nfs/client.c b/fs/nfs/client.c
> index 65b3de91b441..62aece00f810 100644
> --- a/fs/nfs/client.c
> +++ b/fs/nfs/client.c
> @@ -1062,6 +1062,7 @@ struct nfs_server *nfs_alloc_server(void)
>  	INIT_LIST_HEAD(&server->delegations);
>  	spin_lock_init(&server->delegations_lock);
>  	INIT_LIST_HEAD(&server->delegations_return);
> +	INIT_LIST_HEAD(&server->delegations_lru);
>  	INIT_LIST_HEAD(&server->layouts);
>  	INIT_LIST_HEAD(&server->state_owners_lru);
>  	INIT_LIST_HEAD(&server->ss_copies);
> diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
> index 25f4bb598fd8..712cdb3381ad 100644
> --- a/fs/nfs/delegation.c
> +++ b/fs/nfs/delegation.c
> @@ -657,6 +657,60 @@ static int nfs_server_return_marked_delegations(struct nfs_server *server,
>  	return err;
>  }
>  
> +static inline bool nfs_delegations_over_limit(struct nfs_server *server)
> +{
> +	return !list_empty_careful(&server->delegations_lru) &&
> +		atomic_long_read(&server->nr_active_delegations) >
> +		nfs_delegation_watermark;
> +}
> +
> +static void nfs_delegations_return_from_lru(struct nfs_server *server)
> +{
> +	struct nfs_delegation *d, *n;
> +	unsigned int pass = 0;
> +	bool moved = false;
> +
> +retry:
> +	spin_lock(&server->delegations_lock);
> +	list_for_each_entry_safe(d, n, &server->delegations_lru, entry) {
> +		if (!nfs_delegations_over_limit(server))
> +			break;
> +		if (pass == 0 && test_bit(NFS_DELEGATION_REFERENCED, &d->flags))
> +			continue;
> +		list_move_tail(&d->entry, &server->delegations_return);
> +		moved = true;
> +	}
> +	spin_unlock(&server->delegations_lock);
> +
> +	/*
> +	 * If we are still over the limit, try to reclaim referenced delegations
> +	 * as well.
> +	 */
> +	if (pass == 0 && nfs_delegations_over_limit(server)) {
> +		pass++;
> +		goto retry;
> +	}
> +
> +	if (moved) {
> +		set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
> +		nfs4_schedule_state_manager(server->nfs_client);
> +	}
> +}
> +
> +static void nfs_delegation_add_lru(struct nfs_server *server,
> +		struct nfs_delegation *delegation)
> +{
> +	spin_lock(&server->delegations_lock);
> +	if (list_empty(&delegation->entry)) {
> +		list_add_tail(&delegation->entry, &server->delegations_lru);
> +		refcount_inc(&delegation->refcount);
> +	}
> +	spin_unlock(&server->delegations_lock);
> +
> +	if (nfs_delegations_over_limit(server))
> +		nfs_delegations_return_from_lru(server);
> +}
> +
>  static bool nfs_server_clear_delayed_delegations(struct nfs_server *server)
>  {
>  	struct nfs_delegation *d;
> @@ -822,6 +876,7 @@ void nfs4_inode_set_return_delegation_on_close(struct inode *inode)
>   */
>  void nfs4_inode_return_delegation_on_close(struct inode *inode)
>  {
> +	struct nfs_server *server = NFS_SERVER(inode);
>  	struct nfs_delegation *delegation;
>  	bool return_now = false;
>  
> @@ -829,9 +884,7 @@ void nfs4_inode_return_delegation_on_close(struct inode *inode)
>  	if (!delegation)
>  		return;
>  
> -	if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) ||
> -	    atomic_long_read(&NFS_SERVER(inode)->nr_active_delegations) >=
> -	    nfs_delegation_watermark) {
> +	if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) {
>  		spin_lock(&delegation->lock);
>  		if (delegation->inode &&
>  		    list_empty(&NFS_I(inode)->open_files) &&
> @@ -845,6 +898,8 @@ void nfs4_inode_return_delegation_on_close(struct inode *inode)
>  	if (return_now) {
>  		nfs_clear_verifier_delegated(inode);
>  		nfs_end_delegation_return(inode, delegation, 0);
> +	} else {
> +		nfs_delegation_add_lru(server, delegation);
>  	}
>  	nfs_put_delegation(delegation);
>  }
> diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
> index e377b8c7086e..bb13a294b69e 100644
> --- a/include/linux/nfs_fs_sb.h
> +++ b/include/linux/nfs_fs_sb.h
> @@ -261,6 +261,7 @@ struct nfs_server {
>  	struct list_head	delegations;
>  	spinlock_t		delegations_lock;
>  	struct list_head	delegations_return;
> +	struct list_head	delegations_lru;
>  	atomic_long_t		nr_active_delegations;
>  	unsigned int		delegation_hash_mask;
>  	struct hlist_head	*delegation_hash_table;


  reply	other threads:[~2025-12-18 22:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18  5:56 add a LRU for delegations Christoph Hellwig
2025-12-18  5:56 ` [PATCH 01/24] NFS: remove __nfs_client_for_each_server Christoph Hellwig
2025-12-18  5:56 ` [PATCH 02/24] NFS: remove nfs_client_mark_return_unused_delegation_types Christoph Hellwig
2025-12-18  5:56 ` [PATCH 03/24] NFS: remove nfs_client_mark_return_all_delegations Christoph Hellwig
2025-12-18  5:56 ` [PATCH 04/24] NFS: remove the NULL inode check in nfs4_inode_return_delegation_on_close Christoph Hellwig
2025-12-18  5:56 ` [PATCH 05/24] NFS: remove nfs_inode_detach_delegation Christoph Hellwig
2025-12-18  5:56 ` [PATCH 06/24] NFS: remove nfs_start_delegation_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 07/24] NFS: assert rcu_read_lock is held in nfs_start_delegation_return_locked Christoph Hellwig
2025-12-18  5:56 ` [PATCH 08/24] NFS: drop the _locked postfix from nfs_start_delegation_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 09/24] NFS: remove NFS_DELEGATION_INODE_FREEING Christoph Hellwig
2025-12-18  5:56 ` [PATCH 10/24] NFS: open code nfs_delegation_need_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 11/24] NFS: remove nfs_free_delegation Christoph Hellwig
2025-12-18  5:56 ` [PATCH 12/24] NFS: rewrite nfs_delegations_present in terms of nr_active_delegations Christoph Hellwig
2025-12-18  5:56 ` [PATCH 13/24] NFS: move delegation lookup into can_open_delegated Christoph Hellwig
2025-12-18  5:56 ` [PATCH 14/24] NFS: return bool from nfs_detach_delegation{,_locked} Christoph Hellwig
2025-12-18  5:56 ` [PATCH 15/24] NFS: move the deleg_cur check out of nfs_detach_delegation_locked Christoph Hellwig
2025-12-18  5:56 ` [PATCH 16/24] NFS: simplify the detached delegation check in update_open_stateid Christoph Hellwig
2025-12-18  5:56 ` [PATCH 17/24] NFS: take a delegation reference in nfs4_get_valid_delegation Christoph Hellwig
2025-12-18  5:56 ` [PATCH 18/24] NFS: don't consume a delegation reference in nfs_end_delegation_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 19/24] NFS: use refcount_inc_not_zero nfs_start_delegation_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 20/24] NFS: use a local RCU critical section in nfs_start_delegation_return Christoph Hellwig
2025-12-18  5:56 ` [PATCH 21/24] NFS: reformat nfs_mark_delegation_revoked Christoph Hellwig
2025-12-18  5:56 ` [PATCH 22/24] NFS: add a separate delegation return list Christoph Hellwig
2025-12-18  5:56 ` [PATCH 23/24] NFS: return delegations from the end of a LRU when over the watermark Christoph Hellwig
2025-12-18 22:02   ` Anna Schumaker [this message]
2025-12-19  5:21     ` Christoph Hellwig
2025-12-19 11:14       ` Christoph Hellwig
2025-12-19 14:29         ` Anna Schumaker
2025-12-18  5:56 ` [PATCH 24/24] NFS: make nfs_mark_return_unreferenced_delegations less aggressive Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2026-01-07  7:26 add a LRU for delegations Christoph Hellwig
2026-01-07  7:27 ` [PATCH 23/24] NFS: return delegations from the end of a LRU when over the watermark Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13891f50-73a1-40ee-aaa2-373dba3886e6@oracle.com \
    --to=anna.schumaker@oracle.com \
    --cc=anna@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox