Balance filters: stripes, enhanced limit
David Sterba
maintainercover Balance filters: stripes, enhanced limit
Update to balance filters, intended fro 4.4:
* new 'stripes=<range>' - process only stripes that cross given number of devices, specified by a range
* updated 'limit=<range>' - previously a single number was accepted, it's a range so now we can specify a minimum number of chunks to process
There will be more documentation about the use in the btrfs-progs patches, the kernel side just applies the ranges. The update to 'limit' is backward compatible, reuses the previous struct member.
Can be pulled from
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git dev/balance-filters
I'm finalizing the progs patches and haven't tested that them extensively.
David Sterba (1):
btrfs: extend balance filter limit to take minimum and maximum
Gabríel Arthúr Pétursson (1):
btrfs: add balance filter for stripes
fs/btrfs/ctree.h | 23 ++++++++++++++++++++--- fs/btrfs/volumes.c | 33 +++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 23 +++++++++++++++++++++-- 4 files changed, 76 insertions(+), 5 deletions(-)
Signature · 1 line
2.6.1
David Sterba
maintainerPATCH 1/2 btrfs: extend balance filter limit to take minimum and maximum
The 'limit' filter is underdesigned, it should have been a range for [min,max], with some relaxed semantics when one of the bounds is missing. Besides that, using a full u64 for a single value is a waste of bytes.
Let's fix both by extending the use of the u64 bytes for the [min,max] range. This can be done in a backward compatible way, the range will be interpreted only if the appropriate flag is set (BTRFS_BALANCE_ARGS_LIMITS).
--- fs/btrfs/ctree.h | 14 ++++++++++++-- fs/btrfs/volumes.c | 14 ++++++++++++++ fs/btrfs/volumes.h | 1 + include/uapi/linux/btrfs.h | 13 ++++++++++++- 4 files changed, 39 insertions(+), 3 deletions(-)
fs/btrfs/ctree.h +12 -2
@@ -846,8 +846,18 @@ struct btrfs_disk_balance_args {/* BTRFS_BALANCE_ARGS_* */ __le64 flags; -/* BTRFS_BALANCE_ARGS_LIMIT value */ -__le64 limit; +/* +* BTRFS_BALANCE_ARGS_LIMIT with value 'limit' +* BTRFS_BALANCE_ARGS_LIMITS - the extend version can use minimum and +* maximum +*/ +union { +__le64 limit; +struct { +__le32 limit_min; +__le32 limit_max; + }; + };__le64 unused[7 ]; } __attribute__ ((__packed__));
fs/btrfs/volumes.c +14 -0
@@ -3250,6 +3250,15 @@ static int should_balance_chunk(struct btrfs_root *root,return 0 ; else bargs->limit--; + }else if ((bargs->flags &BTRFS_BALANCE_ARGS_LIMITS )) { +if (bargs->limit_min < bargs->limit_max) { + bargs->limit_max--; + }else if (bargs->limit_min == bargs->limit_max) { + bargs->limit_min =UINT_MAX ; + bargs->limit_max =0 ; + }else { +return 0 ; + } }return 1 ;
@@ -3274,6 +3283,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)int ret;int enospc_errors =0 ;bool counting = true; +/* The single value limit and min/max limits use the same bytes in the */ u64 limit_data = bctl->data.limit;u64 limit_meta = bctl->meta.limit;u64 limit_sys = bctl->sys.limit;
@@ -3317,6 +3327,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)spin_unlock (&fs_info->balance_lock); again:if (!counting) { +/* +* The single value limit and min/max limits use the same bytes +* in the +*/ bctl->data.limit = limit_data; bctl->meta.limit = limit_meta; bctl->sys.limit = limit_sys;
fs/btrfs/volumes.h +1 -0
@@ -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_LIMITS (1ULL << 6)/* * Profile changing flags. When SOFT is set we won't relocate chunk if
include/uapi/linux/btrfs.h +12 -1
@@ -217,7 +217,18 @@ struct btrfs_balance_args {__u64 flags; -__u64 limit;/* limit number of processed chunks */ +/* +* BTRFS_BALANCE_ARGS_LIMIT with value 'limit' +* BTRFS_BALANCE_ARGS_LIMITS - the extend version can use minimum and +* maximum +*/ +union { +__u64 limit;/* limit number of processed chunks */ +struct { +__u32 limit_min; +__u32 limit_max; + }; + };__u64 unused[7 ]; } __attribute__ ((__packed__));
Signature · 1 line
2.6.1
David Sterba
maintainerPATCH 2/2 btrfs: add balance filter for stripes
In reply to David SterbaFrom: Gabríel Arthúr Pétursson <[email protected]>
Balance block groups which have the given number of stripes, defined by a range min..max. This is useful to selectively rebalance only chunks that do not span enough devices, applies to RAID0/10/5/6.
--- fs/btrfs/ctree.h | 9 ++++++++- fs/btrfs/volumes.c | 19 +++++++++++++++++++ fs/btrfs/volumes.h | 1 + include/uapi/linux/btrfs.h | 10 +++++++++- 4 files changed, 37 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +8 -1
@@ -859,7 +859,14 @@ struct btrfs_disk_balance_args { }; }; -__le64 unused[7 ]; +/* +* Process chunks that cross stripes_min..stripes_max devices, +* BTRFS_BALANCE_ARGS_STRIPES +*/ +__le32 stripes_min; +__le32 stripes_max; + +__le64 unused[6 ]; } __attribute__ ((__packed__));/*
fs/btrfs/volumes.c +19 -0
@@ -3170,6 +3170,19 @@ 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->stripes_min <= num_stripes + && num_stripes <= bargs->stripes_max) +return 0 ; + +return 1 ; +} +static int chunk_soft_convert_filter (u64 chunk_type,struct btrfs_balance_args *bargs) {
@@ -3236,6 +3249,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)) {
fs/btrfs/volumes.h +1 -0
@@ -376,6 +376,7 @@ struct map_lookup {#define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)#define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)#define BTRFS_BALANCE_ARGS_LIMITS (1ULL << 6) +#define BTRFS_BALANCE_ARGS_STRIPES (1ULL << 7)/* * Profile changing flags. When SOFT is set we won't relocate chunk if
include/uapi/linux/btrfs.h +9 -1
@@ -229,7 +229,15 @@ struct btrfs_balance_args {__u32 limit_max; }; }; -__u64 unused[7 ]; + +/* +* Process chunks that cross stripes_min..stripes_max devices, +* BTRFS_BALANCE_ARGS_STRIPES +*/ +__le32 stripes_min; +__le32 stripes_max; + +__u64 unused[6 ]; } __attribute__ ((__packed__));/* report balance progress to userspace */
Signature · 1 line
2.6.1