btrfs: change block group reclaim_mark to bool
PATCH 1/1 btrfs: change block group reclaim_mark to bool
The reclaim_mark field in struct btrfs_block_group was a u64 that was incremented when marking block groups for reclaim during sweeping, but the actual counter value was never used - only the zero/non-zero state mattered for determining if a block group needed reclaim.
Convert it to a bool to properly reflect its usage and reduce memory footprint by 8 bytes. Update assignments to use true/false instead of increment and zero.
--- fs/btrfs/block-group.c | 2 +- fs/btrfs/block-group.h | 7 ++++++- fs/btrfs/space-info.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/block-group.c +1 -1
@@ -3923,7 +3923,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, old_val += num_bytes; cache->used = old_val; cache->reserved -= num_bytes; - cache->reclaim_mark =0 ; + cache->reclaim_mark = false; space_info->bytes_reserved -= num_bytes; space_info->bytes_used += num_bytes; space_info->disk_used += num_bytes * factor;
fs/btrfs/block-group.h +6 -1
@@ -263,6 +263,12 @@ struct btrfs_block_group { enum btrfs_block_group_size_class size_class:8; +/* +* Mark this blockgroup is not used for allocation +* between two reclaim sweeps. +*/ +bool reclaim_mark; +/* * Number of extents in this block group used for swap files. * All accesses protected by the spinlock 'lock'.
@@ -281,7 +287,6 @@ struct btrfs_block_group {struct list_head active_bg_list;struct work_struct zone_finish_work;struct extent_buffer *last_eb; -u64 reclaim_mark; };static inline u64 btrfs_block_group_end (const struct btrfs_block_group *block_group)
fs/btrfs/space-info.c +1 -1
@@ -2156,7 +2156,7 @@ static bool do_reclaim_sweep(struct btrfs_space_info *space_info, int raid) will_reclaim = true; reclaim = true; } - bg->reclaim_mark++; + bg->reclaim_mark = true;spin_unlock (&bg->lock);if (reclaim)btrfs_mark_bg_to_reclaim (bg);
Signature · 1 line
2.54.0
Quoted 9 lines · Sun YangKai
The
reclaim_markfield in structbtrfs_block_groupwas a u64 that was incremented when marking block groups for reclaim during sweeping, but the actual counter value was never used - only the zero/non-zero state mattered for determining if a block group needed reclaim.Convert it to a bool to properly reflect its usage and reduce memory footprint by 8 bytes. Update assignments to use true/false instead of increment and zero.
LGTM, thanks.
Quoted 25 lines
Signed-off-by Sun YangKai <[email protected]>--- fs/btrfs/block-group.c | 2 +- fs/btrfs/block-group.h | 7 ++++++- fs/btrfs/space-info.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)fs/btrfs/block-group.c +1
-1@@ -3923,7 +3923,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, old_val += num_bytes; cache->used = old_val; cache->reserved -= num_bytes; - cache->reclaim_mark =0 ; + cache->reclaim_mark = false; space_info->bytes_reserved -= num_bytes; space_info->bytes_used += num_bytes; space_info->disk_used += num_bytes * factor;fs/btrfs/block-group.h +0
-0
fs/btrfs/block-group.h struct btrfs_block_group { · line 268
Quoted 6 lines
fs/btrfs/block-group.h +3
-0@@ -263,6 +263,12 @@ struct btrfs_block_group { enum btrfs_block_group_size_class size_class:8; +/* +* Mark this blockgroup is not used for allocation +* between two reclaim sweeps.
nit: this grammar doesn't parse great to me. Maybe drop "Mark"? or change it to "We identified this for reclaim on a previous pass, so it stably needs reclaim across passes" or something like that.
Quoted 30 lines
fs/btrfs/block-group.h +3
-1+*/ +bool reclaim_mark; +/* * Number of extents in this block group used for swap files. * All accesses protected by the spinlock 'lock'. @@ -281,7 +287,6 @@ struct btrfs_block_group {struct list_head active_bg_list;struct work_struct zone_finish_work;struct extent_buffer *last_eb; -u64 reclaim_mark; };static inline u64 btrfs_block_group_end (const struct btrfs_block_group *block_group)fs/btrfs/space-info.c +1
-1@@ -2156,7 +2156,7 @@ static bool do_reclaim_sweep(struct btrfs_space_info *space_info, int raid) will_reclaim = true; reclaim = true; } - bg->reclaim_mark++; + bg->reclaim_mark = true;spin_unlock (&bg->lock);if (reclaim)btrfs_mark_bg_to_reclaim (bg);Signature · 1 line
2.54.0
Quoted 42 lines · Boris Burkov
Quoted 9 lines · Sun YangKai
The
reclaim_markfield in structbtrfs_block_groupwas a u64 that was incremented when marking block groups for reclaim during sweeping, but the actual counter value was never used - only the zero/non-zero state mattered for determining if a block group needed reclaim.Convert it to a bool to properly reflect its usage and reduce memory footprint by 8 bytes. Update assignments to use true/false instead of increment and zero.
LGTM, thanks.
Reviewed-by Boris Burkov <[email protected]>Quoted 28 lines
Signed-off-by Sun YangKai <[email protected]>--- fs/btrfs/block-group.c | 2 +- fs/btrfs/block-group.h | 7 ++++++- fs/btrfs/space-info.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)fs/btrfs/block-group.c +1
-1@@ -3923,7 +3923,7 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans, old_val += num_bytes; cache->used = old_val; cache->reserved -= num_bytes; - cache->reclaim_mark =0 ; + cache->reclaim_mark = false; space_info->bytes_reserved -= num_bytes; space_info->bytes_used += num_bytes; space_info->disk_used += num_bytes * factor;fs/btrfs/block-group.h +0
-0@@ -263,6 +263,12 @@ struct btrfs_block_group { enum btrfs_block_group_size_class size_class:8;
Quoted 7 lines
fs/btrfs/block-group.h struct btrfs_block_group { · line 268
Quoted 3 lines
fs/btrfs/block-group.h +3
-0+/* +* Mark this blockgroup is not used for allocation +* between two reclaim sweeps. nit: this grammar doesn't parse great to me. Maybe drop "Mark"? or change it to "We identified this for reclaim on a previous pass, so it stably needs reclaim across passes" or something like that.
I also think this comment should be polished but have no idea. Your nit helps a lot. How about this:
Tracks whether this blockgroup has been idle during the previous periodic sweep cycle. It is set to false on allocation, and set to true by the periodic sweep upon first pass. If found true on a subsequent scan, the blockgroup is eligible for reclamation.
Quoted 30 lines
Quoted 30 lines
fs/btrfs/block-group.h +3
-1+*/ +bool reclaim_mark; +/* * Number of extents in this block group used for swap files. * All accesses protected by the spinlock 'lock'. @@ -281,7 +287,6 @@ struct btrfs_block_group {struct list_head active_bg_list;struct work_struct zone_finish_work;struct extent_buffer *last_eb; -u64 reclaim_mark; };static inline u64 btrfs_block_group_end (const struct btrfs_block_group *block_group)fs/btrfs/space-info.c +1
-1@@ -2156,7 +2156,7 @@ static bool do_reclaim_sweep(struct btrfs_space_info *space_info, int raid) will_reclaim = true; reclaim = true; } - bg->reclaim_mark++; + bg->reclaim_mark = true;spin_unlock (&bg->lock);if (reclaim)btrfs_mark_bg_to_reclaim (bg);Signature · 1 line
2.54.0
Quoted 10 lines · Sun YangKai
The
reclaim_markfield in structbtrfs_block_groupwas a u64 that was incremented when marking block groups for reclaim during sweeping, but the actual counter value was never used - only the zero/non-zero state mattered for determining if a block group needed reclaim.Convert it to a bool to properly reflect its usage and reduce memory footprint by 8 bytes. Update assignments to use true/false instead of increment and zero.
Signed-off-by Sun YangKai <[email protected]>
Added to for-next, with updated comment. Thanks.