Add stripes filter
diff mbox

Message ID 1443463025.16163.6.camel@system.is
State New
Headers show

Commit Message

Gabríel Arthúr Pétursson Sept. 28, 2015, 5:57 p.m. UTC
Hello everyone!

The attached patches to linux and btrfs-progs add support for filtering
based on the number of strips in a block when balancing.

This is my first attempt at kernel development, I'd love if you could
please point out any mistakes that I've made.

Thanks,
Gabríel

P.S. I could not figure out how to subscribe to this mailing list, so
please remember to include me in your replies.

Comments

Omar Sandoval Sept. 28, 2015, 9:11 p.m. UTC | #1
On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> Hello everyone!
> 
> The attached patches to linux and btrfs-progs add support for filtering
> based on the number of strips in a block when balancing.
> 
> This is my first attempt at kernel development, I'd love if you could
> please point out any mistakes that I've made.
> 
> Thanks,
> Gabríel
> 
> P.S. I could not figure out how to subscribe to this mailing list, so
> please remember to include me in your replies.

Hi, Gabríel,

To subscribe to the mailing list, all you have to do is email
majordomo@vger.kernel.org with "subscribe linux-btrfs" in the body (see
http://vger.kernel.org/vger-lists.html#linux-btrfs). Also, be sure to
take a look at https://btrfs.wiki.kernel.org/index.php/Developer%27s_FAQ
and https://www.kernel.org/doc/Documentation/SubmittingPatches
for instructions on how to send in patches. The biggest takeaway is to
use `git format-patch` and `git send-email`.

Thanks!
David Sterba Sept. 29, 2015, noon UTC | #2
On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> The attached patches to linux and btrfs-progs add support for filtering
> based on the number of strips in a block when balancing.

What usecase do you want to address? As I understand it, this would help
the raid56 rebalancing to process only blockgroups that are not spread
accross enough devices.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Sept. 29, 2015, 12:10 p.m. UTC | #3
On 2015-09-29 08:00, David Sterba wrote:
> On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
>> The attached patches to linux and btrfs-progs add support for filtering
>> based on the number of strips in a block when balancing.
>
> What usecase do you want to address? As I understand it, this would help
> the raid56 rebalancing to process only blockgroups that are not spread
> accross enough devices.
This could also be helpful when reshaping a raid10 or raid0 setup.
Hugo Mills Sept. 29, 2015, 12:21 p.m. UTC | #4
On Tue, Sep 29, 2015 at 08:10:19AM -0400, Austin S Hemmelgarn wrote:
> On 2015-09-29 08:00, David Sterba wrote:
> >On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> >>The attached patches to linux and btrfs-progs add support for filtering
> >>based on the number of strips in a block when balancing.
> >
> >What usecase do you want to address? As I understand it, this would help
> >the raid56 rebalancing to process only blockgroups that are not spread
> >accross enough devices.

   Exactly. Last week, I was trying to help Gabríel on IRC with a
close-to-full filesystem balance it to add some new devices in a
parity RAID configuration. He'd added the devices and balanced, but
the usage was unequal across the devices. The only way I could think
of dealing with it with the current tools was either to do a full
balance repeatedly until it worked itself out, or to delve into the
metadata with btrfs-debug-tree, and balance selected block groups
individually.

   I whinged that we needed a filter to pick just the block groups
that weren't "as full as possible", and Gabríel picked up the idea and
ran with it.

> This could also be helpful when reshaping a raid10 or raid0 setup.

   Yes, although ultimately less important in most cases, I think,
because you don't lose space by reducing the number of devices in a
block group for those. There are some corner cases where you could end
up losing space by having one (for RAID-0) or up to three (for
RAID-10) devices with more space left than the rest.

   Hugo.
David Sterba Sept. 30, 2015, 3:16 p.m. UTC | #5
On Tue, Sep 29, 2015 at 08:10:19AM -0400, Austin S Hemmelgarn wrote:
> On 2015-09-29 08:00, David Sterba wrote:
> > On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> >> The attached patches to linux and btrfs-progs add support for filtering
> >> based on the number of strips in a block when balancing.
> >
> > What usecase do you want to address? As I understand it, this would help
> > the raid56 rebalancing to process only blockgroups that are not spread
> > accross enough devices.
> This could also be helpful when reshaping a raid10 or raid0 setup.

Right, I forgot to mention it, I should have said "any raid profile that
uses stripes".
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Sept. 30, 2015, 3:28 p.m. UTC | #6
On Tue, Sep 29, 2015 at 12:21:39PM +0000, Hugo Mills wrote:
> On Tue, Sep 29, 2015 at 08:10:19AM -0400, Austin S Hemmelgarn wrote:
> > On 2015-09-29 08:00, David Sterba wrote:
> > >On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> > >>The attached patches to linux and btrfs-progs add support for filtering
> > >>based on the number of strips in a block when balancing.
> > >
> > >What usecase do you want to address? As I understand it, this would help
> > >the raid56 rebalancing to process only blockgroups that are not spread
> > >accross enough devices.
> 
>    Exactly. Last week, I was trying to help Gabríel on IRC with a
> close-to-full filesystem balance it to add some new devices in a
> parity RAID configuration. He'd added the devices and balanced, but
> the usage was unequal across the devices. The only way I could think
> of dealing with it with the current tools was either to do a full
> balance repeatedly until it worked itself out, or to delve into the
> metadata with btrfs-debug-tree, and balance selected block groups
> individually.
> 
>    I whinged that we needed a filter to pick just the block groups
> that weren't "as full as possible", and Gabríel picked up the idea and
> ran with it.

That's great, thanks. The stripe filters are really missing.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Oct. 12, 2015, 2:10 p.m. UTC | #7
On Mon, Sep 28, 2015 at 05:57:05PM +0000, Gabríel Arthúr Pétursson wrote:
> The attached patches to linux and btrfs-progs add support for filtering
> based on the number of strips in a block when balancing.

FYI, I'm going to make the fixups myself as they're mostly cosmetic and
prepare this patch for 4.4 merge window, together with the extension to
the 'limit' filter I mentioned.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 938efe3..78573e5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -849,7 +849,11 @@  struct btrfs_disk_balance_args {
 	/* BTRFS_BALANCE_ARGS_LIMIT value */
 	__le64 limit;
 
-	__le64 unused[7];
+	/* btrfs stripes filter */
+	__le64 sstart;
+	__le64 send;
+
+	__le64 unused[5];
 } __attribute__ ((__packed__));
 
 /*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 6fc73586..dc65fbb 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3170,6 +3170,18 @@  static int chunk_vrange_filter(struct extent_buffer *leaf,
 	return 1;
 }
 
+static int chunk_stripes_filter(struct extent_buffer *leaf,
+			       struct btrfs_chunk *chunk,
+			       struct btrfs_balance_args *bargs)
+{
+	int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
+
+	if (bargs->sstart <= num_stripes && num_stripes <= bargs->send)
+		return 0;
+
+	return 1;
+}
+
 static int chunk_soft_convert_filter(u64 chunk_type,
 				     struct btrfs_balance_args *bargs)
 {
@@ -3236,6 +3248,12 @@  static int should_balance_chunk(struct btrfs_root *root,
 		return 0;
 	}
 
+	/* stripes filter */
+	if ((bargs->flags & BTRFS_BALANCE_ARGS_STRIPES) &&
+	    chunk_stripes_filter(leaf, chunk, bargs)) {
+		return 0;
+	}
+
 	/* soft profile changing mode */
 	if ((bargs->flags & BTRFS_BALANCE_ARGS_SOFT) &&
 	    chunk_soft_convert_filter(chunk_type, bargs)) {
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2ca784a..fb6b89a 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -375,6 +375,7 @@  struct map_lookup {
 #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
+#define BTRFS_BALANCE_ARGS_STRIPES	(1ULL << 6)
 
 /*
  * Profile changing flags.  When SOFT is set we won't relocate chunk if
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index b6dec05..a7819d0 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -218,7 +218,11 @@  struct btrfs_balance_args {
 	__u64 flags;
 
 	__u64 limit;		/* limit number of processed chunks */
-	__u64 unused[7];
+
+	__u64 sstart;
+	__u64 send;
+
+	__u64 unused[5];
 } __attribute__ ((__packed__));
 
 /* report balance progress to userspace */