[PATCH 0/1] block: move sector bio member into blk_next_bio()

Chaitanya Kulkarni kch at nvidia.com
Mon Feb 28 18:23:09 PST 2022


Hi,

blk_next_bio() is the central function which allocates bios for
discard, write-same, write-zeroes and zone-mgmt. The initialization of
sector bio member is duplicated in disacrd, write-same, write-zeores
etc. Move sector member to the blk_next_bio() just like we have moved
other members to blk_next_bio().

-ck

Chaitanya Kulkarni (1):
  block: move sector bio member into blk_next_bio()

 block/bio.c               |  5 ++++-
 block/blk-lib.c           | 20 +++++++++-----------
 block/blk-zoned.c         |  9 ++++-----
 drivers/nvme/target/zns.c |  3 +--
 include/linux/bio.h       |  3 ++-
 5 files changed, 20 insertions(+), 20 deletions(-)

dev linux-block-broken (for-next) # sh test-discard-wz.sh 
+ git diff block drivers/block/null_blk
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 3407b1afc079..afb2d471bbe7 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -79,6 +79,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 
                WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
 
+               pr_info("%s %d sector %llu nr_sects %llu\n",
+                               __func__, __LINE__, sector, nr_sects);
                bio = blk_next_bio(bio, bdev, sector, 0, op, gfp_mask);
                bio->bi_iter.bi_size = req_sects << 9;
                sector += req_sects;
@@ -166,6 +168,8 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
        max_write_same_sectors = bio_allowed_max_sectors(q);
 
        while (nr_sects) {
+               pr_info("%s %d sector %llu nr_sects %llu\n",
+                               __func__, __LINE__, sector, nr_sects);
                bio = blk_next_bio(bio, bdev, sector, 1, REQ_OP_WRITE_SAME,
                                   gfp_mask);
                bio->bi_vcnt = 1;
@@ -238,6 +242,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
                return -EOPNOTSUPP;
 
        while (nr_sects) {
+               pr_info("%s %d sector %llu nr_sects %llu\n",
+                               __func__, __LINE__, sector, nr_sects);
                bio = blk_next_bio(bio, bdev, sector, 0, op | opf, gfp_mask);
 
                if (nr_sects > max_write_zeroes_sectors) {
@@ -281,6 +287,8 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
                return -EPERM;
 
        while (nr_sects != 0) {
+               pr_info("%s %d sector %llu nr_sects %llu\n",
+                               __func__, __LINE__, sector, nr_sects);
                bio = blk_next_bio(bio, bdev, sector, nr_pages, REQ_OP_WRITE,
                                   gfp_mask);
 
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 0a8680df3f1c..78fca69b7b28 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -215,6 +215,8 @@ static int blkdev_zone_reset_all_emulated(struct block_device *bdev,
                        continue;
                }
 
+               pr_info("%s %d sector %llu nr_sects 0\n",
+                               __func__, __LINE__, sector);
                bio = blk_next_bio(bio, bdev, sector, 0,
                                   REQ_OP_ZONE_RESET | REQ_SYNC, gfp_mask);
                sector += zone_sectors;
@@ -301,6 +303,8 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
        }
 
        while (sector < end_sector) {
+               pr_info("%s %d sector %llu nr_sects 0\n",
+                               __func__, __LINE__, sector);
                bio = blk_next_bio(bio, bdev, sector, 0, op | REQ_SYNC,
                                   gfp_mask);
                sector += zone_sectors;
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 05b1120e6623..9f7be46c6549 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -80,6 +80,12 @@ enum {
        NULL_Q_MQ               = 2,
 };
 
+static bool g_write_zeroes = false;
+module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
+
+static bool g_reset_all = false;
+module_param_named(reset_all, g_reset_all, bool, 0444);
+
 static bool g_virt_boundary = false;
 module_param_named(virt_boundary, g_virt_boundary, bool, 0444);
 MODULE_PARM_DESC(virt_boundary, "Require a virtual boundary for the device. Default: False");
@@ -656,6 +662,7 @@ static struct nullb_device *null_alloc_dev(void)
        dev->zone_nr_conv = g_zone_nr_conv;
        dev->zone_max_open = g_zone_max_open;
        dev->zone_max_active = g_zone_max_active;
+       dev->reset_all = g_reset_all;
        dev->virt_boundary = g_virt_boundary;
        return dev;
 }
@@ -1749,25 +1756,12 @@ static void null_del_dev(struct nullb *nullb)
 
 static void null_config_discard(struct nullb *nullb)
 {
-       if (nullb->dev->discard == false)
-               return;
-
-       if (!nullb->dev->memory_backed) {
-               nullb->dev->discard = false;
-               pr_info("discard option is ignored without memory backing\n");
-               return;
-       }
-
-       if (nullb->dev->zoned) {
-               nullb->dev->discard = false;
-               pr_info("discard option is ignored in zoned mode\n");
-               return;
-       }
-
        nullb->q->limits.discard_granularity = nullb->dev->blocksize;
        nullb->q->limits.discard_alignment = nullb->dev->blocksize;
        blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9);
        blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
+       if (g_write_zeroes)
+               blk_queue_max_write_zeroes_sectors(nullb->q, UINT_MAX >> 9);
 }
 
 static const struct block_device_operations null_bio_ops = {
diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h
index 78eb56b0ca55..619433f2d599 100644
--- a/drivers/block/null_blk/null_blk.h
+++ b/drivers/block/null_blk/null_blk.h
@@ -102,6 +102,7 @@ struct nullb_device {
        bool power; /* power on/off the device */
        bool memory_backed; /* if data is stored in memory */
        bool discard; /* if support discard */
+       bool reset_all; /* if support reset_all */
        bool zoned; /* if device is zoned */
        bool virt_boundary; /* virtual boundary on/off for the device */
 };
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index dae54dd1aeac..7ed032e43131 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -157,7 +157,8 @@ int null_register_zoned_dev(struct nullb *nullb)
        struct request_queue *q = nullb->q;
 
        blk_queue_set_zoned(nullb->disk, BLK_ZONED_HM);
-       blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
+       if (dev->reset_all)
+               blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
        blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
 
        if (queue_is_mq(q)) {
+ modprobe -r null_blk
+ modprobe null_blk
+ blkdiscard -o 0 -l 40960 /dev/nullb0
+ blkdiscard -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.094314] null_blk: module loaded
[21846.097714] __blkdev_issue_discard 82 sector 0 nr_sects 80
[21846.100089] __blkdev_issue_discard 82 sector 2 nr_sects 20
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ blkdiscard -z -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.104408] __blkdev_issue_zero_pages 290 sector 0 nr_sects 80
[21846.106771] __blkdev_issue_zero_pages 290 sector 2 nr_sects 20
+ modprobe -r null_blk
+ modprobe null_blk write_zeroes=1
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ blkdiscard -z -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.144751] null_blk: module loaded
[21846.147315] __blkdev_issue_write_zeroes 245 sector 0 nr_sects 80
[21846.149549] __blkdev_issue_write_zeroes 245 sector 2 nr_sects 20
+ modprobe -r null_blk
+ modprobe null_blk zoned=1 gb=1 zone_size=128
+ dd if=/dev/zero of=/dev/nullb0 bs=4k oflag=direct
dd: error writing '/dev/nullb0': No space left on device
262145+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.17173 s, 208 MB/s
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0001c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*7)/512'
++ bc
+ offset=1835008
+ blkzone reset -o 1835008 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*6)/512'
++ bc
+ offset=1572864
+ blkzone reset -o 1572864 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*5)/512'
++ bc
+ offset=1310720
+ blkzone reset -o 1310720 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*4)/512'
++ bc
+ offset=1048576
+ blkzone reset -o 1048576 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*3)/512'
++ bc
+ offset=786432
+ blkzone reset -o 786432 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*2)/512'
++ bc
+ offset=524288
+ blkzone reset -o 524288 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*1)/512'
++ bc
+ offset=262144
+ blkzone reset -o 262144 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*0)/512'
++ bc
+ offset=0
+ blkzone reset -o 0 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ dmesg -c
[21846.186170] null_blk: module loaded
[21851.363766] blkdev_zone_mgmt 306 sector 1835008 nr_sects 0
[21851.368268] blkdev_zone_mgmt 306 sector 1572864 nr_sects 0
[21851.372565] blkdev_zone_mgmt 306 sector 1310720 nr_sects 0
[21851.377126] blkdev_zone_mgmt 306 sector 1048576 nr_sects 0
[21851.381438] blkdev_zone_mgmt 306 sector 786432 nr_sects 0
[21851.385542] blkdev_zone_mgmt 306 sector 524288 nr_sects 0
[21851.389727] blkdev_zone_mgmt 306 sector 262144 nr_sects 0
[21851.394340] blkdev_zone_mgmt 306 sector 0 nr_sects 0
+ echo ---------------------------------------------------
---------------------------------------------------
+ modprobe -r null_blk
+ modprobe null_blk zoned=1 gb=1 zone_size=128 reset_all=0
+ dd if=/dev/zero of=/dev/nullb0 bs=4k oflag=direct
dd: error writing '/dev/nullb0': No space left on device
262145+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.12941 s, 209 MB/s
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
  start: 0x0001c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
+ blkzone reset /dev/nullb0
+ blkzone report /dev/nullb0
  start: 0x000000000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
  start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ modprobe -r null_blk
+ rm -fr /dev/nullb0
+ dmesg -c
[21851.434632] null_blk: module loaded
[21856.567436] blkdev_zone_reset_all_emulated 218 sector 0 nr_sects 0
[21856.567441] blkdev_zone_reset_all_emulated 218 sector 262144 nr_sects 0
[21856.567449] blkdev_zone_reset_all_emulated 218 sector 524288 nr_sects 0
[21856.567451] blkdev_zone_reset_all_emulated 218 sector 786432 nr_sects 0
[21856.567452] blkdev_zone_reset_all_emulated 218 sector 1048576 nr_sects 0
[21856.567454] blkdev_zone_reset_all_emulated 218 sector 1310720 nr_sects 0
[21856.567455] blkdev_zone_reset_all_emulated 218 sector 1572864 nr_sects 0
[21856.567459] blkdev_zone_reset_all_emulated 218 sector 1835008 nr_sects 0
+ set +x




More information about the Linux-nvme mailing list