Skip to contentSkip to conversation

NFS: dont restart loop in nfs_delegation_reap_unclaimed

PATCH In review Weston Andros Adamson 3 participants 5 messages Apr 14, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: dont restart loop in nfs_delegation_reap_unclaimed

The loop was being restarted after each delegation that has NFS_DELEGATION_NEED_RECLAIM set. Instead, build a temporary list of delegations that need to be freed and free them after the for-each-delegation loop.

---
 fs/nfs/delegation.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +11 -5
index bbbc6bf..c87fad8 100644
@@ -645,8 +645,8 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
 	struct nfs_delegation *delegation;
 	struct nfs_server *server;
 	struct inode *inode;
+	LIST_HEAD(tmplist);
 
-restart:
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
 		list_for_each_entry_rcu(delegation, &server->delegations,
@@ -659,15 +659,21 @@ restart:
 				continue;
 			delegation = nfs_detach_delegation(NFS_I(inode),
 								server);
-			rcu_read_unlock();
-
+			/* super_list is unused now that deleg is detached */
 			if (delegation != NULL)
-				nfs_free_delegation(delegation);
+				list_add(&delegation->super_list, &tmplist);
+
 			iput(inode);
-			goto restart;
 		}
 	}
 	rcu_read_unlock();
+
+	while (!list_empty(&tmplist)) {
+		delegation = list_first_entry(&tmplist, struct nfs_delegation,
+					super_list);
+		list_del(&delegation->super_list);
+		nfs_free_delegation(delegation);
+	}
 }
 
 /**
Signature · 1 line
1.7.4.2
#1 lore raw
Quoted 25 lines · Weston Andros Adamson

The loop was being restarted after each delegation that has NFS_DELEGATION_NEED_RECLAIM set. Instead, build a temporary list of delegations that need to be freed and free them after the for-each-delegation loop.

---
fs/nfs/delegation.c | 16 +++++++++++-----

1 files changed, 11 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +1 -1
index bbbc6bf..c87fad8 100644
@@ -645,8 +645,8 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
 	struct nfs_delegation *delegation;
 	struct nfs_server *server;
 	struct inode *inode;
+	LIST_HEAD(tmplist);
 
-restart:
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
 		list_for_each_entry_rcu(delegation, &server->delegations,
@@ -659,15 +659,21 @@ restart:
 				continue;

fs/nfs/delegation.c restart: · line 666

Quoted 10 lines
fs/nfs/delegation.c +3 -3
 			delegation = nfs_detach_delegation(NFS_I(inode),
 								server);
-			rcu_read_unlock();
-
+			/* super_list is unused now that deleg is detached */
 			if (delegation != NULL)
-				nfs_free_delegation(delegation);
+				list_add(&delegation->super_list, &tmplist);
+
 			iput(inode);

/me idly wonders if that iput() is safe to do inside rcu_read_lock() / rcu_read_unlock().

Quoted 21 lines
fs/nfs/delegation.c +7 -1
-			goto restart;
 		}
 	}
 	rcu_read_unlock();
+
+	while (!list_empty(&tmplist)) {
+		delegation = list_first_entry(&tmplist, struct nfs_delegation,
+					super_list);
+		list_del(&delegation->super_list);
+		nfs_free_delegation(delegation);
+	}
 }
 
 /**
Signature · 6 lines
1.7.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#2 lore raw
Quoted 32 lines · Chuck Lever
Quoted 29 lines · Weston Andros Adamson

The loop was being restarted after each delegation that has NFS_DELEGATION_NEED_RECLAIM set. Instead, build a temporary list of delegations that need to be freed and free them after the for-each-delegation loop.

---
fs/nfs/delegation.c | 16 +++++++++++-----

1 files changed, 11 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +1 -3
index bbbc6bf..c87fad8 100644
@@ -645,8 +645,8 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
 	struct nfs_delegation *delegation;
 	struct nfs_server *server;
 	struct inode *inode;
+	LIST_HEAD(tmplist);
 
-restart:
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
 		list_for_each_entry_rcu(delegation, &server->delegations,
@@ -659,15 +659,21 @@ restart:
 				continue;
 			delegation = nfs_detach_delegation(NFS_I(inode),
 								server);
-			rcu_read_unlock();
-
Quoted 8 lines

fs/nfs/delegation.c restart: · line 666

Quoted 6 lines
fs/nfs/delegation.c +3 -1
+			/* super_list is unused now that deleg is detached */
 			if (delegation != NULL)
-				nfs_free_delegation(delegation);
+				list_add(&delegation->super_list, &tmplist);
+
 			iput(inode);

/me idly wonders if that iput() is safe to do inside rcu_read_lock() / rcu_read_unlock().

Hrm, I think you're right. I take this patch back!

-dros

#3 lore raw
In reply to Chuck Lever
Quoted 31 lines · Chuck Lever
Quoted 29 lines · Weston Andros Adamson

The loop was being restarted after each delegation that has NFS_DELEGATION_NEED_RECLAIM set. Instead, build a temporary list of delegations that need to be freed and free them after the for-each-delegation loop.

---
fs/nfs/delegation.c | 16 +++++++++++-----

1 files changed, 11 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +1 -3
index bbbc6bf..c87fad8 100644
@@ -645,8 +645,8 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
 	struct nfs_delegation *delegation;
 	struct nfs_server *server;
 	struct inode *inode;
+	LIST_HEAD(tmplist);
 
-restart:
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
 		list_for_each_entry_rcu(delegation, &server->delegations,
@@ -659,15 +659,21 @@ restart:
 				continue;
 			delegation = nfs_detach_delegation(NFS_I(inode),
 								server);
-			rcu_read_unlock();
-
Quoted 8 lines

fs/nfs/delegation.c restart: · line 666

Quoted 6 lines
fs/nfs/delegation.c +3 -1
+			/* super_list is unused now that deleg is detached */
 			if (delegation != NULL)
-				nfs_free_delegation(delegation);
+				list_add(&delegation->super_list, &tmplist);
+
 			iput(inode);

/me idly wonders if that iput() is safe to do inside rcu_read_lock() / rcu_read_unlock().

It isn't....

Quoted 4 lines
Quoted 4 lines
fs/nfs/delegation.c +0 -1
-			goto restart;
 		}
 	}
 	rcu_read_unlock();
Quoted 8 lines

fs/nfs/delegation.c restart: · line 677

Quoted 8 lines
fs/nfs/delegation.c +7 -0
+
+	while (!list_empty(&tmplist)) {
+		delegation = list_first_entry(&tmplist, struct nfs_delegation,
+					super_list);
+		list_del(&delegation->super_list);
+		nfs_free_delegation(delegation);
+	}
 }

There is also the issue that the inode may have disappeared when we get to this stage; there is nothing pinning it in memory any more.

One suggestion would be to move the iput into the above loop.

The question is, though, whether or not we get much of a performance improvement.
One advantage of the current scheme is that we're immediately freeing the delegation after detaching it. If you queue up the delegations for freeing, then a process that may need to free a delegation that is at the end of that list in order to make progress (because it wants to rename a file, or open it for writing) may have a longer wait during which the server will be replying NFS4ERR_DELAY.

Do we have any evidence for or against?

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
#4 lore raw
Quoted 59 lines · Trond Myklebust
Quoted 31 lines · Chuck Lever
Quoted 29 lines · Weston Andros Adamson

The loop was being restarted after each delegation that has NFS_DELEGATION_NEED_RECLAIM set. Instead, build a temporary list of delegations that need to be freed and free them after the for-each-delegation loop.

---
fs/nfs/delegation.c | 16 +++++++++++-----

1 files changed, 11 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +1 -3
index bbbc6bf..c87fad8 100644
@@ -645,8 +645,8 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
 	struct nfs_delegation *delegation;
 	struct nfs_server *server;
 	struct inode *inode;
+	LIST_HEAD(tmplist);
 
-restart:
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
 		list_for_each_entry_rcu(delegation, &server->delegations,
@@ -659,15 +659,21 @@ restart:
 				continue;
 			delegation = nfs_detach_delegation(NFS_I(inode),
 								server);
-			rcu_read_unlock();
-
Quoted 8 lines

fs/nfs/delegation.c restart: · line 666

Quoted 6 lines
fs/nfs/delegation.c +3 -1
+			/* super_list is unused now that deleg is detached */
 			if (delegation != NULL)
-				nfs_free_delegation(delegation);
+				list_add(&delegation->super_list, &tmplist);
+
 			iput(inode);

/me idly wonders if that iput() is safe to do inside rcu_read_lock() / rcu_read_unlock().

It isn't....

Quoted 4 lines
Quoted 4 lines
fs/nfs/delegation.c +0 -1
-			goto restart;
 		}
 	}
 	rcu_read_unlock();
Quoted 8 lines

fs/nfs/delegation.c restart: · line 677

Quoted 8 lines
fs/nfs/delegation.c +7 -0
+
+	while (!list_empty(&tmplist)) {
+		delegation = list_first_entry(&tmplist, struct nfs_delegation,
+					super_list);
+		list_del(&delegation->super_list);
+		nfs_free_delegation(delegation);
+	}
 }

There is also the issue that the inode may have disappeared when we get to this stage; there is nothing pinning it in memory any more.

Quoted 1 line

One suggestion would be to move the iput into the above loop.

Good points! Sorry, I'm still trying to wrap my head around RCU...

Quoted 11 lines

The question is, though, whether or not we get much of a performance improvement.
One advantage of the current scheme is that we're immediately freeing the delegation after detaching it. If you queue up the delegations for freeing, then a process that may need to free a delegation that is at the end of that list in order to make progress (because it wants to rename a file, or open it for writing) may have a longer wait during which the server will be replying NFS4ERR_DELAY.

Do we have any evidence for or against?

Well, the reason that I attempted to fix this is that it looks very wrong for this scenario:

- there are many nfs_server structures with many delegations
- servers at the end of the list have many delegations with NEED_RECLAIM set

In this case, we have terrible performance, iterating through the first N delegations (that don't need to be reclaimed) potentially many, many times.

In your example, the delegation that needs reclaiming is at the end of the list, so both methods need to traverse the whole server list and each of the delegation sub-lists.
If there is really only one (or a few) that need reclaiming, the difference between methods should be negligible. If there are many that need reclaiming, the "dont restart the loop every time" method should be a clear winner.

The scenario where the "restart every time" loop is faster (for a waiting process) is when the only delegations that need reclaiming are at the beginning of the list-of-lists (the other method won't free until iterating through everything).

But my question is: once a delegation is detached, can't a waiting process progress? as far as i can tell, nfs_free_delegation() is just a RCU safe wrapper for kfree(). nfs_detach_delegation() removes it from the list, and sets the nfs_inode's delegation pointer to NULL. I'm new here, but as far as I can tell, at that point it should be out of the picture (outside of freeing it).

Maybe this work isn't needed. It just looked wrong to me!

Thoughts?

-dros