public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Chaitanya Kulkarni <kch@nvidia.com>
Cc: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"axboe@kernel.dk" <axboe@kernel.dk>,
	"damien.lemoal@opensource.wdc.com"
	<damien.lemoal@opensource.wdc.com>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	"vincent.fu@samsung.com" <vincent.fu@samsung.com>
Subject: Re: [PATCH V4 1/8] null_blk: allow REQ_OP_WRITE_ZEROES
Date: Wed, 30 Nov 2022 07:59:32 +0000	[thread overview]
Message-ID: <20221130075932.nfbxiixykfpxrweh@shindev> (raw)
In-Reply-To: <20221129232813.37968-2-kch@nvidia.com>

On Nov 29, 2022 / 15:28, Chaitanya Kulkarni wrote:
> Add a helper function to enable the REQ_OP_WRITE_ZEROES operations
> when null_blk.
> 
> 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 <kch@nvidia.com>

This motivation sounds good. I tried this patch. With a quick test it looks
working good for me. Please find minor comments in line.

[...]

> +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);
> +}

Did you consider to call null_lookup_page() for __null_lookup_page() from
null_zero_sector()? It may simplify this function a bit.

> +
>  static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
>  	struct nullb_page *t_page, bool is_cache)
>  {
> @@ -1186,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;
> @@ -1352,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
> @@ -1800,6 +1849,13 @@ static void null_config_discard(struct nullb *nullb)
>  	blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9);
>  }
>  
> +static void null_config_write_zeroes(struct nullb *nullb)
> +{
> +	if (!nullb->dev->write_zeroes)
> +		return;
> +	blk_queue_max_write_zeroes_sectors(nullb->q, UINT_MAX >> 9);

Just comment: this value UINT_MAX >> 9 sounds a bit weird, but probably ok. This
value was introduced by commit 306eb6b4ad4f ("nullb: support discard") to call
blk_queue_max_discard_sectors(). I guess you chose the same value for write
zeroes.

> +}
> +
>  static const struct block_device_operations null_bio_ops = {
>  	.owner		= THIS_MODULE,
>  	.submit_bio	= null_submit_bio,
> @@ -2111,6 +2167,7 @@ static int null_add_dev(struct nullb_device *dev)
>  		blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1);
>  
>  	null_config_discard(nullb);
> +	null_config_write_zeroes(nullb);
>  
>  	if (config_item_name(&dev->item)) {
>  		/* Use configfs dir name as the device name */
> diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h
> index 94ff68052b1e..2c0c9c29158f 100644
> --- a/drivers/block/null_blk/null_blk.h
> +++ b/drivers/block/null_blk/null_blk.h
> @@ -111,6 +111,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 */
>  	bool virt_boundary; /* virtual boundary on/off for the device */
>  	bool no_sched; /* no IO scheduler for the device */
> -- 
> 2.29.0
> 

-- 
Shin'ichiro Kawasaki

  reply	other threads:[~2022-11-30  7:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 23:28 [PATCH V4 0/7] null_blk: allow REQ_OP_WRITE_ZEROES and cleanup Chaitanya Kulkarni
2022-11-29 23:28 ` [PATCH V4 1/8] null_blk: allow REQ_OP_WRITE_ZEROES Chaitanya Kulkarni
2022-11-30  7:59   ` Shinichiro Kawasaki [this message]
2022-11-30 23:29     ` Chaitanya Kulkarni
2022-12-01  1:21       ` Shinichiro Kawasaki
2022-11-29 23:28 ` [PATCH V4 2/8] null_blk: code cleaup Chaitanya Kulkarni
2022-11-30  8:00   ` Shinichiro Kawasaki
2022-11-29 23:28 ` [PATCH V4 3/8] null_blk: initialize cmd->bio in __alloc_cmd() Chaitanya Kulkarni
2022-11-30  8:01   ` Shinichiro Kawasaki
2022-11-29 23:28 ` [PATCH V4 4/8] null_blk: don't use magic numbers in the code Chaitanya Kulkarni
2022-11-29 23:28 ` [PATCH V4 5/8] null_blk: remove extra space in switch condition Chaitanya Kulkarni
2022-11-29 23:28 ` [PATCH V4 6/8] null_blk: add param to set max disacrd sectors Chaitanya Kulkarni
2022-11-30  8:07   ` Shinichiro Kawasaki
2022-11-29 23:28 ` [PATCH V4 7/8] null_blk: add param to set max write-zeroes sects Chaitanya Kulkarni
2022-11-30  8:09   ` Shinichiro Kawasaki
2022-11-29 23:28 ` [PATCH V4 8/8] null-blk: allow REQ_OP_ZONE_RESET_ALL to configure Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221130075932.nfbxiixykfpxrweh@shindev \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vincent.fu@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox