All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: [PATCH] btrfs: add missing discards when unpinning extents with, -o discard
Date: Mon, 30 Mar 2015 15:12:34 -0400	[thread overview]
Message-ID: <5519A022.9090804@suse.com> (raw)

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

             reply	other threads:[~2015-03-30 19:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30 19:12 Jeff Mahoney [this message]
2015-03-30 19:29 ` [PATCH] btrfs: add missing discards when unpinning extents with, -o discard Filipe David Manana
2015-03-30 21:36   ` Jeff Mahoney
2015-08-21 19:25 ` Jun He

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=5519A022.9090804@suse.com \
    --to=jeffm@suse.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 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.