All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] null_blk: add missing write-zeroes and discard support
@ 2019-07-11 17:53 Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 18309 bytes --]

Hi,

This patch series focusses on adding the support for:-                                                                   
1. Memory backed REQ_OP_WRITE_ZEROES through configfs.
2. Non Memory backed REQ_OP_DISCARD through module parameter.
3. Non Memory backed REQ_OP_WRITE_ZEROES through module parameter.

While the development of the blktrace extension, this support turned
out  to be useful in the debugging and discovering the various
scenarios when dealing with special REQ_OP_XXX (DISCARD, WRITE_ZEROES).

Also, for block layer in the blktests, we are missing the tests for 
write-zeroes. With this support now we can add tests so developers can
ensure that any change(s) to the I/O path is not breaking the special
REQ_OP_XXX without actually depending on the supporting controller and
the respective driver.

With this support, I sign-up for writing the testcases for the
REQ_OP_WRITE_ZEROES with memory backed null_blk as soon as this series
goes upstream in the blktests.

If anyone is interested please find the testing log at the end.

Regards,
Chaitanya

Chaitanya Kulkarni (8):
  null_blk: add module parameter for REQ_OP_DISCARD
  null_blk: add REQ_OP_WRITE_ZEROES config property
  null_blk: add support for write-zeroes
  null_blk: allow memory-backed write-zeroes-req
  null_blk: code cleaup
  null_blk: allow memory-backed write-zeroes-bio
  null_blk: add support for configfs write_zeroes
  null_blk: adjusts the code with latest changes

 drivers/block/null_blk.h      |   1 +
 drivers/block/null_blk_main.c | 125 +++++++++++++++++++++++++++-------
 2 files changed, 102 insertions(+), 24 deletions(-)

# Test log :-

Simple Test log for changing the block size and enabling the
write-zeroes with null_blk memory backed :-

######################BLKISZ 512#######################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── mbps
├── memory_backed
├── power
├── queue_mode
├── size
├── submit_queues
├── use_per_node_hctx
├── write_zeroes
├── zoned
├── zone_nr_conv
└── zone_size

0 directories, 21 files
ODD:- 
20+0 records in
20+0 records out
10240 bytes (10 kB) copied, 0.00120115 s, 8.5 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:- 
20+0 records in
20+0 records out
10240 bytes (10 kB) copied, 0.00118618 s, 8.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
├── mbps
├── memory_backed
├── power
├── queue_mode
├── size
├── submit_queues
├── use_per_node_hctx
├── write_zeroes
├── zoned
├── zone_nr_conv
└── zone_size

0 directories, 21 files
ODD:- 
20+0 records in
20+0 records out
20480 bytes (20 kB) copied, 0.00134839 s, 15.2 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:- 
20+0 records in
20+0 records out
20480 bytes (20 kB) copied, 0.0012485 s, 16.4 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
├── mbps
├── memory_backed
├── power
├── queue_mode
├── size
├── submit_queues
├── use_per_node_hctx
├── write_zeroes
├── zoned
├── zone_nr_conv
└── zone_size

0 directories, 21 files
ODD:- 
20+0 records in
20+0 records out
40960 bytes (41 kB) copied, 0.00161901 s, 25.3 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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0010256
0012288   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0014336   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0014352
0016384   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0018432   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0014336  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0014352
0016384   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0018432  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0018448
------------------------------------------------------
EVEN:- 
20+0 records in
20+0 records out
40960 bytes (41 kB) copied, 0.00180328 s, 22.7 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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0010256
0012288   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0014336   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0014352
0016384   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0018432   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0010256
0012288  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0012304
0014336   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0014352
0016384  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0016400
0018432   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0018448
------------------------------------------------------




######################BLKISZ 4096#######################
config/nullb/nullb0
├── badblocks
├── blocking
├── blocksize
├── cache_size
├── completion_nsec
├── discard
├── home_node
├── hw_queue_depth
├── index
├── irqmode
├── mbps
├── memory_backed
├── power
├── queue_mode
├── size
├── submit_queues
├── use_per_node_hctx
├── write_zeroes
├── zoned
├── zone_nr_conv
└── zone_size

0 directories, 21 files
ODD:- 
16+1 records in
16+1 records out
65537 bytes (66 kB) copied, 0.00140571 s, 46.6 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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0016384   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0020480   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0020496
0024576   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0024592
0028672   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0028688
0032768   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0032784
0036864   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0020480  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0020496
0024576   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0024592
0028672  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0028688
0032768   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0032784
0036864  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0036880
------------------------------------------------------
EVEN:- 
16+1 records in
16+1 records out
65537 bytes (66 kB) copied, 0.00123278 s, 53.2 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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0016384   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0016400
0020480   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0020496
0024576   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0024592
0028672   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0028688
0032768   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0032784
0036864   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
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   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0012304
0016384  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0016400
0020480   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0020496
0024576  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0024592
0028672   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0028688
0032768  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0032784
0036864   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a   a
0036880
------------------------------------------------------
-- 
2.17.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:04   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This patch adds a module parameter to configure the REQ_OP_DISCARD
handling support when null_blk module is not memory-backed. This support
is useful in the various scenarios such as examining REQ_OP_DISCARD path
tests, blktrace and discard with priorities.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 99328ded60d1..20d60b951622 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -3,6 +3,7 @@
  * Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
  * Shaohua Li <shli@fb.com>
  */
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 #include <linux/module.h>
 
 #include <linux/moduleparam.h>
@@ -193,6 +194,10 @@ static unsigned int g_zone_nr_conv;
 module_param_named(zone_nr_conv, g_zone_nr_conv, uint, 0444);
 MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones when block device is zoned. Default: 0");
 
+static bool g_discard;
+module_param_named(discard, g_discard, bool, 0444);
+MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
+
 static struct nullb_device *null_alloc_dev(void);
 static void null_free_dev(struct nullb_device *dev);
 static void null_del_dev(struct nullb *nullb);
@@ -529,6 +534,8 @@ static struct nullb_device *null_alloc_dev(void)
 	dev->zoned = g_zoned;
 	dev->zone_size = g_zone_size;
 	dev->zone_nr_conv = g_zone_nr_conv;
+	dev->discard = g_discard;
+	pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
 	return dev;
 }
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:17   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This is a preparation patch for implementing the support for the
write-zeroes operations for null_blk. We introduce a new bool flag
write-zeroes for nullb_device structure so that user can either set
this value through configfs when null_blk is memory backed or use
module parameter. Following two patches are implementing respective
support for REQ_OP_WRITE_ZEROES.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h
index 34b22d6523ba..ecd1e45f6eb9 100644
--- a/drivers/block/null_blk.h
+++ b/drivers/block/null_blk.h
@@ -63,6 +63,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 write_zeroes; /* if support write_zeroes */
 	bool zoned; /* if device is zoned */
 };
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/8] null_blk: add support for write-zeroes
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:08   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This patch adds support to execute REQ_OP_WRITE_ZEROES operations on
the null_blk device when device is not memory-backed. Just like
REQ_OP_DISCARD we add a new module parameter to enable this support.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 20d60b951622..65da7c2d93b9 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -198,6 +198,10 @@ static bool g_discard;
 module_param_named(discard, g_discard, bool, 0444);
 MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
 
+static bool g_write_zeroes;
+module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
+MODULE_PARM_DESC(write_zeroes, "Allow REQ_OP_WRITE_ZEROES processing. Default: false");
+
 static struct nullb_device *null_alloc_dev(void);
 static void null_free_dev(struct nullb_device *dev);
 static void null_del_dev(struct nullb *nullb);
@@ -535,7 +539,10 @@ static struct nullb_device *null_alloc_dev(void)
 	dev->zone_size = g_zone_size;
 	dev->zone_nr_conv = g_zone_nr_conv;
 	dev->discard = g_discard;
+	dev->write_zeroes = g_write_zeroes;
 	pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
+	pr_info("write-zeroes : %s\n", dev->write_zeroes ? "TRUE" : "FALSE");
+
 	return dev;
 }
 
@@ -1419,6 +1426,13 @@ static void null_config_discard(struct nullb *nullb)
 	blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
 }
 
+static void null_config_write_zeroes(struct nullb *nullb)
+{
+	if (nullb->dev->write_zeroes == false)
+		return;
+	blk_queue_max_write_zeroes_sectors(nullb->q, UINT_MAX >> SECTOR_SHIFT);
+}
+
 static int null_open(struct block_device *bdev, fmode_t mode)
 {
 	return 0;
@@ -1710,6 +1724,7 @@ static int null_add_dev(struct nullb_device *dev)
 	blk_queue_physical_block_size(nullb->q, dev->blocksize);
 
 	null_config_discard(nullb);
+	null_config_write_zeroes(nullb);
 
 	sprintf(nullb->disk_name, "nullb%d", nullb->index);
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:11   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This patch adds support for memory backed REQ_OP_WRITE_ZEROES
operations for the null_blk request mode. We introduce two new
functions where we zeroout the sector(s) using memset which are part
of the payloadless write-zeroes request.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 45 ++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 65da7c2d93b9..fca011a05277 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -725,6 +725,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)
 {
@@ -1026,6 +1044,25 @@ static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n)
 	spin_unlock_irq(&nullb->lock);
 }
 
+static void null_handle_write_zeroes(struct nullb *nullb, sector_t sector,
+				     unsigned int bytes_left)
+{
+	sector_t nr_sectors;
+	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);
+}
+
 static int null_handle_flush(struct nullb *nullb)
 {
 	int err;
@@ -1075,9 +1112,15 @@ static int null_handle_rq(struct nullb_cmd *cmd)
 
 	sector = blk_rq_pos(rq);
 
-	if (req_op(rq) == REQ_OP_DISCARD) {
+	switch (req_op(rq)) {
+	case REQ_OP_DISCARD:
 		null_handle_discard(nullb, sector, blk_rq_bytes(rq));
 		return 0;
+	case REQ_OP_WRITE_ZEROES:
+		null_handle_write_zeroes(nullb, sector, blk_rq_bytes(rq));
+		return 0;
+	default:
+		break;
 	}
 
 	spin_lock_irq(&nullb->lock);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/8] null_blk: code cleaup
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:12   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

In the null_blk for different page and sector calculation we have
simple macros to make the code more redable.

Similar to that this is a purely code cleanup patch where we
introduce two new macros for calculating the page index from given
sector and index (offset) of the sector in the page.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 37 ++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index fca011a05277..d463bde001b6 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -16,6 +16,11 @@
 #define PAGE_SECTORS		(1 << PAGE_SECTORS_SHIFT)
 #define SECTOR_MASK		(PAGE_SECTORS - 1)
 
+/* Gives page index for which this sector belongs to. */
+#define PAGE_IDX_FROM_SECT(sect)	(sect >> PAGE_SECTORS_SHIFT)
+/* Gives index (offset) of the sector within page. */
+#define SECT_IDX_IN_PAGE(sect)		((sect & SECTOR_MASK) << SECTOR_SHIFT)
+
 #define FREE_BATCH		16
 
 #define TICKS_PER_SEC		50ULL
@@ -708,20 +713,20 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
 	struct radix_tree_root *root;
 
 	root = is_cache ? &nullb->dev->cache : &nullb->dev->data;
-	idx = sector >> PAGE_SECTORS_SHIFT;
+	idx = PAGE_IDX_FROM_SECT(sector);
 	sector_bit = (sector & SECTOR_MASK);
 
 	t_page = radix_tree_lookup(root, idx);
-	if (t_page) {
-		__clear_bit(sector_bit, t_page->bitmap);
-
-		if (null_page_empty(t_page)) {
-			ret = radix_tree_delete_item(root, idx, t_page);
-			WARN_ON(ret != t_page);
-			null_free_page(ret);
-			if (is_cache)
-				nullb->dev->curr_cache -= PAGE_SIZE;
-		}
+	if (!t_page)
+		return;
+	__clear_bit(sector_bit, t_page->bitmap);
+
+	if (null_page_empty(t_page)) {
+		ret = radix_tree_delete_item(root, idx, t_page);
+		WARN_ON(ret != t_page);
+		null_free_page(ret);
+		if (is_cache)
+			nullb->dev->curr_cache -= PAGE_SIZE;
 	}
 }
 
@@ -733,11 +738,11 @@ static void null_zero_sector(struct nullb_device *d, sector_t sect,
 	unsigned int offset;
 	void *dest;
 
-	t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
+	t_page = radix_tree_lookup(root, PAGE_IDX_FROM_SECT(sect));
 	if (!t_page)
 		return;
 
-	offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
+	offset = SECT_IDX_IN_PAGE(sect);
 	dest = kmap_atomic(t_page->page);
 	memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
 	kunmap_atomic(dest);
@@ -797,7 +802,7 @@ static struct nullb_page *__null_lookup_page(struct nullb *nullb,
 	struct nullb_page *t_page;
 	struct radix_tree_root *root;
 
-	idx = sector >> PAGE_SECTORS_SHIFT;
+	idx = PAGE_IDX_FROM_SECT(sector);
 	sector_bit = (sector & SECTOR_MASK);
 
 	root = is_cache ? &nullb->dev->cache : &nullb->dev->data;
@@ -973,7 +978,7 @@ static int copy_to_nullb(struct nullb *nullb, struct page *source,
 		if (null_cache_active(nullb) && !is_fua)
 			null_make_cache_space(nullb, PAGE_SIZE);
 
-		offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+		offset = SECT_IDX_IN_PAGE(sector);
 		t_page = null_insert_page(nullb, sector,
 			!null_cache_active(nullb) || is_fua);
 		if (!t_page)
@@ -1007,7 +1012,7 @@ static int copy_from_nullb(struct nullb *nullb, struct page *dest,
 	while (count < n) {
 		temp = min_t(size_t, nullb->dev->blocksize, n - count);
 
-		offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+		offset = SECT_IDX_IN_PAGE(sector);
 		t_page = null_lookup_page(nullb, sector, false,
 			!null_cache_active(nullb));
 
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
                   ` (4 preceding siblings ...)
  2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-28  6:18   ` Minwoo Im
  2019-07-11 17:53 ` [PATCH 7/8] null_blk: add support for configfs write_zeroes Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 8/8] null_blk: adjusts the code with latest changes Chaitanya Kulkarni
  7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This patch adds support for memory backed REQ_OP_WRITE_ZEROES
operations for the null_blk bio mode.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index d463bde001b6..30cb90553167 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1147,6 +1147,7 @@ static int null_handle_rq(struct nullb_cmd *cmd)
 
 static int null_handle_bio(struct nullb_cmd *cmd)
 {
+	unsigned int blk_bio_bytes = bio_sectors(cmd->bio) << SECTOR_SHIFT;
 	struct bio *bio = cmd->bio;
 	struct nullb *nullb = cmd->nq->dev->nullb;
 	int err;
@@ -1157,10 +1158,15 @@ static int null_handle_bio(struct nullb_cmd *cmd)
 
 	sector = bio->bi_iter.bi_sector;
 
-	if (bio_op(bio) == REQ_OP_DISCARD) {
-		null_handle_discard(nullb, sector,
-			bio_sectors(bio) << SECTOR_SHIFT);
+	switch (bio_op(bio)) {
+	case REQ_OP_DISCARD:
+		null_handle_discard(nullb, sector, blk_bio_bytes);
+		return 0;
+	case REQ_OP_WRITE_ZEROES:
+		null_handle_write_zeroes(nullb, sector, blk_bio_bytes);
 		return 0;
+	default:
+		break;
 	}
 
 	spin_lock_irq(&nullb->lock);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7/8] null_blk: add support for configfs write_zeroes
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
                   ` (5 preceding siblings ...)
  2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  2019-07-11 17:53 ` [PATCH 8/8] null_blk: adjusts the code with latest changes Chaitanya Kulkarni
  7 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

This patch adds a new configfs parameter to enable REQ_OP_WRITE_ZEROES
feature for null_blk similar to REQ_OP_DISCARD when device is memory
backed.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 30cb90553167..c734ddaa697f 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -308,6 +308,7 @@ NULLB_DEVICE_ATTR(blocking, bool);
 NULLB_DEVICE_ATTR(use_per_node_hctx, bool);
 NULLB_DEVICE_ATTR(memory_backed, bool);
 NULLB_DEVICE_ATTR(discard, bool);
+NULLB_DEVICE_ATTR(write_zeroes, bool);
 NULLB_DEVICE_ATTR(mbps, uint);
 NULLB_DEVICE_ATTR(cache_size, ulong);
 NULLB_DEVICE_ATTR(zoned, bool);
@@ -423,6 +424,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,
@@ -481,7 +483,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
 
 static ssize_t memb_group_features_show(struct config_item *item, char *page)
 {
-	return snprintf(page, PAGE_SIZE, "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size\n");
+	return snprintf(page, PAGE_SIZE, "memory_backed,discard,write_zeroes,bandwidth,cache,badblocks,zoned,zone_size\n");
 }
 
 CONFIGFS_ATTR_RO(memb_group_, features);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 8/8] null_blk: adjusts the code with latest changes
  2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
                   ` (6 preceding siblings ...)
  2019-07-11 17:53 ` [PATCH 7/8] null_blk: add support for configfs write_zeroes Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
  7 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni

Now that we have support for more than on special operations
REQ_OP_DISCARD and REQ_OP_WRITE_ZEROES create a helper to isolate the
code common code.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/block/null_blk_main.c | 41 +++++++++++++++++------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index c734ddaa697f..f59a05bcf56f 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1107,28 +1107,36 @@ static int null_transfer(struct nullb *nullb, struct page *page,
 	return err;
 }
 
+static inline bool null_handle_special_op(struct nullb *nullb, sector_t sector,
+					  unsigned int bytes, enum req_opf op)
+{
+	switch (op) {
+	case REQ_OP_DISCARD:
+		null_handle_discard(nullb, sector, bytes);
+		return true;
+	case REQ_OP_WRITE_ZEROES:
+		null_handle_write_zeroes(nullb, sector, bytes);
+		return true;
+	default:
+		break;
+	}
+	return false;
+}
+
 static int null_handle_rq(struct nullb_cmd *cmd)
 {
 	struct request *rq = cmd->rq;
 	struct nullb *nullb = cmd->nq->dev->nullb;
 	int err;
-	unsigned int len;
+	unsigned int len = blk_rq_bytes(rq);
 	sector_t sector;
 	struct req_iterator iter;
 	struct bio_vec bvec;
 
 	sector = blk_rq_pos(rq);
 
-	switch (req_op(rq)) {
-	case REQ_OP_DISCARD:
-		null_handle_discard(nullb, sector, blk_rq_bytes(rq));
+	if (null_handle_special_op(nullb, sector, len, req_op(rq)))
 		return 0;
-	case REQ_OP_WRITE_ZEROES:
-		null_handle_write_zeroes(nullb, sector, blk_rq_bytes(rq));
-		return 0;
-	default:
-		break;
-	}
 
 	spin_lock_irq(&nullb->lock);
 	rq_for_each_segment(bvec, rq, iter) {
@@ -1149,27 +1157,18 @@ static int null_handle_rq(struct nullb_cmd *cmd)
 
 static int null_handle_bio(struct nullb_cmd *cmd)
 {
-	unsigned int blk_bio_bytes = bio_sectors(cmd->bio) << SECTOR_SHIFT;
+	unsigned int len = bio_sectors(cmd->bio) << SECTOR_SHIFT;
 	struct bio *bio = cmd->bio;
 	struct nullb *nullb = cmd->nq->dev->nullb;
 	int err;
-	unsigned int len;
 	sector_t sector;
 	struct bio_vec bvec;
 	struct bvec_iter iter;
 
 	sector = bio->bi_iter.bi_sector;
 
-	switch (bio_op(bio)) {
-	case REQ_OP_DISCARD:
-		null_handle_discard(nullb, sector, blk_bio_bytes);
+	if (null_handle_special_op(nullb, sector, len, bio_op(bio)))
 		return 0;
-	case REQ_OP_WRITE_ZEROES:
-		null_handle_write_zeroes(nullb, sector, blk_bio_bytes);
-		return 0;
-	default:
-		break;
-	}
 
 	spin_lock_irq(&nullb->lock);
 	bio_for_each_segment(bvec, bio, iter) {
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
  2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
@ 2019-07-28  6:04   ` Minwoo Im
  2019-07-30  4:48     ` Chaitanya Kulkarni
  0 siblings, 1 reply; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:04 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

Hi Chaitanya,

On 19-07-11 10:53:21, Chaitanya Kulkarni wrote:
> This patch adds a module parameter to configure the REQ_OP_DISCARD
> handling support when null_blk module is not memory-backed. This support
> is useful in the various scenarios such as examining REQ_OP_DISCARD path
> tests, blktrace and discard with priorities.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/null_blk_main.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 99328ded60d1..20d60b951622 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -3,6 +3,7 @@
>   * Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
>   * Shaohua Li <shli@fb.com>
>   */
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Maybe it casue other pr_ family prints "null_blk" twice, doesn't it?  If
so, can we have this change with the other pr_ family updated?

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/8] null_blk: add support for write-zeroes
  2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
@ 2019-07-28  6:08   ` Minwoo Im
  0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:08 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

On 19-07-11 10:53:23, Chaitanya Kulkarni wrote:
> This patch adds support to execute REQ_OP_WRITE_ZEROES operations on
> the null_blk device when device is not memory-backed. Just like
> REQ_OP_DISCARD we add a new module parameter to enable this support.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/null_blk_main.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 20d60b951622..65da7c2d93b9 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -198,6 +198,10 @@ static bool g_discard;
>  module_param_named(discard, g_discard, bool, 0444);
>  MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
>  
> +static bool g_write_zeroes;
> +module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
> +MODULE_PARM_DESC(write_zeroes, "Allow REQ_OP_WRITE_ZEROES processing. Default: false");
> +
>  static struct nullb_device *null_alloc_dev(void);
>  static void null_free_dev(struct nullb_device *dev);
>  static void null_del_dev(struct nullb *nullb);
> @@ -535,7 +539,10 @@ static struct nullb_device *null_alloc_dev(void)
>  	dev->zone_size = g_zone_size;
>  	dev->zone_nr_conv = g_zone_nr_conv;
>  	dev->discard = g_discard;
> +	dev->write_zeroes = g_write_zeroes;
>  	pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
> +	pr_info("write-zeroes : %s\n", dev->write_zeroes ? "TRUE" : "FALSE");
> +
>  	return dev;
>  }
>  
> @@ -1419,6 +1426,13 @@ static void null_config_discard(struct nullb *nullb)
>  	blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
>  }
>  
> +static void null_config_write_zeroes(struct nullb *nullb)
> +{
> +	if (nullb->dev->write_zeroes == false)

Can this trivial one for the style like the others in this module ?
	if (!nullb->dev->write_zeroes)

Besides that it looks good to me :)

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req
  2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
@ 2019-07-28  6:11   ` Minwoo Im
  0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:11 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

On 19-07-11 10:53:24, Chaitanya Kulkarni wrote:
> This patch adds support for memory backed REQ_OP_WRITE_ZEROES
> operations for the null_blk request mode. We introduce two new
> functions where we zeroout the sector(s) using memset which are part
> of the payloadless write-zeroes request.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  drivers/block/null_blk_main.c | 45 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 65da7c2d93b9..fca011a05277 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -725,6 +725,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)
>  {
> @@ -1026,6 +1044,25 @@ static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n)
>  	spin_unlock_irq(&nullb->lock);
>  }
>  
> +static void null_handle_write_zeroes(struct nullb *nullb, sector_t sector,
> +				     unsigned int bytes_left)
> +{
> +	sector_t nr_sectors;
> +	size_t curr_bytes;
> +
> +	spin_lock_irq(&nullb->lock);
> +	while (bytes_left > 0) {

Hi Chaitanya,

Thanks for your support for this!

I have a simple query here.  Is there any recommended rule about using
the function argument to be changed inside of that function like
_bytes_left_?  I'm not against it, but I'd like to know if it's okay to
decrement inside of this function in code-style point-of-view.

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/8] null_blk: code cleaup
  2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
@ 2019-07-28  6:12   ` Minwoo Im
  0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:12 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

On 19-07-11 10:53:25, Chaitanya Kulkarni wrote:
> In the null_blk for different page and sector calculation we have
> simple macros to make the code more redable.
                                      ^^^^^^^
Maybe someone can take care of this in any step :) s/redable/readable/

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property
  2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
@ 2019-07-28  6:17   ` Minwoo Im
  0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:17 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

On 19-07-11 10:53:22, Chaitanya Kulkarni wrote:
> This is a preparation patch for implementing the support for the
> write-zeroes operations for null_blk. We introduce a new bool flag
> write-zeroes for nullb_device structure so that user can either set
> this value through configfs when null_blk is memory backed or use
> module parameter. Following two patches are implementing respective
> support for REQ_OP_WRITE_ZEROES.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

Hi Chaitanya,

It looks good to be squashed with 3rd patch.  Code looks good to me.

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio
  2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
@ 2019-07-28  6:18   ` Minwoo Im
  0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28  6:18 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im

On 19-07-11 10:53:26, Chaitanya Kulkarni wrote:
> This patch adds support for memory backed REQ_OP_WRITE_ZEROES
> operations for the null_blk bio mode.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

Hi Chaitanya,

This patch looks like good to me merged with 4th patch which is about
the null_handle_rq().  I think it would be great if a commit covers the
actual callers for those introduced.  But code looks good to me :)

Thanks!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
  2019-07-28  6:04   ` Minwoo Im
@ 2019-07-30  4:48     ` Chaitanya Kulkarni
  0 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-30  4:48 UTC (permalink / raw)
  To: Minwoo Im; +Cc: linux-block, axboe, hch

On 7/27/19 11:04 PM, Minwoo Im wrote:
> Hi Chaitanya,
>
> On 19-07-11 10:53:21, Chaitanya Kulkarni wrote:
>> This patch adds a module parameter to configure the REQ_OP_DISCARD
>> handling support when null_blk module is not memory-backed. This support
>> is useful in the various scenarios such as examining REQ_OP_DISCARD path
>> tests, blktrace and discard with priorities.
>>
>> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
>> ---
>>  drivers/block/null_blk_main.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
>> index 99328ded60d1..20d60b951622 100644
>> --- a/drivers/block/null_blk_main.c
>> +++ b/drivers/block/null_blk_main.c
>> @@ -3,6 +3,7 @@
>>   * Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
>>   * Shaohua Li <shli@fb.com>
>>   */
>> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> Maybe it casue other pr_ family prints "null_blk" twice, doesn't it?  If
> so, can we have this change with the other pr_ family updated?
>
> Thanks!
>
Okay, I'll add this in next version.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-07-30  4:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
2019-07-28  6:04   ` Minwoo Im
2019-07-30  4:48     ` Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
2019-07-28  6:17   ` Minwoo Im
2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
2019-07-28  6:08   ` Minwoo Im
2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
2019-07-28  6:11   ` Minwoo Im
2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
2019-07-28  6:12   ` Minwoo Im
2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
2019-07-28  6:18   ` Minwoo Im
2019-07-11 17:53 ` [PATCH 7/8] null_blk: add support for configfs write_zeroes Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 8/8] null_blk: adjusts the code with latest changes Chaitanya Kulkarni

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.