Skip to contentSkip to conversation

btrfs: some cleanups related to io trees

PATCH In review [email protected] 3 participants 6 messages Mar 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover btrfs: some cleanups related to io trees

From: Filipe Manana <[email protected]>

Remove some no longer used/needed code related to io trees. Details in the change logs.

Filipe Manana (3):
btrfs: remove leftover EXTENT_UPTODATE clear from an inode's io_tree
btrfs: stop searching for EXTENT_DIRTY bit in the excluded extents io tree
btrfs: remove EXTENT_UPTODATE io tree flag

 fs/btrfs/block-group.c           |  9 ++++-----
 fs/btrfs/extent-io-tree.h        |  8 --------
 fs/btrfs/inode.c                 | 22 ++++++++++------------
 fs/btrfs/relocation.c            |  3 ---
 fs/btrfs/tests/extent-io-tests.c |  1 -
 fs/btrfs/tests/inode-tests.c     | 12 ++++--------
 include/trace/events/btrfs.h     |  1 -
 7 files changed, 18 insertions(+), 38 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/3 btrfs: remove leftover EXTENT_UPTODATE clear from an inode's io_tree

From: Filipe Manana <[email protected]>

After commit 52b029f42751 ("btrfs: remove unnecessary EXTENT_UPTODATE state in buffered I/O path") we never set EXTENT_UPTODATE in an inode's io_tree anymore, but we still have some code attempting to clear that bit from an inode's io_tree. Remove that code as it doesn't do anything anymore. The sole use of the EXTENT_UPTODATE bit is for the excluded extents io_tree (fs_info->excluded_extents), which is used to track the locations of super blocks, so that their ranges are neved marked as free, making them unavailable for extent allocation.

---
 fs/btrfs/extent-io-tree.h    |  7 -------
 fs/btrfs/inode.c             | 22 ++++++++++------------
 fs/btrfs/relocation.c        |  3 ---
 fs/btrfs/tests/inode-tests.c | 12 ++++--------
 4 files changed, 14 insertions(+), 30 deletions(-)
fs/btrfs/extent-io-tree.h +0 -7
index cf83e094b00e..ac1a59bd2f95 100644
@@ -203,13 +203,6 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
 int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 		   u32 bits, struct extent_state **cached_state);
 
-static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
-		u64 end, struct extent_state **cached_state)
-{
-	return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE,
-				  cached_state, NULL);
-}
-
 static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
 				     u64 end, struct extent_state **cached)
 {
fs/btrfs/inode.c +10 -12
index 469b3fd64f17..95d29b9282ba 100644
@@ -3237,8 +3237,6 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 		btrfs_end_transaction(trans);
 
 	if (ret || truncated) {
-		u64 unwritten_start = start;
-
 		/*
 		 * If we failed to finish this ordered extent for any reason we
 		 * need to make sure BTRFS_ORDERED_IOERR is set on the ordered
@@ -3250,10 +3248,6 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 		if (ret)
 			btrfs_mark_ordered_extent_error(ordered_extent);
 
-		if (truncated)
-			unwritten_start += logical_len;
-		clear_extent_uptodate(io_tree, unwritten_start, end, NULL);
-
 		/*
 		 * Drop extent maps for the part of the extent we didn't write.
 		 *
@@ -3268,9 +3262,15 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
 		 * we don't mess with the extent map tree in the NOCOW case, but
 		 * for now simply skip this if we are the free space inode.
 		 */
-		if (!btrfs_is_free_space_inode(inode))
+		if (!btrfs_is_free_space_inode(inode)) {
+			u64 unwritten_start = start;
+
+			if (truncated)
+				unwritten_start += logical_len;
+
 			btrfs_drop_extent_map_range(inode, unwritten_start,
 						    end, false);
+		}
 
 		/*
 		 * If the ordered extent had an IOERR or something else went
@@ -7483,12 +7483,10 @@ static void btrfs_invalidate_folio(struct folio *folio, size_t offset,
 		 *    Since the IO will never happen for this page.
 		 */
 		btrfs_qgroup_free_data(inode, NULL, cur, range_end + 1 - cur, NULL);
-		if (!inode_evicting) {
+		if (!inode_evicting)
 			clear_extent_bit(tree, cur, range_end, EXTENT_LOCKED |
-				 EXTENT_DELALLOC | EXTENT_UPTODATE |
-				 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG |
-				 extra_flags, &cached_state);
-		}
+					 EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING |
+					 EXTENT_DEFRAG | extra_flags, &cached_state);
 		cur = range_end + 1;
 	}
 	/*
fs/btrfs/relocation.c +0 -3
index f948f4f6431c..ddcd98c59d33 100644
@@ -2706,9 +2706,6 @@ static noinline_for_stack int prealloc_file_extent_cluster(struct reloc_control
 		if (ret < 0)
 			return ret;
 
-		clear_extent_bits(&inode->io_tree, i_size,
-				  round_up(i_size, PAGE_SIZE) - 1,
-				  EXTENT_UPTODATE);
 		folio = filemap_lock_folio(mapping, i_size >> PAGE_SHIFT);
 		/*
 		 * If page is freed we don't need to do anything then, as we
fs/btrfs/tests/inode-tests.c +4 -8
index 3ea3bc2225fe..8142a84129b6 100644
@@ -952,8 +952,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 	ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
 			       BTRFS_MAX_EXTENT_SIZE >> 1,
 			       (BTRFS_MAX_EXTENT_SIZE >> 1) + sectorsize - 1,
-			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
-			       EXTENT_UPTODATE, NULL);
+			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW, NULL);
 	if (ret) {
 		test_err("clear_extent_bit returned %d", ret);
 		goto out;
@@ -1020,8 +1019,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 	ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
 			       BTRFS_MAX_EXTENT_SIZE + sectorsize,
 			       BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1,
-			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
-			       EXTENT_UPTODATE, NULL);
+			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW, NULL);
 	if (ret) {
 		test_err("clear_extent_bit returned %d", ret);
 		goto out;
@@ -1053,8 +1051,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 
 	/* Empty */
 	ret = clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
-			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
-			       EXTENT_UPTODATE, NULL);
+			       EXTENT_DELALLOC | EXTENT_DELALLOC_NEW, NULL);
 	if (ret) {
 		test_err("clear_extent_bit returned %d", ret);
 		goto out;
@@ -1069,8 +1066,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 out:
 	if (ret)
 		clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
-				 EXTENT_DELALLOC | EXTENT_DELALLOC_NEW |
-				 EXTENT_UPTODATE, NULL);
+				 EXTENT_DELALLOC | EXTENT_DELALLOC_NEW, NULL);
 	iput(inode);
 	btrfs_free_dummy_root(root);
 	btrfs_free_dummy_fs_info(fs_info);
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/3 btrfs: stop searching for EXTENT_DIRTY bit in the excluded extents io tree

In reply to [email protected]

From: Filipe Manana <[email protected]>

At btrfs_add_new_free_space() we keep searching for ranges in the excluded extents io tree that have the EXTENT_DIRTY bit set, however we never ever set that bit for ranges in that tree. That is a leftover from when that function used the global freed extents trees (fs_info->freed_extents[2]), where we used both the EXTENT_DIRTY and EXTENT_UPTODATE bits, but those trees are gone with commit fe119a6eeb67 ("btrfs: switch to per-transaction pinned extents"), which introduced the fs_info->excluded_extents io tree, where only EXTENT_UPTODATE is set.

So remove the EXTENT_DIRTY bit search at btrfs_add_new_free_space().

---
 fs/btrfs/block-group.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/block-group.c +1 -2
index a8129f1ce78c..8a02375f27e8 100644
@@ -527,8 +527,7 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start,
 	while (start < end) {
 		if (!find_first_extent_bit(&info->excluded_extents, start,
 					   &extent_start, &extent_end,
-					   EXTENT_DIRTY | EXTENT_UPTODATE,
-					   NULL))
+					   EXTENT_UPTODATE, NULL))
 			break;
 
 		if (extent_start <= start) {
Signature · 1 line
2.45.2
#3 lore raw

PATCH 3/3 btrfs: remove EXTENT_UPTODATE io tree flag

In reply to [email protected]

From: Filipe Manana <[email protected]>

The EXTENT_UPTODATE io tree flag is now used only to mark ranges in the fs_info->excluded_extents as used by super blocks and not available for extent allocation (to prevent adding those ranges as free space in the in memory space caches). As we can use any flag for that purpose, and we are using EXTENT_DIRTY for the pinned extents io tree for example, remove the EXTENT_UPTODATE flag and use instead EXTENT_DIRTY for the excluded extents io tree.

---
 fs/btrfs/block-group.c           | 8 ++++----
 fs/btrfs/extent-io-tree.h        | 1 -
 fs/btrfs/tests/extent-io-tests.c | 1 -
 include/trace/events/btrfs.h     | 1 -
 4 files changed, 4 insertions(+), 7 deletions(-)
fs/btrfs/block-group.c +4 -4
index 8a02375f27e8..a38578c60f34 100644
@@ -527,7 +527,7 @@ int btrfs_add_new_free_space(struct btrfs_block_group *block_group, u64 start,
 	while (start < end) {
 		if (!find_first_extent_bit(&info->excluded_extents, start,
 					   &extent_start, &extent_end,
-					   EXTENT_UPTODATE, NULL))
+					   EXTENT_DIRTY, NULL))
 			break;
 
 		if (extent_start <= start) {
@@ -834,7 +834,7 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
 static inline void btrfs_free_excluded_extents(const struct btrfs_block_group *bg)
 {
 	clear_extent_bits(&bg->fs_info->excluded_extents, bg->start,
-			  bg->start + bg->length - 1, EXTENT_UPTODATE);
+			  bg->start + bg->length - 1, EXTENT_DIRTY);
 }
 
 static noinline void caching_thread(struct btrfs_work *work)
@@ -2219,7 +2219,7 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)
 		cache->bytes_super += stripe_len;
 		ret = set_extent_bit(&fs_info->excluded_extents, cache->start,
 				     cache->start + stripe_len - 1,
-				     EXTENT_UPTODATE, NULL);
+				     EXTENT_DIRTY, NULL);
 		if (ret)
 			return ret;
 	}
@@ -2247,7 +2247,7 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)
 			cache->bytes_super += len;
 			ret = set_extent_bit(&fs_info->excluded_extents, logical[nr],
 					     logical[nr] + len - 1,
-					     EXTENT_UPTODATE, NULL);
+					     EXTENT_DIRTY, NULL);
 			if (ret) {
 				kfree(logical);
 				return ret;
fs/btrfs/extent-io-tree.h +0 -1
index ac1a59bd2f95..6dfe8b097d93 100644
@@ -17,7 +17,6 @@ struct btrfs_inode;
 /* Bits for the extent state */
 enum {
 	ENUM_BIT(EXTENT_DIRTY),
-	ENUM_BIT(EXTENT_UPTODATE),
 	ENUM_BIT(EXTENT_LOCKED),
 	ENUM_BIT(EXTENT_DIO_LOCKED),
 	ENUM_BIT(EXTENT_NEW),
fs/btrfs/tests/extent-io-tests.c +0 -1
index 74aca7180a5a..8773758a8cc7 100644
@@ -74,7 +74,6 @@ static void extent_flag_to_str(const struct extent_state *state, char *dest)
 
 	dest[0] = 0;
 	PRINT_ONE_FLAG(state, dest, cur, DIRTY);
-	PRINT_ONE_FLAG(state, dest, cur, UPTODATE);
 	PRINT_ONE_FLAG(state, dest, cur, LOCKED);
 	PRINT_ONE_FLAG(state, dest, cur, NEW);
 	PRINT_ONE_FLAG(state, dest, cur, DELALLOC);
include/trace/events/btrfs.h +0 -1
index 549ab3b41961..60f279181ae2 100644
@@ -143,7 +143,6 @@ FLUSH_STATES
 
 #define EXTENT_FLAGS						\
 	{ EXTENT_DIRTY,			"DIRTY"},		\
-	{ EXTENT_UPTODATE,		"UPTODATE"},		\
 	{ EXTENT_LOCKED,		"LOCKED"},		\
 	{ EXTENT_NEW,			"NEW"},			\
 	{ EXTENT_DELALLOC,		"DELALLOC"},		\
Signature · 1 line
2.45.2
Reviewed-by on the v1 series
#4 lore raw
In reply to [email protected]
Quoted 4 lines · On Fri, Mar 28, 2025 at 02:24:01PM +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

Remove some no longer used/needed code related to io trees. Details in the change logs.

Thanks,
Boris

Quoted 18 lines

Filipe Manana (3):
btrfs: remove leftover EXTENT_UPTODATE clear from an inode's io_tree
btrfs: stop searching for EXTENT_DIRTY bit in the excluded extents io tree
btrfs: remove EXTENT_UPTODATE io tree flag

 fs/btrfs/block-group.c           |  9 ++++-----
 fs/btrfs/extent-io-tree.h        |  8 --------
 fs/btrfs/inode.c                 | 22 ++++++++++------------
 fs/btrfs/relocation.c            |  3 ---
 fs/btrfs/tests/extent-io-tests.c |  1 -
 fs/btrfs/tests/inode-tests.c     | 12 ++++--------
 include/trace/events/btrfs.h     |  1 -
 7 files changed, 18 insertions(+), 38 deletions(-)
Signature · 1 line
2.45.2
Reviewed-by on the v1 series
#5 lore raw
In reply to [email protected]
Quoted 9 lines · On Fri, Mar 28, 2025 at 02:24:01PM +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

Remove some no longer used/needed code related to io trees. Details in the change logs.

Filipe Manana (3):
btrfs: remove leftover EXTENT_UPTODATE clear from an inode's io_tree
btrfs: stop searching for EXTENT_DIRTY bit in the excluded extents io tree
btrfs: remove EXTENT_UPTODATE io tree flag