diff mbox series

[2/2] vfs: reorder struct file structure elements to remove unneeded padding.

Message ID 20240618113505.476072-2-sunjunchao2870@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] xfs: reorder xfs_inode structure elements to remove unneeded padding. | expand

Commit Message

Julian Sun June 18, 2024, 11:35 a.m. UTC
By reordering the elements in the struct file structure, we can
reduce the padding needed on an x86_64 system by 8 bytes.

Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
---
 include/linux/fs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christian Brauner June 18, 2024, 2:52 p.m. UTC | #1
On Tue, Jun 18, 2024 at 07:35:05PM GMT, Junchao Sun wrote:
> By reordering the elements in the struct file structure, we can
> reduce the padding needed on an x86_64 system by 8 bytes.
> 
> Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
> ---
>  include/linux/fs.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 0283cf366c2a..9235b7a960d3 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -999,10 +999,10 @@ struct file {
>  	 */
>  	spinlock_t		f_lock;
>  	fmode_t			f_mode;
> +	unsigned int		f_flags;

Iiuc, then this will push f_pos_lock into a new cache line whereas it's
explicitly optimized so that f_lock, f_mode, and f_pos_lock are all in
the same cache line.

You could play around with moving the union to the end of struct file.
diff mbox series

Patch

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0283cf366c2a..9235b7a960d3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -999,10 +999,10 @@  struct file {
 	 */
 	spinlock_t		f_lock;
 	fmode_t			f_mode;
+	unsigned int		f_flags;
 	atomic_long_t		f_count;
 	struct mutex		f_pos_lock;
 	loff_t			f_pos;
-	unsigned int		f_flags;
 	struct fown_struct	f_owner;
 	const struct cred	*f_cred;
 	struct file_ra_state	f_ra;