public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH 2/7] btrfs: reorder btrfs_block_group members to reduce struct size
Date: Wed, 31 Dec 2025 18:39:35 +0800	[thread overview]
Message-ID: <20251231111623.30136-3-sunk67188@gmail.com> (raw)
In-Reply-To: <20251231111623.30136-1-sunk67188@gmail.com>

Reorder struct btrfs_block_group fields to improve packing and reduce
memory footprint from 624 to 600 bytes (24 bytes saved per instance).

Here's pahole output after this change:

struct btrfs_block_group {
	struct btrfs_fs_info *     fs_info;              /*     0     8 */
	struct btrfs_inode *       inode;                /*     8     8 */
	u64                        start;                /*    16     8 */
	u64                        length;               /*    24     8 */
	u64                        pinned;               /*    32     8 */
	u64                        reserved;             /*    40     8 */
	u64                        used;                 /*    48     8 */
	u64                        delalloc_bytes;       /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	u64                        bytes_super;          /*    64     8 */
	u64                        flags;                /*    72     8 */
	u64                        cache_generation;     /*    80     8 */
	u64                        global_root_id;       /*    88     8 */
	u64                        commit_used;          /*    96     8 */
	u32                        bitmap_high_thresh;   /*   104     4 */
	u32                        bitmap_low_thresh;    /*   108     4 */
	struct rw_semaphore        data_rwsem;           /*   112    40 */
	/* --- cacheline 2 boundary (128 bytes) was 24 bytes ago --- */
	unsigned long              full_stripe_len;      /*   152     8 */
	unsigned long              runtime_flags;        /*   160     8 */
	spinlock_t                 lock;                 /*   168     4 */
	unsigned int               ro;                   /*   172     4 */
	enum btrfs_disk_cache_state disk_cache_state;    /*   176     4 */
	enum btrfs_caching_type    cached;               /*   180     4 */
	struct btrfs_caching_control * caching_ctl;      /*   184     8 */
	/* --- cacheline 3 boundary (192 bytes) --- */
	struct btrfs_space_info *  space_info;           /*   192     8 */
	struct btrfs_free_space_ctl * free_space_ctl;    /*   200     8 */
	struct rb_node             cache_node;           /*   208    24 */
	struct list_head           list;                 /*   232    16 */
	struct list_head           cluster_list;         /*   248    16 */
	/* --- cacheline 4 boundary (256 bytes) was 8 bytes ago --- */
	struct list_head           bg_list;              /*   264    16 */
	struct list_head           ro_list;              /*   280    16 */
	refcount_t                 refs;                 /*   296     4 */
	atomic_t                   frozen;               /*   300     4 */
	struct list_head           discard_list;         /*   304    16 */
	/* --- cacheline 5 boundary (320 bytes) --- */
	enum btrfs_discard_state   discard_state;        /*   320     4 */
	int                        discard_index;        /*   324     4 */
	u64                        discard_eligible_time; /*   328     8 */
	u64                        discard_cursor;       /*   336     8 */
	struct list_head           dirty_list;           /*   344    16 */
	struct list_head           io_list;              /*   360    16 */
	struct btrfs_io_ctl        io_ctl;               /*   376    72 */
	/* --- cacheline 7 boundary (448 bytes) --- */
	atomic_t                   reservations;         /*   448     4 */
	atomic_t                   nocow_writers;        /*   452     4 */
	struct mutex               free_space_lock;      /*   456    32 */
	bool                       using_free_space_bitmaps; /*   488     1 */
	bool                       using_free_space_bitmaps_cached; /*   489     1 */
	bool                       reclaim_mark;         /*   490     1 */

	/* XXX 1 byte hole, try to pack */

	int                        swap_extents;         /*   492     4 */
	u64                        alloc_offset;         /*   496     8 */
	u64                        zone_unusable;        /*   504     8 */
	/* --- cacheline 8 boundary (512 bytes) --- */
	u64                        zone_capacity;        /*   512     8 */
	u64                        meta_write_pointer;   /*   520     8 */
	struct btrfs_chunk_map *   physical_map;         /*   528     8 */
	struct list_head           active_bg_list;       /*   536    16 */
	struct work_struct         zone_finish_work;     /*   552    32 */
	/* --- cacheline 9 boundary (576 bytes) was 8 bytes ago --- */
	struct extent_buffer *     last_eb;              /*   584     8 */
	enum btrfs_block_group_size_class size_class;    /*   592     4 */

	/* size: 600, cachelines: 10, members: 56 */
	/* sum members: 595, holes: 1, sum holes: 1 */
	/* padding: 4 */
	/* last cacheline: 24 bytes */
};

Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
 fs/btrfs/block-group.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
index 3b3c61b3af2c..88c2e3a0a5a0 100644
--- a/fs/btrfs/block-group.h
+++ b/fs/btrfs/block-group.h
@@ -118,7 +118,6 @@ struct btrfs_caching_control {
 struct btrfs_block_group {
 	struct btrfs_fs_info *fs_info;
 	struct btrfs_inode *inode;
-	spinlock_t lock;
 	u64 start;
 	u64 length;
 	u64 pinned;
@@ -159,6 +158,8 @@ struct btrfs_block_group {
 	unsigned long full_stripe_len;
 	unsigned long runtime_flags;
 
+	spinlock_t lock;
+
 	unsigned int ro;
 
 	int disk_cache_state;
@@ -178,8 +179,6 @@ struct btrfs_block_group {
 	/* For block groups in the same raid type */
 	struct list_head list;
 
-	refcount_t refs;
-
 	/*
 	 * List of struct btrfs_free_clusters for this block group.
 	 * Today it will only have one thing on it, but that may change
@@ -199,6 +198,8 @@ struct btrfs_block_group {
 	/* For read-only block groups */
 	struct list_head ro_list;
 
+	refcount_t refs;
+
 	/*
 	 * When non-zero it means the block group's logical address and its
 	 * device extents can not be reused for future block group allocations
@@ -211,10 +212,10 @@ struct btrfs_block_group {
 
 	/* For discard operations */
 	struct list_head discard_list;
+	enum btrfs_discard_state discard_state;
 	int discard_index;
 	u64 discard_eligible_time;
 	u64 discard_cursor;
-	enum btrfs_discard_state discard_state;
 
 	/* For dirty block groups */
 	struct list_head dirty_list;
-- 
2.51.2


  parent reply	other threads:[~2025-12-31 11:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31 10:39 [PATCH 0/7] btrfs: fix periodic reclaim condition with some cleanup Sun YangKai
2025-12-31 10:39 ` [PATCH 1/7] btrfs: change block group reclaim_mark to bool Sun YangKai
2025-12-31 10:39 ` Sun YangKai [this message]
2025-12-31 10:39 ` [PATCH 3/7] btrfs: use proper types for btrfs_block_group fields Sun YangKai
2025-12-31 10:39 ` [PATCH 4/7] btrfs: consolidate reclaim readiness checks in btrfs_should_reclaim() Sun YangKai
2025-12-31 10:39 ` [PATCH 5/7] btrfs: use u8 for reclaim threshold type Sun YangKai
2025-12-31 10:39 ` [PATCH 6/7] btrfs: clarify reclaim sweep control flow Sun YangKai
2025-12-31 10:39 ` [PATCH 7/7] btrfs: fix periodic reclaim condition Sun YangKai
2026-01-01  0:20   ` Qu Wenruo
2026-01-01 11:44     ` Sun Yangkai
2026-01-01  0:13 ` [PATCH 0/7] btrfs: fix periodic reclaim condition with some cleanup Qu Wenruo
2026-01-01 11:54   ` Sun Yangkai
2026-01-01 21:14     ` Qu Wenruo
2026-01-03 11:17       ` Sun Yangkai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251231111623.30136-3-sunk67188@gmail.com \
    --to=sunk67188@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox