linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans van Kranenburg <Hans.van.Kranenburg@mendix.com>
To: Nikolay Borisov <nborisov@suse.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 5/6] btrfs: introduce nparity raid_attr
Date: Fri, 5 Oct 2018 22:45:44 +0000	[thread overview]
Message-ID: <c38ea36e-c827-4e4a-e42d-890a0278bcd1@mendix.com> (raw)
In-Reply-To: <f3602299-4904-9a59-0a38-ab4525be1239@suse.com>

On 10/05/2018 04:42 PM, Nikolay Borisov wrote:
> 
> 
> On  5.10.2018 00:24, Hans van Kranenburg wrote:
>> Instead of hardcoding exceptions for RAID5 and RAID6 in the code, use an
>> nparity field in raid_attr.
>>
>> Signed-off-by: Hans van Kranenburg <hans.van.kranenburg@mendix.com>
>> ---
>>  fs/btrfs/volumes.c | 18 +++++++++++-------
>>  fs/btrfs/volumes.h |  2 ++
>>  2 files changed, 13 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index d82b3d735ebe..453046497ac8 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -37,6 +37,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 1,
>>  		.devs_increment	= 2,
>>  		.ncopies	= 2,
>> +		.nparity        = 0,
>>  		.raid_name	= "raid10",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_RAID10,
>>  		.mindev_error	= BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
>> @@ -49,6 +50,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 1,
>>  		.devs_increment	= 2,
>>  		.ncopies	= 2,
>> +		.nparity        = 0,
>>  		.raid_name	= "raid1",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_RAID1,
>>  		.mindev_error	= BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
>> @@ -61,6 +63,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 0,
>>  		.devs_increment	= 1,
>>  		.ncopies	= 2,
>> +		.nparity        = 0,
>>  		.raid_name	= "dup",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_DUP,
>>  		.mindev_error	= 0,
>> @@ -73,6 +76,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 0,
>>  		.devs_increment	= 1,
>>  		.ncopies	= 1,
>> +		.nparity        = 0,
>>  		.raid_name	= "raid0",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_RAID0,
>>  		.mindev_error	= 0,
>> @@ -85,6 +89,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 0,
>>  		.devs_increment	= 1,
>>  		.ncopies	= 1,
>> +		.nparity        = 0,
>>  		.raid_name	= "single",
>>  		.bg_flag	= 0,
>>  		.mindev_error	= 0,
>> @@ -97,6 +102,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 1,
>>  		.devs_increment	= 1,
>>  		.ncopies	= 1,
>> +		.nparity        = 2,
>>  		.raid_name	= "raid5",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_RAID5,
>>  		.mindev_error	= BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
>> @@ -109,6 +115,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>>  		.tolerated_failures = 2,
>>  		.devs_increment	= 1,
>>  		.ncopies	= 1,
>> +		.nparity        = 2,
>>  		.raid_name	= "raid6",
>>  		.bg_flag	= BTRFS_BLOCK_GROUP_RAID6,
>>  		.mindev_error	= BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
>> @@ -4597,6 +4604,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>>  	int devs_min;		/* min devs needed */
>>  	int devs_increment;	/* ndevs has to be a multiple of this */
>>  	int ncopies;		/* how many copies to data has */
>> +	int nparity;		/* number of stripes worth of bytes to
>> +				   store parity information */
>>  	int ret;
>>  	u64 max_stripe_size;
>>  	u64 max_chunk_size;
>> @@ -4623,6 +4632,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>>  	devs_min = btrfs_raid_array[index].devs_min;
>>  	devs_increment = btrfs_raid_array[index].devs_increment;
>>  	ncopies = btrfs_raid_array[index].ncopies;
>> +	nparity = btrfs_raid_array[index].nparity;
>>  
>>  	if (type & BTRFS_BLOCK_GROUP_DATA) {
>>  		max_stripe_size = SZ_1G;
>> @@ -4752,13 +4762,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>>  	 * this will have to be fixed for RAID1 and RAID10 over
>>  	 * more drives
>>  	 */
>> -	data_stripes = num_stripes / ncopies;
>> -
>> -	if (type & BTRFS_BLOCK_GROUP_RAID5)
>> -		data_stripes = num_stripes - 1;
>> -
>> -	if (type & BTRFS_BLOCK_GROUP_RAID6)
>> -		data_stripes = num_stripes - 2;
>> +	data_stripes = (num_stripes - nparity) / ncopies;
>>  
>>  	/*
>>  	 * Use the number of data stripes to figure out how big this chunk
>> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
>> index 23e9285d88de..0fe005b4295a 100644
>> --- a/fs/btrfs/volumes.h
>> +++ b/fs/btrfs/volumes.h
>> @@ -331,6 +331,8 @@ struct btrfs_raid_attr {
>>  	int tolerated_failures; /* max tolerated fail devs */
>>  	int devs_increment;	/* ndevs has to be a multiple of this */
>>  	int ncopies;		/* how many copies to data has */
>> +	int nparity;		/* number of stripes worth of bytes to
>> +				   store parity information */
> 
> The description can be simplified to: number of parity stripes

Well, if 'stripe' is a synonym for 'device extent' here, then
technically that's incorrect, since all profiles using parity do
distribute the parity data over all stripes. IOW, it's not RAID4.

For the calculations in here we treat it like that, because on this
level we don't care about what goes where later, just that the total
amount of allocated bytes is right.

That's why I thought putting a little hint in there, to make the reader
think about it and then realize that it's actually not that simple. And
apparently that works. :)

> 
>>  	int mindev_error;	/* error code if min devs requisite is unmet */
>>  	const char raid_name[8]; /* name of the raid */
>>  	u64 bg_flag;		/* block group flag of the raid */
>>


-- 
Hans van Kranenburg

  reply	other threads:[~2018-10-05 22:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 21:24 [PATCH 0/6] Chunk allocator DUP fix and cleanups Hans van Kranenburg
2018-10-04 21:24 ` [PATCH 1/6] btrfs: alloc_chunk: do not refurbish num_bytes Hans van Kranenburg
2018-10-05  8:59   ` Nikolay Borisov
2018-10-05  9:00     ` Nikolay Borisov
2018-10-04 21:24 ` [PATCH 2/6] btrfs: alloc_chunk: improve chunk size variable name Hans van Kranenburg
2018-10-04 21:36   ` Hans van Kranenburg
2018-10-05  9:00   ` Nikolay Borisov
2018-10-04 21:24 ` [PATCH 3/6] btrfs: alloc_chunk: fix more DUP stripe size handling Hans van Kranenburg
2018-10-04 21:24 ` [PATCH 4/6] btrfs: fix ncopies raid_attr for RAID56 Hans van Kranenburg
2018-10-05  9:10   ` Nikolay Borisov
2018-10-04 21:24 ` [PATCH 5/6] btrfs: introduce nparity raid_attr Hans van Kranenburg
2018-10-04 22:21   ` Hans van Kranenburg
2018-10-05 14:42   ` Nikolay Borisov
2018-10-05 22:45     ` Hans van Kranenburg [this message]
2018-10-04 21:24 ` [PATCH 6/6] btrfs: alloc_chunk: rework chunk/stripe calculations Hans van Kranenburg
2018-10-05  7:51 ` [PATCH 0/6] Chunk allocator DUP fix and cleanups Qu Wenruo
2018-10-05 10:58   ` Hans van Kranenburg
2018-10-08  6:43     ` Qu Wenruo
2018-10-08 13:19       ` Hans van Kranenburg
2018-10-08 23:51         ` Hans van Kranenburg
2018-10-05  7:51 ` Qu Wenruo
2018-10-11 15:13 ` David Sterba
2018-10-11 19:40   ` Hans van Kranenburg
2018-10-11 20:34     ` Hans van Kranenburg
2018-11-13 15:03     ` David Sterba
2018-11-13 16:45       ` Hans van Kranenburg

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=c38ea36e-c827-4e4a-e42d-890a0278bcd1@mendix.com \
    --to=hans.van.kranenburg@mendix.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).