linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: keith.busch@intel.com (Keith Busch)
Subject: [PATCH 2/5] block: add support for REQ_OP_WRITE_ZEROES
Date: Wed, 16 Nov 2016 12:59:07 -0500	[thread overview]
Message-ID: <20161116175906.GA10050@localhost.localdomain> (raw)
In-Reply-To: <1479279039-25818-3-git-send-email-chaitanya.kulkarni@hgst.com>

On Tue, Nov 15, 2016@10:50:36PM -0800, Chaitanya Kulkarni wrote:
> This adds a new block layer operation to zero out a range of
> LBAs. This allows to implement zeroing for devices that don't use
> either discard with a predictable zero pattern or WRITE SAME of zeroes.
> The prominent example of that is NVMe with the Write Zeroes command,
> but in the future this should also help with improving the way
> zeroing discards work.
> 
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at hgst.com>
> ---

> +static int __blkdev_issue_write_zeroes(struct block_device *bdev,
> +		sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
> +		struct bio **biop)
> +{
> +	struct bio *bio = *biop;
> +	unsigned int max_write_zeroes_sectors;
> +	struct request_queue *q = bdev_get_queue(bdev);
> +
> +	if (!q)
> +		return -ENXIO;
> +
> +	if (!blk_queue_write_zeroes(q))
> +		return -EOPNOTSUPP;
> +
> +	/* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */
> +	max_write_zeroes_sectors = UINT_MAX >> 9;
> +
> +	while (nr_sects) {
> +		bio = next_bio(bio, 0, gfp_mask);
> +		bio->bi_iter.bi_sector = sector;
> +		bio->bi_bdev = bdev;
> +		bio_set_op_attrs(bio, REQ_OP_WRITE_ZEROES, 0);
> +
> +		if (nr_sects > max_write_zeroes_sectors) {
> +			bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;

Your maximum bi_size exceeds the 2-bytes an NVMe Write Zeroes command
provides for the block count. Instead of having a simple queue flag
for write zeroes support, have it take a max sectors value instead. I
proposed this here a couple years ago (though I goof'ed registering the
nvme part...):

  http://lists.infradead.org/pipermail/linux-nvme/2014-July/001054.html

  reply	other threads:[~2016-11-16 17:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16  6:50 [PATCHSET] Add support for write zeroes operation in Block layer and NVMe Driver Chaitanya Kulkarni
2016-11-16  6:50 ` [PATCH 1/5] block: add async variant of blkdev_issue_zeroout Chaitanya Kulkarni
2016-11-17 10:29   ` Christoph Hellwig
2016-11-16  6:50 ` [PATCH 2/5] block: add support for REQ_OP_WRITE_ZEROES Chaitanya Kulkarni
2016-11-16 17:59   ` Keith Busch [this message]
2016-11-17  2:48     ` Martin K. Petersen
2016-11-17 22:28       ` chaitany kulkarni
2016-11-16  6:50 ` [PATCH 4/5] nvme: add support for the Write Zeroes command Chaitanya Kulkarni
2016-11-16 16:48   ` Sagi Grimberg
2016-11-16  6:50 ` [PATCH 5/5] nvmet: " Chaitanya Kulkarni
2016-11-16 16:47   ` Sagi Grimberg
2016-11-17 10:28     ` Christoph Hellwig
2016-11-17 10:28   ` Christoph Hellwig

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=20161116175906.GA10050@localhost.localdomain \
    --to=keith.busch@intel.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;
as well as URLs for NNTP newsgroup(s).