linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs.h: Optimize file struct to prevent false sharing
@ 2023-05-30  2:06 chenzhiyin
  2023-05-30  8:50 ` Christian Brauner
  0 siblings, 1 reply; 15+ messages in thread
From: chenzhiyin @ 2023-05-30  2:06 UTC (permalink / raw)
  To: viro, brauner; +Cc: linux-fsdevel, linux-kernel, nanhai.zou, zhiyin.chen

In the syscall test of UnixBench, performance regression occurred
due to false sharing.

The lock and atomic members, including file::f_lock, file::f_count
and file::f_pos_lock are highly contended and frequently updated
in the high-concurrency test scenarios. perf c2c indentified one
affected read access, file::f_op.
To prevent false sharing, the layout of file struct is changed as
following
(A) f_lock, f_count and f_pos_lock are put together to share the
same cache line.
(B) The read mostly members, including f_path, f_inode, f_op are
put into a separate cache line.
(C) f_mode is put together with f_count, since they are used
frequently at the same time.

The optimization has been validated in the syscall test of
UnixBench. performance gain is 30~50%, when the number of parallel
jobs is 16.

Signed-off-by: chenzhiyin <zhiyin.chen@intel.com>
---
 include/linux/fs.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 21a981680856..01c55e3a1b96 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -962,23 +962,23 @@ struct file {
 		struct rcu_head 	f_rcuhead;
 		unsigned int 		f_iocb_flags;
 	};
-	struct path		f_path;
-	struct inode		*f_inode;	/* cached value */
-	const struct file_operations	*f_op;
 
 	/*
 	 * Protects f_ep, f_flags.
 	 * Must not be taken from IRQ context.
 	 */
 	spinlock_t		f_lock;
-	atomic_long_t		f_count;
-	unsigned int 		f_flags;
 	fmode_t			f_mode;
+	atomic_long_t		f_count;
 	struct mutex		f_pos_lock;
+	unsigned int		f_flags;
 	loff_t			f_pos;
 	struct fown_struct	f_owner;
 	const struct cred	*f_cred;
 	struct file_ra_state	f_ra;
+	struct path		f_path;
+	struct inode		*f_inode;	/* cached value */
+	const struct file_operations	*f_op;
 
 	u64			f_version;
 #ifdef CONFIG_SECURITY
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-06-05 12:59 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30  2:06 [PATCH] fs.h: Optimize file struct to prevent false sharing chenzhiyin
2023-05-30  8:50 ` Christian Brauner
2023-05-30 10:02   ` Amir Goldstein
2023-05-31 11:15     ` Christian Brauner
2023-05-31  1:55   ` Eric Biggers
2023-05-31  7:54     ` Christian Brauner
2023-06-01  9:24       ` chenzhiyin
2023-06-01  9:49         ` Christian Brauner
2023-06-01 10:06         ` Bernd Schubert
2023-06-05 12:58         ` Christian Brauner
2023-05-31 10:31     ` Chen, Zhiyin
2023-05-31 22:30       ` Dave Chinner
2023-06-01 10:47         ` Chen, Zhiyin
2023-06-02  0:47           ` Dave Chinner
2023-06-02 11:01             ` Chen, Zhiyin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).