Skip to contentSkip to conversation

Btrfs: Batched discard support for btrfs

PATCH New Li Dongyang 1 participant 1 message Mar 3, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Btrfs: Batched discard support for btrfs

Here is V3, sorry for sending the patch out without checking the style. Tested with xfstests 251, we are still only trimming the first stripe of a free extent from RAID0/1/10/DUP, but I think we are done with FITRIM, the problem could be addressed by loop inside btrfs_discard_extent() and trim the extent stripe by stripe, or make the free extent be mapped as a whole, and that could been done in another patch, Thanks.

---
Changelog V3:
*fix style problems.
*rebase to 2.6.38-rc7.
Changelog V2:
*Check if we have devices support trim before trying to trim the fs, also adjust
minlen according to the discard_granularity.
*Update reserved extent calculations in btrfs_trim_block_group().
*Call cond_resched() without checking need_resched()
*Use bitmap_clear_bits() and unlink_free_space() instead of btrfs_remove_free_space(),
so we won't search the same extent for twice.
*Try harder in btrfs_discard_extent(), now we won't report errors
if it's not a EOPNOTSUPP.
*make sure the block group is cached before trimming it,or we'll see an empty caching
tree if the block group is not cached.
*Minor return value fix in btrfs_discard_block_group().

---
 fs/btrfs/ctree.h            |    5 ++-
 fs/btrfs/disk-io.c          |    5 ++-
 fs/btrfs/extent-tree.c      |  103 +++++++++++++++++++++++++++++++++----------
 fs/btrfs/free-space-cache.c |   92 ++++++++++++++++++++++++++++++++++++++
 fs/btrfs/free-space-cache.h |    2 +
 fs/btrfs/ioctl.c            |   46 +++++++++++++++++++
 6 files changed, 227 insertions(+), 26 deletions(-)
fs/btrfs/ctree.h +4 -1
index 6f820fa..9511af9 100644
@@ -2148,6 +2148,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
 		      u64 root_objectid, u64 owner, u64 offset);
 
 int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len);
+int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
+				u64 num_bytes, int reserve, int sinfo);
 int btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
 				struct btrfs_root *root);
 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
@@ -2218,9 +2220,10 @@ u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
 int btrfs_error_unpin_extent_range(struct btrfs_root *root,
 				   u64 start, u64 end);
 int btrfs_error_discard_extent(struct btrfs_root *root, u64 bytenr,
-			       u64 num_bytes);
+			       u64 num_bytes, u64 *actual_bytes);
 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans,
 			    struct btrfs_root *root, u64 type);
+int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
 
 /* ctree.c */
 int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
fs/btrfs/disk-io.c +4 -1
index e1aa8d6..bcb9451 100644
@@ -2947,7 +2947,10 @@ static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
 			break;
 
 		/* opt_discard */
-		ret = btrfs_error_discard_extent(root, start, end + 1 - start);
+		if (btrfs_test_opt(root, DISCARD))
+			ret = btrfs_error_discard_extent(root, start,
+							 end + 1 - start,
+							 NULL);
 
 		clear_extent_dirty(unpin, start, end, GFP_NOFS);
 		btrfs_error_unpin_extent_range(root, start, end);
fs/btrfs/extent-tree.c +79 -24

187 lines not on this page · raw message

fs/btrfs/free-space-cache.c +92 -0

95 lines not on this page · raw message

fs/btrfs/free-space-cache.h +2 -0
index e49ca5c..65c3b93 100644
@@ -68,4 +68,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
 int btrfs_return_cluster_to_free_space(
 			       struct btrfs_block_group_cache *block_group,
 			       struct btrfs_free_cluster *cluster);
+int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group,
+			   u64 *trimmed, u64 start, u64 end, u64 minlen);
 #endif
fs/btrfs/ioctl.c +46 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.1