Skip to contentSkip to conversation

nfs: avoid triggering out-of-order write handling in nfs_setattr()

PATCH In review Michael Stoler 2 participants 2 messages Feb 22 – Feb 23

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

PATCH 1/1 nfs: avoid triggering out-of-order write handling in nfs_setattr()

I’m seeing a performance issue with an NFS driver based on Linux 6.6. When
untar extracts an archive, it sets file attributes and timestamps after each file is created. As a result, the inodes of these files are marked as OOO (out-of-order write), which causes valid page cache to be dropped on subsequent opens.
This false OOO tagging occurs during the nfs_setattr() inode method. The
reason is that inode attributes are updated twice: first in the protocol version specific method nfs*_proc_setattr(), and then again in nfs_setattr() itself via nfs_refresh_inode(), even though the inode state has already been updated by nfs_update_inode() in protocol-version-specific method. As a result, nfs_refresh_inode() falsely detects the second attempt to apply the same file attributes as an out-of-order operation and marks the inode with an OOO range.
The proposed patch resolves this issue by eliminating the second inode
attribute update in nfs_refresh_inode() when the inode has already been updated.

---
 fs/nfs/inode.c         | 10 ++++++----
 fs/nfs/nfs3proc.c      |  2 +-
 fs/nfs/nfs4proc.c      |  2 +-
 fs/nfs/proc.c          |  2 +-
 include/linux/nfs_fs.h |  2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)
fs/nfs/inode.c +6 -4
index 0d7facfdafb9..13ac5dffd3e6 100644
@@ -657,8 +657,6 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	}
 
 	error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
-	if (error == 0)
-		error = nfs_refresh_inode(inode, fattr);
 	nfs_free_fattr(fattr);
 out:
 	trace_nfs_setattr_exit(inode, error);
@@ -709,9 +707,11 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset)
  * Note: we do this in the *proc.c in order to ensure that
  *       it works for things like exclusive creates too.
  */
-void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
+int nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
 		struct nfs_fattr *fattr)
 {
+	int ret = 0;
+
 	/* Barrier: bump the attribute generation count. */
 	nfs_fattr_set_barrier(fattr);
 
@@ -780,8 +780,10 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
 					| NFS_INO_INVALID_CTIME);
 	}
 	if (fattr->valid)
-		nfs_update_inode(inode, fattr);
+		ret = nfs_update_inode(inode, fattr);
 	spin_unlock(&inode->i_lock);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
 
fs/nfs/nfs3proc.c +1 -1
index 715753f41fb0..dc9f33735cf2 100644
@@ -144,7 +144,7 @@ nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
 	nfs_fattr_init(fattr);
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
 	if (status == 0) {
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 		if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
 			nfs_zap_acl_cache(inode);
 	}
fs/nfs/nfs4proc.c +1 -1
index fe6986939bc9..a41c5b046205 100644
@@ -4436,7 +4436,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
 
 	status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL);
 	if (status == 0) {
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 		nfs_setsecurity(inode, fattr);
 	}
 	return status;
fs/nfs/proc.c +1 -1
index e3570c656b0f..edf3edf6720a 100644
@@ -147,7 +147,7 @@ nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
 	nfs_fattr_init(fattr);
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
 	if (status == 0)
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 	dprintk("NFS reply setattr: %d\n", status);
 	return status;
 }
include/linux/nfs_fs.h +1 -1
index 832b7e354b4e..a1bcec8d0992 100644
@@ -434,7 +434,7 @@ extern bool nfs_mapping_need_revalidate_inode(struct inode *inode);
 extern int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
 extern int nfs_revalidate_mapping_rcu(struct inode *inode);
 extern int nfs_setattr(struct mnt_idmap *, struct dentry *, struct iattr *);
-extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, struct nfs_fattr *);
+extern int nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, struct nfs_fattr *);
 extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr);
 extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
 extern void put_nfs_open_context(struct nfs_open_context *ctx);
Signature · 1 line
2.53.0
#1 lore raw

Hi Michael,

Quoted 1 line · Michael Stoler

I’m seeing a performance issue with an NFS driver based on Linux 6.6. When

Linux 6.6 was from late 2023. Have you checked if this problem is still there on a more recent upstream Linux kernel?

Quoted 28 lines

untar extracts an archive, it sets file attributes and timestamps after each file is created. As a result, the inodes of these files are marked as OOO (out-of-order write), which causes valid page cache to be dropped on subsequent opens.
This false OOO tagging occurs during the nfs_setattr() inode method. The
reason is that inode attributes are updated twice: first in the protocol version specific method nfs*_proc_setattr(), and then again in nfs_setattr() itself via nfs_refresh_inode(), even though the inode state has already been updated by nfs_update_inode() in protocol-version-specific method. As a result, nfs_refresh_inode() falsely detects the second attempt to apply the same file attributes as an out-of-order operation and marks the inode with an OOO range.
The proposed patch resolves this issue by eliminating the second inode
attribute update in nfs_refresh_inode() when the inode has already been updated.

---
 fs/nfs/inode.c         | 10 ++++++----
 fs/nfs/nfs3proc.c      |  2 +-
 fs/nfs/nfs4proc.c      |  2 +-
 fs/nfs/proc.c          |  2 +-
 include/linux/nfs_fs.h |  2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)
fs/nfs/inode.c +0 -0
index 0d7facfdafb9..13ac5dffd3e6 100644

fs/nfs/inode.c nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 661

Quoted 5 lines
fs/nfs/inode.c +0 -2
@@ -657,8 +657,6 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
 	}
 
 	error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
-	if (error == 0)
-		error = nfs_refresh_inode(inode, fattr);

The code in this area has changed in the last 6 months and does an extra ATTR_SIZE check in this if statement that you're removing. Any chance you can rebase your patch on current upstream and resubmit?

Thanks,
Anna

Quoted 94 lines
fs/nfs/inode.c +6 -2
 	nfs_free_fattr(fattr);
 out:
 	trace_nfs_setattr_exit(inode, error);
@@ -709,9 +707,11 @@ static int nfs_vmtruncate(struct inode * inode, 
 loff_t offset)
  * Note: we do this in the *proc.c in order to ensure that
  *       it works for things like exclusive creates too.
  */
-void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
+int nfs_setattr_update_inode(struct inode *inode, struct iattr *attr,
 		struct nfs_fattr *fattr)
 {
+	int ret = 0;
+
 	/* Barrier: bump the attribute generation count. */
 	nfs_fattr_set_barrier(fattr);
@@ -780,8 +780,10 @@ void nfs_setattr_update_inode(struct inode *inode, 
 struct iattr *attr,
 					| NFS_INO_INVALID_CTIME);
 	}
 	if (fattr->valid)
-		nfs_update_inode(inode, fattr);
+		ret = nfs_update_inode(inode, fattr);
 	spin_unlock(&inode->i_lock);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(nfs_setattr_update_inode);
fs/nfs/nfs3proc.c +1 -1
index 715753f41fb0..dc9f33735cf2 100644
@@ -144,7 +144,7 @@ nfs3_proc_setattr(struct dentry *dentry, struct 
 nfs_fattr *fattr,
 	nfs_fattr_init(fattr);
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
 	if (status == 0) {
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 		if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
 			nfs_zap_acl_cache(inode);
fs/nfs/nfs3proc.c +0 -0
 	}
fs/nfs/nfs4proc.c +1 -1
index fe6986939bc9..a41c5b046205 100644
@@ -4436,7 +4436,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct 
 nfs_fattr *fattr,
 
 	status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL);
 	if (status == 0) {
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 		nfs_setsecurity(inode, fattr);
 	}
fs/nfs/nfs4proc.c +0 -0
 	return status;
fs/nfs/proc.c +1 -1
index e3570c656b0f..edf3edf6720a 100644
@@ -147,7 +147,7 @@ nfs_proc_setattr(struct dentry *dentry, struct 
 nfs_fattr *fattr,
 	nfs_fattr_init(fattr);
 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
 	if (status == 0)
-		nfs_setattr_update_inode(inode, sattr, fattr);
+		status = nfs_setattr_update_inode(inode, sattr, fattr);
 	dprintk("NFS reply setattr: %d\n", status);
 	return status;

}

include/linux/nfs_fs.h +0 -1
index 832b7e354b4e..a1bcec8d0992 100644
@@ -434,7 +434,7 @@ extern bool 
 nfs_mapping_need_revalidate_inode(struct inode *inode);
 extern int nfs_revalidate_mapping(struct inode *inode, struct 
 address_space *mapping);
 extern int nfs_revalidate_mapping_rcu(struct inode *inode);
 extern int nfs_setattr(struct mnt_idmap *, struct dentry *, struct 
 iattr *);
-extern void nfs_setattr_update_inode(struct inode *inode, struct iattr 

*attr, struct nfs_fattr *);
+extern int nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, struct nfs_fattr *);
extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr
*fattr);
extern struct nfs_open_context *get_nfs_open_context(struct
nfs_open_context *ctx);
extern void put_nfs_open_context(struct nfs_open_context *ctx);

Signature · 1 line
2.53.0