On Mon, Mar 30, 2015 at 8:12 PM, Jeff Mahoney <jeffm@xxxxxxxx> wrote:
> 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@xxxxxxxx>
> ---
> 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;
> + }
> +
Jeff we can't do a discard here, specially if unpin ==
fs_info->pinned_extents, as explained in:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=678886bdc6378c1cbd5072da2c5a3035000214e3
> 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;
> + }
> + }
This isn't safe either for the similar reason as above. For example,
transaction N running, metadata bg X becomes empty and it's added to
fs_info->unused_bgs, cleaner kthread running and gets bg X from
fs_info->unused_bgs (running btrfs_delete_unused_bgs), does the
discard, power failure, reboot, superblock points to metadata extents
in the physical location of bg X that are now full of zeroes.
thanks
> 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
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html