All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: add missing discards when unpinning extents with, -o discard
@ 2015-03-30 19:12 Jeff Mahoney
  2015-03-30 19:29 ` Filipe David Manana
  2015-08-21 19:25 ` Jun He
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Mahoney @ 2015-03-30 19:12 UTC (permalink / raw)
  To: linux-btrfs

The block group removal patch adds an alternate path to forget extents
other than btrfs_finish_extent_commit. As a result, any extents that would
be freed when the block group is removed aren't discarded. In my
test run, with a large copy of mixed sized files followed by removal, it
left nearly 2/3 of extents undiscarded.

As part of the extent removal review, I also added the discard call to
btrfs_destroy_pinned_extent.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/disk-io.c     | 7 +++++++
 fs/btrfs/extent-tree.c | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 639f266..f7dfcf8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4167,6 +4167,13 @@ again:
 		if (ret)
 			break;
 
+		if (btrfs_test_opt(root, DISCARD)) {
+			ret = btrfs_discard_extent(root, start,
+						   end + 1 - start, NULL);
+			if (ret)
+				break;
+		}
+
 		clear_extent_dirty(unpin, start, end, GFP_NOFS);
 		btrfs_error_unpin_extent_range(root, start, end);
 		cond_resched();
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 0bf45b8..6a7ff46 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -9630,6 +9630,15 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
 		 * a BUG_ON() at btrfs_unpin_extent_range().
 		 */
 		mutex_lock(&fs_info->unused_bg_unpin_mutex);
+		if (btrfs_test_opt(root, DISCARD)) {
+			ret = btrfs_discard_extent(root, start, end + 1 - start,
+						   NULL);
+			if (ret) {
+				mutex_unlock(&fs_info->unused_bg_unpin_mutex);
+				btrfs_set_block_group_rw(root, block_group);
+				goto end_trans;
+			}
+		}
 		ret = clear_extent_bits(&fs_info->freed_extents[0], start, end,
 				  EXTENT_DIRTY, GFP_NOFS);
 		if (ret) {
-- 
1.8.5.6


-- 
Jeff Mahoney
SUSE Labs

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

end of thread, other threads:[~2015-08-21 19:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-30 19:12 [PATCH] btrfs: add missing discards when unpinning extents with, -o discard Jeff Mahoney
2015-03-30 19:29 ` Filipe David Manana
2015-03-30 21:36   ` Jeff Mahoney
2015-08-21 19:25 ` Jun He

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.