All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	Nikolay Borisov <nborisov@suse.com>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Hannes Reinecke <hare@suse.com>,
	Anand Jain <anand.jain@oracle.com>,
	linux-fsdevel@vger.kernel.org,
	Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH 05/20] btrfs: factor out set_parameters()
Date: Thu,  6 Feb 2020 19:41:59 +0900	[thread overview]
Message-ID: <20200206104214.400857-6-naohiro.aota@wdc.com> (raw)
In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com>

Factor out set_parameters() from __btrfs_alloc_chunk(). This function
initialises parameters of "struct alloc_chunk_ctl" for allocation.
set_parameters() handles a common part of the initialisation to load the
RAID parameters from btrfs_raid_array. set_parameters_regular() decides
some parameters for its allocation.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/volumes.c | 96 ++++++++++++++++++++++++++++------------------
 1 file changed, 59 insertions(+), 37 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index cfde302bf297..a5d6f0b5ca70 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4841,6 +4841,60 @@ struct alloc_chunk_ctl {
 	int ndevs;
 };
 
+static void set_parameters_regular(struct btrfs_fs_devices *fs_devices,
+				   struct alloc_chunk_ctl *ctl)
+{
+	u64 type = ctl->type;
+
+	if (type & BTRFS_BLOCK_GROUP_DATA) {
+		ctl->max_stripe_size = SZ_1G;
+		ctl->max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE;
+	} else if (type & BTRFS_BLOCK_GROUP_METADATA) {
+		/* for larger filesystems, use larger metadata chunks */
+		if (fs_devices->total_rw_bytes > 50ULL * SZ_1G)
+			ctl->max_stripe_size = SZ_1G;
+		else
+			ctl->max_stripe_size = SZ_256M;
+		ctl->max_chunk_size = ctl->max_stripe_size;
+	} else if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
+		ctl->max_stripe_size = SZ_32M;
+		ctl->max_chunk_size = 2 * ctl->max_stripe_size;
+		ctl->devs_max = min_t(int, ctl->devs_max,
+				      BTRFS_MAX_DEVS_SYS_CHUNK);
+	} else {
+		BUG();
+	}
+
+	/* We don't want a chunk larger than 10% of writable space */
+	ctl->max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1),
+				  ctl->max_chunk_size);
+}
+
+static void set_parameters(struct btrfs_fs_devices *fs_devices,
+			   struct alloc_chunk_ctl *ctl)
+{
+	int index = btrfs_bg_flags_to_raid_index(ctl->type);
+
+	ctl->sub_stripes = btrfs_raid_array[index].sub_stripes;
+	ctl->dev_stripes = btrfs_raid_array[index].dev_stripes;
+	ctl->devs_max = btrfs_raid_array[index].devs_max;
+	if (!ctl->devs_max)
+		ctl->devs_max = BTRFS_MAX_DEVS(fs_devices->fs_info);
+	ctl->devs_min = btrfs_raid_array[index].devs_min;
+	ctl->devs_increment = btrfs_raid_array[index].devs_increment;
+	ctl->ncopies = btrfs_raid_array[index].ncopies;
+	ctl->nparity = btrfs_raid_array[index].nparity;
+	ctl->ndevs = 0;
+
+	switch (fs_devices->chunk_alloc_policy) {
+	case BTRFS_CHUNK_ALLOC_REGULAR:
+		set_parameters_regular(fs_devices, ctl);
+		break;
+	default:
+		BUG();
+	}
+}
+
 static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 			       u64 start, u64 type)
 {
@@ -4859,7 +4913,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	int ndevs;
 	int i;
 	int j;
-	int index;
 
 	BUG_ON(!alloc_profile_is_valid(type, 0));
 
@@ -4869,45 +4922,14 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		return -ENOSPC;
 	}
 
-	ctl.start = start;
-	ctl.type = type;
-
-	index = btrfs_bg_flags_to_raid_index(type);
-
-	ctl.sub_stripes = btrfs_raid_array[index].sub_stripes;
-	ctl.dev_stripes = btrfs_raid_array[index].dev_stripes;
-	ctl.devs_max = btrfs_raid_array[index].devs_max;
-	if (!ctl.devs_max)
-		ctl.devs_max = BTRFS_MAX_DEVS(info);
-	ctl.devs_min = btrfs_raid_array[index].devs_min;
-	ctl.devs_increment = btrfs_raid_array[index].devs_increment;
-	ctl.ncopies = btrfs_raid_array[index].ncopies;
-	ctl.nparity = btrfs_raid_array[index].nparity;
-
-	if (type & BTRFS_BLOCK_GROUP_DATA) {
-		ctl.max_stripe_size = SZ_1G;
-		ctl.max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE;
-	} else if (type & BTRFS_BLOCK_GROUP_METADATA) {
-		/* for larger filesystems, use larger metadata chunks */
-		if (fs_devices->total_rw_bytes > 50ULL * SZ_1G)
-			ctl.max_stripe_size = SZ_1G;
-		else
-			ctl.max_stripe_size = SZ_256M;
-		ctl.max_chunk_size = ctl.max_stripe_size;
-	} else if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
-		ctl.max_stripe_size = SZ_32M;
-		ctl.max_chunk_size = 2 * ctl.max_stripe_size;
-		ctl.devs_max = min_t(int, ctl.devs_max,
-				      BTRFS_MAX_DEVS_SYS_CHUNK);
-	} else {
-		btrfs_err(info, "invalid chunk type 0x%llx requested",
-		       type);
+	if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
+		btrfs_err(info, "invalid chunk type 0x%llx requested", type);
 		BUG();
 	}
 
-	/* We don't want a chunk larger than 10% of writable space */
-	ctl.max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1),
-				  ctl.max_chunk_size);
+	ctl.start = start;
+	ctl.type = type;
+	set_parameters(fs_devices, &ctl);
 
 	devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info),
 			       GFP_NOFS);
-- 
2.25.0


  parent reply	other threads:[~2020-02-06 10:44 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06 10:41 [PATCH 00/20] btrfs: refactor and generalize chunk/dev_extent/extent allocation Naohiro Aota
2020-02-06 10:41 ` [PATCH 01/20] btrfs: change type of full_search to bool Naohiro Aota
2020-02-06 11:26   ` Johannes Thumshirn
2020-02-06 16:03   ` Josef Bacik
2020-02-06 10:41 ` [PATCH 02/20] btrfs: introduce chunk allocation policy Naohiro Aota
2020-02-06 11:30   ` Johannes Thumshirn
2020-02-07  6:11     ` Naohiro Aota
2020-02-06 16:06   ` Josef Bacik
2020-02-06 16:07   ` Josef Bacik
2020-02-06 10:41 ` [PATCH 03/20] btrfs: refactor find_free_dev_extent_start() Naohiro Aota
2020-02-06 12:02   ` Johannes Thumshirn
2020-02-07  6:22     ` Naohiro Aota
2020-02-06 16:34   ` Josef Bacik
2020-02-06 10:41 ` [PATCH 04/20] btrfs: introduce alloc_chunk_ctl Naohiro Aota
2020-02-06 12:07   ` Johannes Thumshirn
2020-02-06 16:38   ` Josef Bacik
2020-02-07  7:08     ` Naohiro Aota
2020-02-06 10:41 ` Naohiro Aota [this message]
2020-02-06 13:51   ` [PATCH 05/20] btrfs: factor out set_parameters() Johannes Thumshirn
2020-02-06 16:40   ` Josef Bacik
2020-02-07  7:59     ` Naohiro Aota
2020-02-06 10:42 ` [PATCH 06/20] btrfs: factor out gather_device_info() Naohiro Aota
2020-02-06 15:43   ` Johannes Thumshirn
2020-02-07  9:54     ` Naohiro Aota
2020-02-06 16:44   ` Josef Bacik
2020-02-06 10:42 ` [PATCH 07/20] btrfs: factor out decide_stripe_size() Naohiro Aota
2020-02-06 15:59   ` Johannes Thumshirn
2020-02-06 16:47   ` Josef Bacik
2020-02-06 10:42 ` [PATCH 08/20] btrfs: factor out create_chunk() Naohiro Aota
2020-02-06 16:49   ` Josef Bacik
2020-02-07  9:17     ` Naohiro Aota
2020-02-06 10:42 ` [PATCH 09/20] btrfs: parameterize dev_extent_min Naohiro Aota
2020-02-06 16:52   ` Josef Bacik
2020-02-07  9:00     ` Naohiro Aota
2020-02-06 10:42 ` [PATCH 10/20] btrfs: introduce extent allocation policy Naohiro Aota
2020-02-06 10:42 ` [PATCH 11/20] btrfs: move hint_byte into find_free_extent_ctl Naohiro Aota
2020-02-06 10:42 ` [PATCH 12/20] btrfs: introduce clustered_alloc_info Naohiro Aota
2020-02-06 12:44   ` Su Yue
2020-02-07  9:25     ` Naohiro Aota
2020-02-06 17:01   ` Josef Bacik
2020-02-07  9:53     ` Naohiro Aota
2020-02-06 10:42 ` [PATCH 13/20] btrfs: factor out do_allocation() Naohiro Aota
2020-02-06 10:42 ` [PATCH 14/20] btrfs: drop unnecessary arguments from clustered allocation functions Naohiro Aota
2020-02-06 10:42 ` [PATCH 15/20] btrfs: factor out release_block_group() Naohiro Aota
2020-02-06 10:42 ` [PATCH 16/20] btrfs: factor out found_extent() Naohiro Aota
2020-02-06 10:42 ` [PATCH 17/20] btrfs: drop unnecessary arguments from find_free_extent_update_loop() Naohiro Aota
2020-02-06 10:42 ` [PATCH 18/20] btrfs: factor out chunk_allocation_failed() Naohiro Aota
2020-02-06 10:42 ` [PATCH 19/20] btrfs: skip LOOP_NO_EMPTY_SIZE if not clustered allocation Naohiro Aota
2020-02-06 10:42 ` [PATCH 20/20] btrfs: factor out prepare_allocation() Naohiro Aota
2020-02-06 11:43 ` [PATCH 00/20] btrfs: refactor and generalize chunk/dev_extent/extent allocation Martin Steigerwald
2020-02-07  6:06   ` Naohiro Aota
2020-02-07  8:02     ` Martin Steigerwald

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=20200206104214.400857-6-naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=anand.jain@oracle.com \
    --cc=clm@fb.com \
    --cc=damien.lemoal@wdc.com \
    --cc=dsterba@suse.com \
    --cc=hare@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.