Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
@ 2024-06-03 13:15 Junchao Sun
  2024-06-03 14:07 ` Jan Kara
  2024-08-22 15:00 ` Theodore Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Junchao Sun @ 2024-06-03 13:15 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, adilger.kernel, jack, Junchao Sun

Using pahole, we can see that there are some padding holes
in the current ext4_inode_info structure. Adjusting the
layout of ext4_inode_info can reduce these holes,
resulting in the size of the structure decreasing
from 2424 bytes to 2408 bytes.

Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
---
 fs/ext4/ext4.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 023571f8dd1b..42bcd4f749a8 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1055,6 +1055,7 @@ struct ext4_inode_info {
 
 	/* Number of ongoing updates on this inode */
 	atomic_t  i_fc_updates;
+	atomic_t i_unwritten; /* Nr. of inflight conversions pending */
 
 	/* Fast commit wait queue for this inode */
 	wait_queue_head_t i_fc_wait;
@@ -1103,6 +1104,10 @@ struct ext4_inode_info {
 
 	/* mballoc */
 	atomic_t i_prealloc_active;
+
+	/* allocation reservation info for delalloc */
+	/* In case of bigalloc, this refer to clusters rather than blocks */
+	unsigned int i_reserved_data_blocks;
 	struct rb_root i_prealloc_node;
 	rwlock_t i_prealloc_lock;
 
@@ -1119,10 +1124,6 @@ struct ext4_inode_info {
 	/* ialloc */
 	ext4_group_t	i_last_alloc_group;
 
-	/* allocation reservation info for delalloc */
-	/* In case of bigalloc, this refer to clusters rather than blocks */
-	unsigned int i_reserved_data_blocks;
-
 	/* pending cluster reservations for bigalloc file systems */
 	struct ext4_pending_tree i_pending_tree;
 
@@ -1146,7 +1147,6 @@ struct ext4_inode_info {
 	 */
 	struct list_head i_rsv_conversion_list;
 	struct work_struct i_rsv_conversion_work;
-	atomic_t i_unwritten; /* Nr. of inflight conversions pending */
 
 	spinlock_t i_block_reservation_lock;
 
-- 
2.39.2


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

* Re: [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
  2024-06-03 13:15 [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory Junchao Sun
@ 2024-06-03 14:07 ` Jan Kara
  2024-06-03 14:43   ` JunChao Sun
  2024-08-22 15:00 ` Theodore Ts'o
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kara @ 2024-06-03 14:07 UTC (permalink / raw)
  To: Junchao Sun; +Cc: linux-ext4, tytso, adilger.kernel, jack

On Mon 03-06-24 21:15:24, Junchao Sun wrote:
> Using pahole, we can see that there are some padding holes
> in the current ext4_inode_info structure. Adjusting the
> layout of ext4_inode_info can reduce these holes,
> resulting in the size of the structure decreasing
> from 2424 bytes to 2408 bytes.

But AFAICT this will save two holes 4 bytes each so only 8 bytes in total?
Not 16?

> 
> Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>

Otherwise looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/ext4.h | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 023571f8dd1b..42bcd4f749a8 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -1055,6 +1055,7 @@ struct ext4_inode_info {
>  
>  	/* Number of ongoing updates on this inode */
>  	atomic_t  i_fc_updates;
> +	atomic_t i_unwritten; /* Nr. of inflight conversions pending */
>  
>  	/* Fast commit wait queue for this inode */
>  	wait_queue_head_t i_fc_wait;
> @@ -1103,6 +1104,10 @@ struct ext4_inode_info {
>  
>  	/* mballoc */
>  	atomic_t i_prealloc_active;
> +
> +	/* allocation reservation info for delalloc */
> +	/* In case of bigalloc, this refer to clusters rather than blocks */
> +	unsigned int i_reserved_data_blocks;
>  	struct rb_root i_prealloc_node;
>  	rwlock_t i_prealloc_lock;
>  
> @@ -1119,10 +1124,6 @@ struct ext4_inode_info {
>  	/* ialloc */
>  	ext4_group_t	i_last_alloc_group;
>  
> -	/* allocation reservation info for delalloc */
> -	/* In case of bigalloc, this refer to clusters rather than blocks */
> -	unsigned int i_reserved_data_blocks;
> -
>  	/* pending cluster reservations for bigalloc file systems */
>  	struct ext4_pending_tree i_pending_tree;
>  
> @@ -1146,7 +1147,6 @@ struct ext4_inode_info {
>  	 */
>  	struct list_head i_rsv_conversion_list;
>  	struct work_struct i_rsv_conversion_work;
> -	atomic_t i_unwritten; /* Nr. of inflight conversions pending */
>  
>  	spinlock_t i_block_reservation_lock;
>  
> -- 
> 2.39.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
  2024-06-03 14:07 ` Jan Kara
@ 2024-06-03 14:43   ` JunChao Sun
  2024-06-03 15:24     ` Jan Kara
  0 siblings, 1 reply; 5+ messages in thread
From: JunChao Sun @ 2024-06-03 14:43 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, tytso, adilger.kernel

Jan Kara <jack@suse.cz> 于2024年6月3日周一 22:07写道:
>
> On Mon 03-06-24 21:15:24, Junchao Sun wrote:
> > Using pahole, we can see that there are some padding holes
> > in the current ext4_inode_info structure. Adjusting the
> > layout of ext4_inode_info can reduce these holes,
> > resulting in the size of the structure decreasing
> > from 2424 bytes to 2408 bytes.
>
>
> > But AFAICT this will save two holes 4 bytes each so only 8 bytes in total?
> > Not 16?

Indeed it's 16.
Consider the layout int a; hole 0; int b; hole 1; And then move int b
to hole 0 position, this adjustment resulted in saving 8 bytes. There
are two adjustments like this, so it's 16. And GDB confirmed this.

>
> >
> > Signed-off-by: Junchao Sun <sunjunchao2870@gmail.com>
>
> Otherwise looks good. Feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
>                                                                 Honza
>
> > ---
> >  fs/ext4/ext4.h | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> > index 023571f8dd1b..42bcd4f749a8 100644
> > --- a/fs/ext4/ext4.h
> > +++ b/fs/ext4/ext4.h
> > @@ -1055,6 +1055,7 @@ struct ext4_inode_info {
> >
> >       /* Number of ongoing updates on this inode */
> >       atomic_t  i_fc_updates;
> > +     atomic_t i_unwritten; /* Nr. of inflight conversions pending */
> >
> >       /* Fast commit wait queue for this inode */
> >       wait_queue_head_t i_fc_wait;
> > @@ -1103,6 +1104,10 @@ struct ext4_inode_info {
> >
> >       /* mballoc */
> >       atomic_t i_prealloc_active;
> > +
> > +     /* allocation reservation info for delalloc */
> > +     /* In case of bigalloc, this refer to clusters rather than blocks */
> > +     unsigned int i_reserved_data_blocks;
> >       struct rb_root i_prealloc_node;
> >       rwlock_t i_prealloc_lock;
> >
> > @@ -1119,10 +1124,6 @@ struct ext4_inode_info {
> >       /* ialloc */
> >       ext4_group_t    i_last_alloc_group;
> >
> > -     /* allocation reservation info for delalloc */
> > -     /* In case of bigalloc, this refer to clusters rather than blocks */
> > -     unsigned int i_reserved_data_blocks;
> > -
> >       /* pending cluster reservations for bigalloc file systems */
> >       struct ext4_pending_tree i_pending_tree;
> >
> > @@ -1146,7 +1147,6 @@ struct ext4_inode_info {
> >        */
> >       struct list_head i_rsv_conversion_list;
> >       struct work_struct i_rsv_conversion_work;
> > -     atomic_t i_unwritten; /* Nr. of inflight conversions pending */
> >
> >       spinlock_t i_block_reservation_lock;
> >
> > --
> > 2.39.2
> >
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR

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

* Re: [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
  2024-06-03 14:43   ` JunChao Sun
@ 2024-06-03 15:24     ` Jan Kara
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kara @ 2024-06-03 15:24 UTC (permalink / raw)
  To: JunChao Sun; +Cc: Jan Kara, linux-ext4, tytso, adilger.kernel

On Mon 03-06-24 22:43:16, JunChao Sun wrote:
> Jan Kara <jack@suse.cz> 于2024年6月3日周一 22:07写道:
> >
> > On Mon 03-06-24 21:15:24, Junchao Sun wrote:
> > > Using pahole, we can see that there are some padding holes
> > > in the current ext4_inode_info structure. Adjusting the
> > > layout of ext4_inode_info can reduce these holes,
> > > resulting in the size of the structure decreasing
> > > from 2424 bytes to 2408 bytes.
> >
> >
> > > But AFAICT this will save two holes 4 bytes each so only 8 bytes in total?
> > > Not 16?
> 
> Indeed it's 16.
> Consider the layout int a; hole 0; int b; hole 1; And then move int b
> to hole 0 position, this adjustment resulted in saving 8 bytes. There
> are two adjustments like this, so it's 16. And GDB confirmed this.

Aha, OK. Thanks for clarification!

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
  2024-06-03 13:15 [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory Junchao Sun
  2024-06-03 14:07 ` Jan Kara
@ 2024-08-22 15:00 ` Theodore Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2024-08-22 15:00 UTC (permalink / raw)
  To: linux-ext4, Junchao Sun; +Cc: Theodore Ts'o, adilger.kernel, jack


On Mon, 03 Jun 2024 21:15:24 +0800, Junchao Sun wrote:
> Using pahole, we can see that there are some padding holes
> in the current ext4_inode_info structure. Adjusting the
> layout of ext4_inode_info can reduce these holes,
> resulting in the size of the structure decreasing
> from 2424 bytes to 2408 bytes.
> 
> 
> [...]

Applied, thanks!

[1/1] ext4: Adjust the layout of the ext4_inode_info structure to save memory.
      commit: a3c3eecc7c876c7f2b09d9ee1acf5b8b85996cff

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

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

end of thread, other threads:[~2024-08-22 15:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 13:15 [PATCH] ext4: Adjust the layout of the ext4_inode_info structure to save memory Junchao Sun
2024-06-03 14:07 ` Jan Kara
2024-06-03 14:43   ` JunChao Sun
2024-06-03 15:24     ` Jan Kara
2024-08-22 15:00 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox