btrfs: introduce max_zone_append_size
authorNaohiro Aota <naohiro.aota@wdc.com>
Tue, 10 Nov 2020 11:26:09 +0000 (20:26 +0900)
committerDavid Sterba <dsterba@suse.com>
Wed, 9 Dec 2020 18:16:04 +0000 (19:16 +0100)
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.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/zoned.c
fs/btrfs/zoned.h

index 8f20219e2caa7a63a7d747cd4b0f7e0a43f1b3c8..7fe74f6a248643bd1ceb9c814a5eecb64ecf2bd1 100644 (file)
@@ -965,6 +965,9 @@ struct btrfs_fs_info {
                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;
        struct rb_root block_tree;
index 56bb701e3b5366fcb42303cfbadaf1e18d4de718..f984cf9063eea41f0c36b3942bf1e64788019de1 100644 (file)
@@ -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 *queue = bdev_get_queue(bdev);
        sector_t nr_sectors;
        sector_t sector = 0;
        struct blk_zone *zones = NULL;
@@ -70,6 +71,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device)
        ASSERT(zone_sectors != 0 && (zone_sectors & (zone_sectors - 1)) == 0);
        zone_info->zone_size = 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(queue) << SECTOR_SHIFT;
        zone_info->nr_zones = nr_sectors >> ilog2(zone_sectors);
        if (!IS_ALIGNED(nr_sectors, zone_sectors))
                zone_info->nr_zones++;
@@ -174,6 +177,7 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
        u64 zoned_devices = 0;
        u64 nr_devices = 0;
        u64 zone_size = 0;
+       u64 max_zone_append_size = 0;
        const bool incompat_zoned = btrfs_is_zoned(fs_info);
        int ret = 0;
 
@@ -187,10 +191,13 @@ 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;
+
+                       zone_info = device->zone_info;
                        zoned_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: unequal block device zone sizes: have %llu found %llu",
                                          device->zone_info->zone_size,
@@ -198,6 +205,11 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
                                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++;
        }
@@ -241,6 +253,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 with zone size %llu", zone_size);
 out:
index e4ee1a50be2d3f1c17ff3edd6889758aafae870f..bb2afc7320a4c058470b923bfe1ad3208a3ecb44 100644 (file)
@@ -13,6 +13,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;