diff mbox series

[v9,06/41] btrfs: introduce max_zone_append_size

Message ID 066af35477cd9dd3a096128df4aef3b583e93f52.1604065695.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned block device support | expand

Commit Message

Naohiro Aota Oct. 30, 2020, 1:51 p.m. UTC
The zone append write command has a maximum IO size restriction it
accepts. This is because a zone append write command cannot be split, as
we ask the device to place the data into a specific target zone and the
device responds with the actual written location of the data.

Introduce max_zone_append_size to zone_info and fs_info to track the
value, so we can limit all I/O to a zoned block device that we want to
write using the zone append command to the device's limits.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/ctree.h |  2 ++
 fs/btrfs/zoned.c | 19 ++++++++++++++++---
 fs/btrfs/zoned.h |  1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

Comments

Josef Bacik Nov. 2, 2020, 4:57 p.m. UTC | #1
On 10/30/20 9:51 AM, Naohiro Aota wrote:
> The zone append write command has a maximum IO size restriction it
> accepts. This is because a zone append write command cannot be split, as
> we ask the device to place the data into a specific target zone and the
> device responds with the actual written location of the data.
> 
> Introduce max_zone_append_size to zone_info and fs_info to track the
> value, so we can limit all I/O to a zoned block device that we want to
> write using the zone append command to the device's limits.
> 
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

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

Thanks,

Josef
David Sterba Nov. 3, 2020, 12:16 p.m. UTC | #2
On Fri, Oct 30, 2020 at 10:51:13PM +0900, Naohiro Aota wrote:
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -953,6 +953,8 @@ struct btrfs_fs_info {
>  		u64 zone_size;
>  		u64 zoned;
>  	};
> +	/* max size to emit ZONE_APPEND write command */

	/* Max size ... */

> +	u64 max_zone_append_size;
>  
>  #ifdef CONFIG_BTRFS_FS_REF_VERIFY
>  	spinlock_t ref_verify_lock;
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index e1cdff5af3a3..1b42e13b8227 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -47,6 +47,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device)
>  {
>  	struct btrfs_zoned_device_info *zone_info = NULL;
>  	struct block_device *bdev = device->bdev;
> +	struct request_queue *q = bdev_get_queue(bdev);

No single letter variables (exception is 'i' for indexing)

>  	sector_t nr_sectors = bdev->bd_part->nr_sects;
>  	sector_t sector = 0;
>  	struct blk_zone *zones = NULL;
> @@ -70,6 +71,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device)
>  	ASSERT(is_power_of_2(zone_sectors));
>  	zone_info->zone_size = (u64)zone_sectors << SECTOR_SHIFT;
>  	zone_info->zone_size_shift = ilog2(zone_info->zone_size);
> +	zone_info->max_zone_append_size =
> +		(u64)queue_max_zone_append_sectors(q) << SECTOR_SHIFT;
>  	zone_info->nr_zones = nr_sectors >> ilog2(bdev_zone_sectors(bdev));
>  	if (!IS_ALIGNED(nr_sectors, zone_sectors))
>  		zone_info->nr_zones++;
> @@ -182,7 +185,8 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
>  	u64 hmzoned_devices = 0;
>  	u64 nr_devices = 0;
>  	u64 zone_size = 0;
> -	int incompat_zoned = btrfs_is_zoned(fs_info);
> +	u64 max_zone_append_size = 0;
> +	bool incompat_zoned = btrfs_is_zoned(fs_info);

	const bool

>  	int ret = 0;
>  
>  	/* Count zoned devices */
> @@ -195,15 +199,23 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
>  		model = bdev_zoned_model(device->bdev);
>  		if (model == BLK_ZONED_HM ||
>  		    (model == BLK_ZONED_HA && incompat_zoned)) {
> +			struct btrfs_zoned_device_info *zone_info =
> +				device->zone_info;
> +
>  			hmzoned_devices++;

I must have missed in some previous patch, 'hmzoned' should be zoned?

>  			if (!zone_size) {
> -				zone_size = device->zone_info->zone_size;
> -			} else if (device->zone_info->zone_size != zone_size) {
> +				zone_size = zone_info->zone_size;
> +			} else if (zone_info->zone_size != zone_size) {
>  				btrfs_err(fs_info,
>  					  "Zoned block devices must have equal zone sizes");

				"zoned: devices must have equal zone sizes, have %u found %u"

>  				ret = -EINVAL;
>  				goto out;
>  			}
> +			if (!max_zone_append_size ||
> +			    (zone_info->max_zone_append_size &&
> +			     zone_info->max_zone_append_size < max_zone_append_size))
> +				max_zone_append_size =
> +					zone_info->max_zone_append_size;
>  		}
>  		nr_devices++;
>  	}
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 25fd4e97dd2a..383c83a1f5b5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -953,6 +953,8 @@  struct btrfs_fs_info {
 		u64 zone_size;
 		u64 zoned;
 	};
+	/* max size to emit ZONE_APPEND write command */
+	u64 max_zone_append_size;
 
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
 	spinlock_t ref_verify_lock;
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e1cdff5af3a3..1b42e13b8227 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -47,6 +47,7 @@  int btrfs_get_dev_zone_info(struct btrfs_device *device)
 {
 	struct btrfs_zoned_device_info *zone_info = NULL;
 	struct block_device *bdev = device->bdev;
+	struct request_queue *q = bdev_get_queue(bdev);
 	sector_t nr_sectors = bdev->bd_part->nr_sects;
 	sector_t sector = 0;
 	struct blk_zone *zones = NULL;
@@ -70,6 +71,8 @@  int btrfs_get_dev_zone_info(struct btrfs_device *device)
 	ASSERT(is_power_of_2(zone_sectors));
 	zone_info->zone_size = (u64)zone_sectors << SECTOR_SHIFT;
 	zone_info->zone_size_shift = ilog2(zone_info->zone_size);
+	zone_info->max_zone_append_size =
+		(u64)queue_max_zone_append_sectors(q) << SECTOR_SHIFT;
 	zone_info->nr_zones = nr_sectors >> ilog2(bdev_zone_sectors(bdev));
 	if (!IS_ALIGNED(nr_sectors, zone_sectors))
 		zone_info->nr_zones++;
@@ -182,7 +185,8 @@  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 	u64 hmzoned_devices = 0;
 	u64 nr_devices = 0;
 	u64 zone_size = 0;
-	int incompat_zoned = btrfs_is_zoned(fs_info);
+	u64 max_zone_append_size = 0;
+	bool incompat_zoned = btrfs_is_zoned(fs_info);
 	int ret = 0;
 
 	/* Count zoned devices */
@@ -195,15 +199,23 @@  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 		model = bdev_zoned_model(device->bdev);
 		if (model == BLK_ZONED_HM ||
 		    (model == BLK_ZONED_HA && incompat_zoned)) {
+			struct btrfs_zoned_device_info *zone_info =
+				device->zone_info;
+
 			hmzoned_devices++;
 			if (!zone_size) {
-				zone_size = device->zone_info->zone_size;
-			} else if (device->zone_info->zone_size != zone_size) {
+				zone_size = zone_info->zone_size;
+			} else if (zone_info->zone_size != zone_size) {
 				btrfs_err(fs_info,
 					  "Zoned block devices must have equal zone sizes");
 				ret = -EINVAL;
 				goto out;
 			}
+			if (!max_zone_append_size ||
+			    (zone_info->max_zone_append_size &&
+			     zone_info->max_zone_append_size < max_zone_append_size))
+				max_zone_append_size =
+					zone_info->max_zone_append_size;
 		}
 		nr_devices++;
 	}
@@ -246,6 +258,7 @@  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 	}
 
 	fs_info->zone_size = zone_size;
+	fs_info->max_zone_append_size = max_zone_append_size;
 
 	btrfs_info(fs_info, "ZONED mode enabled, zone size %llu B",
 		   fs_info->zone_size);
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index c4c63c4294f2..a63f6177f9ee 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -12,6 +12,7 @@  struct btrfs_zoned_device_info {
 	 */
 	u64 zone_size;
 	u8  zone_size_shift;
+	u64 max_zone_append_size;
 	u32 nr_zones;
 	unsigned long *seq_zones;
 	unsigned long *empty_zones;