2022-10-05 04:43:45

by Chaitanya Kulkarni

[permalink] [raw]
Subject: [PATCH 0/6] null_blk: allow REQ_OP_WRITE_ZEROES and cleanup

Hi,

In order to test the non-trivial I/O path in the block layer for
REQ_OP_WRITE_ZEROES allow write-zeroes on null_blk so we can write
testcases with and without non-memory backed mode followed by
few cleanup patches.

Below is the test report with ext2/ext4 mkfs and a blktest
waiting to get upstream for this patch-series.

-ck

Chaitanya Kulkarni (6):
null_blk: allow write zeores on non-membacked
null_blk: allow write zeores on membacked
null_blk: code cleaup
null_blk: initialize cmd->bio in __alloc_cmd()
null_blk: don't use magic numbers in the code
null_blk: remove extra space in switch condition

drivers/block/null_blk/main.c | 131 ++++++++++++++++++++++--------
drivers/block/null_blk/null_blk.h | 1 +
2 files changed, 97 insertions(+), 35 deletions(-)

1. Write Zeroes test with ext2/ext3 for memory backed :-
linux-block (for-next) # mkfs.ext2 /dev/nullb0
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 76037c2c-9c32-4ac6-b1d6-d1f62e6071ad
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

linux-block (for-next) # mount /dev/nullb0 /mnt/
backend/ data/ nullb0/ nvme1n1/ test/
linux-block (for-next) # mount /dev/nullb0 /mnt/nullb0/
linux-block (for-next) # dmesg -c
[18833.072830] null_blk: null_handle_write_zeroes 1225 2097024 128
[18833.072963] null_blk: null_handle_write_zeroes 1225 536 4096
[18833.073439] null_blk: null_handle_write_zeroes 1225 262680 4096
[18833.073845] null_blk: null_handle_write_zeroes 1225 524304 4096
[18833.074202] null_blk: null_handle_write_zeroes 1225 786968 4096
[18833.074581] null_blk: null_handle_write_zeroes 1225 1048592 4096
[18833.074951] null_blk: null_handle_write_zeroes 1225 1311256 4096
[18833.075381] null_blk: null_handle_write_zeroes 1225 1572880 4096
[18833.075748] null_blk: null_handle_write_zeroes 1225 1835544 4096
[18833.076164] null_blk: null_handle_write_zeroes 1225 4672 8
[18844.752019] EXT4-fs (nullb0): mounting ext2 file system using the ext4 subsystem
[18844.752487] EXT4-fs (nullb0): mounted filesystem without journal. Quota mode: none.
linux-block (for-next) #


linux-block (for-next) # mkfs.ext4 /dev/nullb0
mke2fs 1.45.6 (20-Mar-2020)
/dev/nullb0 contains a ext2 file system
last mounted on Mon Oct 3 18:28:05 2022
Proceed anyway? (y,N) y
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: a4c66d5f-bda9-4f58-aa03-911b87bb5c7d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

linux-block (for-next) # mount /dev/nullb0 /mnt/nullb0/
linux-block (for-next) # dmesg -c
[18882.721160] EXT4-fs (nullb0): unmounting filesystem.
[18888.687070] null_blk: null_handle_write_zeroes 1225 2097024 128
[18888.687159] null_blk: null_handle_write_zeroes 1225 1160 8
[18888.687309] null_blk: null_handle_write_zeroes 1225 33968 8
[18888.687839] null_blk: null_handle_write_zeroes 1225 1048576 65536
[18892.105964] EXT4-fs (nullb0): mounted filesystem with ordered data mode. Quota mode: none.
linux-block (for-next) #

2. Test blkdiscard with -z for different block sizes :-

linux-block (for-next) # ./zeroout.sh
#################### BLKISZ 512 #####################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── max_sectors
├── mbps
├── memory_backed
├── no_sched
├── poll_queues
├── power
├── queue_mode
├── shared_tag_bitmap
├── size
├── submit_queues
├── use_per_node_hctx
├── virt_boundary
├── write_zeroes
├── zone_capacity
├── zoned
├── zone_max_active
├── zone_max_open
├── zone_nr_conv
└── zone_size

0 directories, 29 files
ODD:-
19+1 records in
19+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.000521991 s, 19.2 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0000512 a a a a a a a a a a a a a a a a
0000528
0001024 a a a a a a a a a a a a a a a a
0001040
0001536 a a a a a a a a a a a a a a a a
0001552
0002048 a a a a a a a a a a a a a a a a
0002064
0002560 a a a a a a a a a a a a a a a a
0002576
0003072 a a a a a a a a a a a a a a a a
0003088
0003584 a a a a a a a a a a a a a a a a
0003600
0004096 a a a a a a a a a a a a a a a a
0004112
0004608 a a a a a a a a a a a a a a a a
0004624
------------------------------------------------------
0000000 a a a a a a a a a a a a a a a a
0000016
0000512 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000528
0001024 a a a a a a a a a a a a a a a a
0001040
0001536 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0001552
0002048 a a a a a a a a a a a a a a a a
0002064
0002560 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0002576
0003072 a a a a a a a a a a a a a a a a
0003088
0003584 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0003600
0004096 a a a a a a a a a a a a a a a a
0004112
0004608 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0004624
------------------------------------------------------
EVEN:-
19+1 records in
19+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.000376636 s, 26.6 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0000512 a a a a a a a a a a a a a a a a
0000528
0001024 a a a a a a a a a a a a a a a a
0001040
0001536 a a a a a a a a a a a a a a a a
0001552
0002048 a a a a a a a a a a a a a a a a
0002064
0002560 a a a a a a a a a a a a a a a a
0002576
0003072 a a a a a a a a a a a a a a a a
0003088
0003584 a a a a a a a a a a a a a a a a
0003600
0004096 a a a a a a a a a a a a a a a a
0004112
0004608 a a a a a a a a a a a a a a a a
0004624
------------------------------------------------------
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000016
0000512 a a a a a a a a a a a a a a a a
0000528
0001024 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0001040
0001536 a a a a a a a a a a a a a a a a
0001552
0002048 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0002064
0002560 a a a a a a a a a a a a a a a a
0002576
0003072 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0003088
0003584 a a a a a a a a a a a a a a a a
0003600
0004096 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0004112
0004608 a a a a a a a a a a a a a a a a
0004624
------------------------------------------------------




#################### BLKISZ 1024 #####################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── max_sectors
├── mbps
├── memory_backed
├── no_sched
├── poll_queues
├── power
├── queue_mode
├── shared_tag_bitmap
├── size
├── submit_queues
├── use_per_node_hctx
├── virt_boundary
├── write_zeroes
├── zone_capacity
├── zoned
├── zone_max_active
├── zone_max_open
├── zone_nr_conv
└── zone_size

0 directories, 29 files
ODD:-
9+1 records in
9+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.00040033 s, 25.0 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0001024 a a a a a a a a a a a a a a a a
0001040
0002048 a a a a a a a a a a a a a a a a
0002064
0003072 a a a a a a a a a a a a a a a a
0003088
0004096 a a a a a a a a a a a a a a a a
0004112
0005120 a a a a a a a a a a a a a a a a
0005136
0006144 a a a a a a a a a a a a a a a a
0006160
0007168 a a a a a a a a a a a a a a a a
0007184
0008192 a a a a a a a a a a a a a a a a
0008208
0009216 a a a a a a a a a a a a a a a a
0009232
------------------------------------------------------
0000000 a a a a a a a a a a a a a a a a
0000016
0001024 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0001040
0002048 a a a a a a a a a a a a a a a a
0002064
0003072 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0003088
0004096 a a a a a a a a a a a a a a a a
0004112
0005120 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0005136
0006144 a a a a a a a a a a a a a a a a
0006160
0007168 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0007184
0008192 a a a a a a a a a a a a a a a a
0008208
0009216 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0009232
------------------------------------------------------
EVEN:-
9+1 records in
9+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.000325488 s, 30.7 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0001024 a a a a a a a a a a a a a a a a
0001040
0002048 a a a a a a a a a a a a a a a a
0002064
0003072 a a a a a a a a a a a a a a a a
0003088
0004096 a a a a a a a a a a a a a a a a
0004112
0005120 a a a a a a a a a a a a a a a a
0005136
0006144 a a a a a a a a a a a a a a a a
0006160
0007168 a a a a a a a a a a a a a a a a
0007184
0008192 a a a a a a a a a a a a a a a a
0008208
0009216 a a a a a a a a a a a a a a a a
0009232
------------------------------------------------------
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000016
0001024 a a a a a a a a a a a a a a a a
0001040
0002048 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0002064
0003072 a a a a a a a a a a a a a a a a
0003088
0004096 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0004112
0005120 a a a a a a a a a a a a a a a a
0005136
0006144 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0006160
0007168 a a a a a a a a a a a a a a a a
0007184
0008192 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0008208
0009216 a a a a a a a a a a a a a a a a
0009232
------------------------------------------------------




#################### BLKISZ 2048 #####################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── max_sectors
├── mbps
├── memory_backed
├── no_sched
├── poll_queues
├── power
├── queue_mode
├── shared_tag_bitmap
├── size
├── submit_queues
├── use_per_node_hctx
├── virt_boundary
├── write_zeroes
├── zone_capacity
├── zoned
├── zone_max_active
├── zone_max_open
├── zone_nr_conv
└── zone_size

0 directories, 29 files
ODD:-
4+1 records in
4+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.000367949 s, 27.2 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0002048 a a a a a a a a a a a a a a a a
0002064
0004096 a a a a a a a a a a a a a a a a
0004112
0006144 a a a a a a a a a a a a a a a a
0006160
0008192 a a a a a a a a a a a a a a a a
0008208
0010240 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0010256
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0014336 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0014352
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0018432 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0018448
------------------------------------------------------
0000000 a a a a a a a a a a a a a a a a
0000016
0002048 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0002064
0004096 a a a a a a a a a a a a a a a a
0004112
0006144 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0006160
0008192 a a a a a a a a a a a a a a a a
0008208
0010240 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0010256
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0014336 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0014352
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0018432 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0018448
------------------------------------------------------
EVEN:-
4+1 records in
4+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.000310981 s, 32.2 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0002048 a a a a a a a a a a a a a a a a
0002064
0004096 a a a a a a a a a a a a a a a a
0004112
0006144 a a a a a a a a a a a a a a a a
0006160
0008192 a a a a a a a a a a a a a a a a
0008208
0010240 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0010256
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0014336 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0014352
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0018432 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0018448
------------------------------------------------------
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000016
0002048 a a a a a a a a a a a a a a a a
0002064
0004096 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0004112
0006144 a a a a a a a a a a a a a a a a
0006160
0008192 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0008208
0010240 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0010256
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0014336 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0014352
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0018432 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0018448
------------------------------------------------------




#################### BLKISZ 4096 #####################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── max_sectors
├── mbps
├── memory_backed
├── no_sched
├── poll_queues
├── power
├── queue_mode
├── shared_tag_bitmap
├── size
├── submit_queues
├── use_per_node_hctx
├── virt_boundary
├── write_zeroes
├── zone_capacity
├── zoned
├── zone_max_active
├── zone_max_open
├── zone_nr_conv
└── zone_size

0 directories, 29 files
ODD:-
2+1 records in
2+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.00028502 s, 35.1 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0004096 a a a a a a a a a a a a a a a a
0004112
0008192 a a a a a a a a a a a a a a a a
0008208
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0020480 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0020496
0024576 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0024592
0028672 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0028688
0032768 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0032784
0036864 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0036880
------------------------------------------------------
0000000 a a a a a a a a a a a a a a a a
0000016
0004096 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0004112
0008192 a a a a a a a a a a a a a a a a
0008208
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0020480 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0020496
0024576 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0024592
0028672 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0028688
0032768 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0032784
0036864 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0036880
------------------------------------------------------
EVEN:-
2+1 records in
2+1 records out
10002 bytes (10 kB, 9.8 KiB) copied, 0.00024765 s, 40.4 MB/s
0000000 a a a a a a a a a a a a a a a a
0000016
0004096 a a a a a a a a a a a a a a a a
0004112
0008192 a a a a a a a a a a a a a a a a
0008208
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0020480 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0020496
0024576 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0024592
0028672 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0028688
0032768 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0032784
0036864 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0036880
------------------------------------------------------
0000000 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000016
0004096 a a a a a a a a a a a a a a a a
0004112
0008192 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0008208
0012288 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0012304
0016384 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0016400
0020480 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0020496
0024576 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0024592
0028672 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0028688
0032768 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0032784
0036864 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0036880
------------------------------------------------------





2022-10-05 05:01:22

by Chaitanya Kulkarni

[permalink] [raw]
Subject: [PATCH 2/6] null_blk: allow write zeores on membacked

Add a helper functions to enable the REQ_OP_WRITE_ZEROES operations
when null_blk is configured with the membacked mode.

Since write-zeroes is a non-trivial I/O operation we need this to
add a blktest so we can test the non-trivial I/O path from the
application to the block layer.

Signed-off-by: Chaitanya Kulkarni <[email protected]>
---
drivers/block/null_blk/main.c | 46 ++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index fc3e883f7b84..2d592b4eb815 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -420,6 +420,7 @@ NULLB_DEVICE_ATTR(blocking, bool, NULL);
NULLB_DEVICE_ATTR(use_per_node_hctx, bool, NULL);
NULLB_DEVICE_ATTR(memory_backed, bool, NULL);
NULLB_DEVICE_ATTR(discard, bool, NULL);
+NULLB_DEVICE_ATTR(write_zeroes, bool, NULL);
NULLB_DEVICE_ATTR(mbps, uint, NULL);
NULLB_DEVICE_ATTR(cache_size, ulong, NULL);
NULLB_DEVICE_ATTR(zoned, bool, NULL);
@@ -544,6 +545,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
&nullb_device_attr_power,
&nullb_device_attr_memory_backed,
&nullb_device_attr_discard,
+ &nullb_device_attr_write_zeroes,
&nullb_device_attr_mbps,
&nullb_device_attr_cache_size,
&nullb_device_attr_badblocks,
@@ -618,7 +620,7 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page)
"poll_queues,power,queue_mode,shared_tag_bitmap,size,"
"submit_queues,use_per_node_hctx,virt_boundary,zoned,"
"zone_capacity,zone_max_active,zone_max_open,"
- "zone_nr_conv,zone_size\n");
+ "zone_nr_conv,zone_size,write_zeroes\n");
}

CONFIGFS_ATTR_RO(memb_group_, features);
@@ -875,6 +877,24 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
}
}

+static void null_zero_sector(struct nullb_device *d, sector_t sect,
+ sector_t nr_sects, bool cache)
+{
+ struct radix_tree_root *root = cache ? &d->cache : &d->data;
+ struct nullb_page *t_page;
+ unsigned int offset;
+ void *dest;
+
+ t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
+ if (!t_page)
+ return;
+
+ offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
+ dest = kmap_atomic(t_page->page);
+ memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
+ kunmap_atomic(dest);
+}
+
static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
struct nullb_page *t_page, bool is_cache)
{
@@ -1191,6 +1211,27 @@ blk_status_t null_handle_discard(struct nullb_device *dev,
return BLK_STS_OK;
}

+static blk_status_t null_handle_write_zeroes(struct nullb_device *dev,
+ sector_t sector, sector_t nr_sectors)
+{
+ unsigned int bytes_left = nr_sectors << 9;
+ struct nullb *nullb = dev->nullb;
+ size_t curr_bytes;
+
+ spin_lock_irq(&nullb->lock);
+ while (bytes_left > 0) {
+ curr_bytes = min_t(size_t, bytes_left, nullb->dev->blocksize);
+ nr_sectors = curr_bytes >> SECTOR_SHIFT;
+ null_zero_sector(nullb->dev, sector, nr_sectors, false);
+ if (null_cache_active(nullb))
+ null_zero_sector(nullb->dev, sector, nr_sectors, true);
+ sector += nr_sectors;
+ bytes_left -= curr_bytes;
+ }
+ spin_unlock_irq(&nullb->lock);
+ return BLK_STS_OK;
+}
+
static int null_handle_flush(struct nullb *nullb)
{
int err;
@@ -1357,6 +1398,9 @@ static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd,
if (op == REQ_OP_DISCARD)
return null_handle_discard(dev, sector, nr_sectors);

+ if (op == REQ_OP_WRITE_ZEROES)
+ return null_handle_write_zeroes(dev, sector, nr_sectors);
+
if (dev->queue_mode == NULL_Q_BIO)
err = null_handle_bio(cmd);
else
--
2.29.0

2022-10-05 05:05:02

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH 2/6] null_blk: allow write zeores on membacked

On 10/5/22 12:16, Chaitanya Kulkarni wrote:
> Add a helper functions to enable the REQ_OP_WRITE_ZEROES operations
> when null_blk is configured with the membacked mode.
>
> Since write-zeroes is a non-trivial I/O operation we need this to
> add a blktest so we can test the non-trivial I/O path from the
> application to the block layer.

Why a separate patch for this ? Introducing the module argument and
configfs equivalent separately in 2 different patches is strange and does
not facilitate review.

This patch should be merged with patch 1.

>
> Signed-off-by: Chaitanya Kulkarni <[email protected]>
> ---
> drivers/block/null_blk/main.c | 46 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index fc3e883f7b84..2d592b4eb815 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -420,6 +420,7 @@ NULLB_DEVICE_ATTR(blocking, bool, NULL);
> NULLB_DEVICE_ATTR(use_per_node_hctx, bool, NULL);
> NULLB_DEVICE_ATTR(memory_backed, bool, NULL);
> NULLB_DEVICE_ATTR(discard, bool, NULL);
> +NULLB_DEVICE_ATTR(write_zeroes, bool, NULL);
> NULLB_DEVICE_ATTR(mbps, uint, NULL);
> NULLB_DEVICE_ATTR(cache_size, ulong, NULL);
> NULLB_DEVICE_ATTR(zoned, bool, NULL);
> @@ -544,6 +545,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
> &nullb_device_attr_power,
> &nullb_device_attr_memory_backed,
> &nullb_device_attr_discard,
> + &nullb_device_attr_write_zeroes,
> &nullb_device_attr_mbps,
> &nullb_device_attr_cache_size,
> &nullb_device_attr_badblocks,
> @@ -618,7 +620,7 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page)
> "poll_queues,power,queue_mode,shared_tag_bitmap,size,"
> "submit_queues,use_per_node_hctx,virt_boundary,zoned,"
> "zone_capacity,zone_max_active,zone_max_open,"
> - "zone_nr_conv,zone_size\n");
> + "zone_nr_conv,zone_size,write_zeroes\n");
> }
>
> CONFIGFS_ATTR_RO(memb_group_, features);
> @@ -875,6 +877,24 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
> }
> }
>
> +static void null_zero_sector(struct nullb_device *d, sector_t sect,
> + sector_t nr_sects, bool cache)
> +{
> + struct radix_tree_root *root = cache ? &d->cache : &d->data;
> + struct nullb_page *t_page;
> + unsigned int offset;
> + void *dest;
> +
> + t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
> + if (!t_page)
> + return;
> +
> + offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
> + dest = kmap_atomic(t_page->page);
> + memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
> + kunmap_atomic(dest);
> +}
> +
> static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
> struct nullb_page *t_page, bool is_cache)
> {
> @@ -1191,6 +1211,27 @@ blk_status_t null_handle_discard(struct nullb_device *dev,
> return BLK_STS_OK;
> }
>
> +static blk_status_t null_handle_write_zeroes(struct nullb_device *dev,
> + sector_t sector, sector_t nr_sectors)
> +{
> + unsigned int bytes_left = nr_sectors << 9;
> + struct nullb *nullb = dev->nullb;
> + size_t curr_bytes;
> +
> + spin_lock_irq(&nullb->lock);
> + while (bytes_left > 0) {
> + curr_bytes = min_t(size_t, bytes_left, nullb->dev->blocksize);
> + nr_sectors = curr_bytes >> SECTOR_SHIFT;
> + null_zero_sector(nullb->dev, sector, nr_sectors, false);
> + if (null_cache_active(nullb))
> + null_zero_sector(nullb->dev, sector, nr_sectors, true);
> + sector += nr_sectors;
> + bytes_left -= curr_bytes;
> + }
> + spin_unlock_irq(&nullb->lock);
> + return BLK_STS_OK;
> +}
> +
> static int null_handle_flush(struct nullb *nullb)
> {
> int err;
> @@ -1357,6 +1398,9 @@ static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd,
> if (op == REQ_OP_DISCARD)
> return null_handle_discard(dev, sector, nr_sectors);
>
> + if (op == REQ_OP_WRITE_ZEROES)
> + return null_handle_write_zeroes(dev, sector, nr_sectors);
> +
> if (dev->queue_mode == NULL_Q_BIO)
> err = null_handle_bio(cmd);
> else

--
Damien Le Moal
Western Digital Research

2022-10-05 05:42:20

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: [PATCH 2/6] null_blk: allow write zeores on membacked

On 10/4/22 21:57, Damien Le Moal wrote:
> On 10/5/22 12:16, Chaitanya Kulkarni wrote:
>> Add a helper functions to enable the REQ_OP_WRITE_ZEROES operations
>> when null_blk is configured with the membacked mode.
>>
>> Since write-zeroes is a non-trivial I/O operation we need this to
>> add a blktest so we can test the non-trivial I/O path from the
>> application to the block layer.
>
> Why a separate patch for this ? Introducing the module argument and
> configfs equivalent separately in 2 different patches is strange and does
> not facilitate review.
>
> This patch should be merged with patch 1.
>

Sounds good will merge it.

-ck


2022-10-05 17:45:11

by Brian Foster

[permalink] [raw]
Subject: Re: [PATCH 2/6] null_blk: allow write zeores on membacked

On Tue, Oct 04, 2022 at 08:16:57PM -0700, Chaitanya Kulkarni wrote:
> Add a helper functions to enable the REQ_OP_WRITE_ZEROES operations
> when null_blk is configured with the membacked mode.
>
> Since write-zeroes is a non-trivial I/O operation we need this to
> add a blktest so we can test the non-trivial I/O path from the
> application to the block layer.
>
> Signed-off-by: Chaitanya Kulkarni <[email protected]>
> ---
> drivers/block/null_blk/main.c | 46 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index fc3e883f7b84..2d592b4eb815 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
...
> @@ -875,6 +877,24 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
> }
> }
>
> +static void null_zero_sector(struct nullb_device *d, sector_t sect,
> + sector_t nr_sects, bool cache)
> +{

Any reason to not just pass the tree root directly here instead of the
cache boolean? It might make the callers more readable and also
eliminates the need to pass the nullb_device.

Brian

> + struct radix_tree_root *root = cache ? &d->cache : &d->data;
> + struct nullb_page *t_page;
> + unsigned int offset;
> + void *dest;
> +
> + t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
> + if (!t_page)
> + return;
> +
> + offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
> + dest = kmap_atomic(t_page->page);
> + memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
> + kunmap_atomic(dest);
> +}
> +
> static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
> struct nullb_page *t_page, bool is_cache)
> {
...