[v2,2/4] btrfs: relocation: Check cancel request after each data page read
diff mbox series

Message ID 20200211053729.20807-3-wqu@suse.com
State New
Headers show
Series
  • btrfs: Make balance cancelling response faster
Related show

Commit Message

Qu Wenruo Feb. 11, 2020, 5:37 a.m. UTC
When relocating a data extents with large large data extents, we spend
most of our time in relocate_file_extent_cluster() at stage "moving data
extents":
 1)               |  btrfs_relocate_block_group [btrfs]() {
 1)               |    relocate_file_extent_cluster [btrfs]() {
 1) $ 6586769 us  |    }
 1) + 18.260 us   |    relocate_file_extent_cluster [btrfs]();
 1) + 15.770 us   |    relocate_file_extent_cluster [btrfs]();
 1) $ 8916340 us  |  }
 1)               |  btrfs_relocate_block_group [btrfs]() {
 1)               |    relocate_file_extent_cluster [btrfs]() {
 1) $ 11611586 us |    }
 1) + 16.930 us   |    relocate_file_extent_cluster [btrfs]();
 1) + 15.870 us   |    relocate_file_extent_cluster [btrfs]();
 1) $ 14986130 us |  }

So to make data relocation cancelling quicker, here add extra balance
cancelling check after each page read in relocate_file_extent_cluster().

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/relocation.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Josef Bacik Feb. 13, 2020, 8:03 p.m. UTC | #1
On 2/11/20 12:37 AM, Qu Wenruo wrote:
> When relocating a data extents with large large data extents, we spend
> most of our time in relocate_file_extent_cluster() at stage "moving data
> extents":
>   1)               |  btrfs_relocate_block_group [btrfs]() {
>   1)               |    relocate_file_extent_cluster [btrfs]() {
>   1) $ 6586769 us  |    }
>   1) + 18.260 us   |    relocate_file_extent_cluster [btrfs]();
>   1) + 15.770 us   |    relocate_file_extent_cluster [btrfs]();
>   1) $ 8916340 us  |  }
>   1)               |  btrfs_relocate_block_group [btrfs]() {
>   1)               |    relocate_file_extent_cluster [btrfs]() {
>   1) $ 11611586 us |    }
>   1) + 16.930 us   |    relocate_file_extent_cluster [btrfs]();
>   1) + 15.870 us   |    relocate_file_extent_cluster [btrfs]();
>   1) $ 14986130 us |  }
> 
> So to make data relocation cancelling quicker, here add extra balance
> cancelling check after each page read in relocate_file_extent_cluster().
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

If you respin, can you note that with this cancellation we'll break out and 
merge the reloc roots, its not like everything will just be left over to be 
completed at the next mount.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
David Sterba Feb. 14, 2020, 5:10 p.m. UTC | #2
On Thu, Feb 13, 2020 at 03:03:55PM -0500, Josef Bacik wrote:
> On 2/11/20 12:37 AM, Qu Wenruo wrote:
> > When relocating a data extents with large large data extents, we spend
> > most of our time in relocate_file_extent_cluster() at stage "moving data
> > extents":
> >   1)               |  btrfs_relocate_block_group [btrfs]() {
> >   1)               |    relocate_file_extent_cluster [btrfs]() {
> >   1) $ 6586769 us  |    }
> >   1) + 18.260 us   |    relocate_file_extent_cluster [btrfs]();
> >   1) + 15.770 us   |    relocate_file_extent_cluster [btrfs]();
> >   1) $ 8916340 us  |  }
> >   1)               |  btrfs_relocate_block_group [btrfs]() {
> >   1)               |    relocate_file_extent_cluster [btrfs]() {
> >   1) $ 11611586 us |    }
> >   1) + 16.930 us   |    relocate_file_extent_cluster [btrfs]();
> >   1) + 15.870 us   |    relocate_file_extent_cluster [btrfs]();
> >   1) $ 14986130 us |  }
> > 
> > So to make data relocation cancelling quicker, here add extra balance
> > cancelling check after each page read in relocate_file_extent_cluster().
> > 
> > Signed-off-by: Qu Wenruo <wqu@suse.com>
> 
> If you respin, can you note that with this cancellation we'll break out and 
> merge the reloc roots, its not like everything will just be left over to be 
> completed at the next mount.

Yes that's what I miss here too and asked about it in v1 thread. No
resend is needed, I can update changelog if the new text is sent to me.

Patch
diff mbox series

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 475479d50cc3..23b279872641 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3396,6 +3396,10 @@  static int relocate_file_extent_cluster(struct inode *inode,
 		btrfs_delalloc_release_extents(BTRFS_I(inode), PAGE_SIZE);
 		balance_dirty_pages_ratelimited(inode->i_mapping);
 		btrfs_throttle(fs_info);
+		if (should_cancel_balance(fs_info)) {
+			ret = -ECANCELED;
+			goto out;
+		}
 	}
 	WARN_ON(nr != cluster->nr);
 out: