All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: axboe@kernel.dk, martin.petersen@oracle.com, agk@redhat.com,
	snitzer@redhat.com, shli@kernel.org, philipp.reisner@linbit.com,
	lars.ellenberg@linbit.com
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	drbd-dev@lists.linbit.com, dm-devel@redhat.com,
	linux-raid@vger.kernel.org
Subject: [PATCH 05/23] dm: support REQ_OP_WRITE_ZEROES
Date: Thu, 23 Mar 2017 10:33:23 -0400	[thread overview]
Message-ID: <20170323143341.31549-6-hch@lst.de> (raw)
In-Reply-To: <20170323143341.31549-1-hch@lst.de>

Copy & paste from the REQ_OP_WRITE_SAME code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/dm-core.h          |  1 +
 drivers/md/dm-io.c            | 10 +++++++---
 drivers/md/dm-linear.c        |  1 +
 drivers/md/dm-mpath.c         |  1 +
 drivers/md/dm-rq.c            | 11 ++++++++---
 drivers/md/dm-stripe.c        |  2 ++
 drivers/md/dm-table.c         | 30 ++++++++++++++++++++++++++++++
 drivers/md/dm.c               | 31 ++++++++++++++++++++++++++++---
 include/linux/device-mapper.h |  6 ++++++
 9 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index 136fda3ff9e5..fea5bd52ada8 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -132,6 +132,7 @@ void dm_init_md_queue(struct mapped_device *md);
 void dm_init_normal_md_queue(struct mapped_device *md);
 int md_in_flight(struct mapped_device *md);
 void disable_write_same(struct mapped_device *md);
+void disable_write_zeroes(struct mapped_device *md);
 
 static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
 {
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 03940bf36f6c..fad2d5d1888e 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -312,9 +312,12 @@ static void do_region(int op, int op_flags, unsigned region,
 	 */
 	if (op == REQ_OP_DISCARD)
 		special_cmd_max_sectors = q->limits.max_discard_sectors;
+	else if (op == REQ_OP_WRITE_ZEROES)
+		special_cmd_max_sectors = q->limits.max_write_zeroes_sectors;
 	else if (op == REQ_OP_WRITE_SAME)
 		special_cmd_max_sectors = q->limits.max_write_same_sectors;
-	if ((op == REQ_OP_DISCARD || op == REQ_OP_WRITE_SAME) &&
+	if ((op == REQ_OP_DISCARD || op == REQ_OP_WRITE_ZEROES ||
+	     op == REQ_OP_WRITE_SAME)  &&
 	    special_cmd_max_sectors == 0) {
 		dec_count(io, region, -EOPNOTSUPP);
 		return;
@@ -328,7 +331,8 @@ static void do_region(int op, int op_flags, unsigned region,
 		/*
 		 * Allocate a suitably sized-bio.
 		 */
-		if ((op == REQ_OP_DISCARD) || (op == REQ_OP_WRITE_SAME))
+		if ((op == REQ_OP_DISCARD) || (op == REQ_OP_WRITE_ZEROES) ||
+		    (op == REQ_OP_WRITE_SAME))
 			num_bvecs = 1;
 		else
 			num_bvecs = min_t(int, BIO_MAX_PAGES,
@@ -341,7 +345,7 @@ static void do_region(int op, int op_flags, unsigned region,
 		bio_set_op_attrs(bio, op, op_flags);
 		store_io_and_region_in_bio(bio, io, region);
 
-		if (op == REQ_OP_DISCARD) {
+		if (op == REQ_OP_DISCARD || op == REQ_OP_WRITE_ZEROES) {
 			num_sectors = min_t(sector_t, special_cmd_max_sectors, remaining);
 			bio->bi_iter.bi_size = num_sectors << SECTOR_SHIFT;
 			remaining -= num_sectors;
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 4788b0b989a9..e17fd44ceef5 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -59,6 +59,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	ti->num_flush_bios = 1;
 	ti->num_discard_bios = 1;
 	ti->num_write_same_bios = 1;
+	ti->num_write_zeroes_bios = 1;
 	ti->private = lc;
 	return 0;
 
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 7f223dbed49f..ab55955ed704 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1103,6 +1103,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	ti->num_flush_bios = 1;
 	ti->num_discard_bios = 1;
 	ti->num_write_same_bios = 1;
+	ti->num_write_zeroes_bios = 1;
 	if (m->queue_mode == DM_TYPE_BIO_BASED)
 		ti->per_io_data_size = multipath_per_bio_data_size();
 	else
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 28955b94d2b2..6006d5d4b06e 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -298,9 +298,14 @@ static void dm_done(struct request *clone, int error, bool mapped)
 			r = rq_end_io(tio->ti, clone, error, &tio->info);
 	}
 
-	if (unlikely(r == -EREMOTEIO && (req_op(clone) == REQ_OP_WRITE_SAME) &&
-		     !clone->q->limits.max_write_same_sectors))
-		disable_write_same(tio->md);
+	if (unlikely(r == -EREMOTEIO)) {
+		if (req_op(clone) == REQ_OP_WRITE_SAME &&
+		    !clone->q->limits.max_write_same_sectors)
+			disable_write_same(tio->md);
+		if (req_op(clone) == REQ_OP_WRITE_ZEROES &&
+		    !clone->q->limits.max_write_zeroes_sectors)
+			disable_write_zeroes(tio->md);
+	}
 
 	if (r <= 0)
 		/* The target wants to complete the I/O */
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index 28193a57bf47..5ef49c121d99 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -169,6 +169,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	ti->num_flush_bios = stripes;
 	ti->num_discard_bios = stripes;
 	ti->num_write_same_bios = stripes;
+	ti->num_write_zeroes_bios = stripes;
 
 	sc->chunk_size = chunk_size;
 	if (chunk_size & (chunk_size - 1))
@@ -293,6 +294,7 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)
 		return DM_MAPIO_REMAPPED;
 	}
 	if (unlikely(bio_op(bio) == REQ_OP_DISCARD) ||
+	    unlikely(bio_op(bio) == REQ_OP_WRITE_ZEROES) ||
 	    unlikely(bio_op(bio) == REQ_OP_WRITE_SAME)) {
 		target_bio_nr = dm_bio_get_target_bio_nr(bio);
 		BUG_ON(target_bio_nr >= sc->stripes);
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 3ad16d9c9d5a..5cd665c91ead 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1533,6 +1533,34 @@ static bool dm_table_supports_write_same(struct dm_table *t)
 	return true;
 }
 
+static int device_not_write_zeroes_capable(struct dm_target *ti, struct dm_dev *dev,
+					   sector_t start, sector_t len, void *data)
+{
+	struct request_queue *q = bdev_get_queue(dev->bdev);
+
+	return q && !q->limits.max_write_zeroes_sectors;
+}
+
+static bool dm_table_supports_write_zeroes(struct dm_table *t)
+{
+	struct dm_target *ti;
+	unsigned i = 0;
+
+	while (i < dm_table_get_num_targets(t)) {
+		ti = dm_table_get_target(t, i++);
+
+		if (!ti->num_write_zeroes_bios)
+			return false;
+
+		if (!ti->type->iterate_devices ||
+		    ti->type->iterate_devices(ti, device_not_write_zeroes_capable, NULL))
+			return false;
+	}
+
+	return true;
+}
+
+
 static int device_discard_capable(struct dm_target *ti, struct dm_dev *dev,
 				  sector_t start, sector_t len, void *data)
 {
@@ -1603,6 +1631,8 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
 
 	if (!dm_table_supports_write_same(t))
 		q->limits.max_write_same_sectors = 0;
+	if (!dm_table_supports_write_zeroes(t))
+		q->limits.max_write_zeroes_sectors = 0;
 
 	if (dm_table_all_devices_attribute(t, queue_supports_sg_merge))
 		queue_flag_clear_unlocked(QUEUE_FLAG_NO_SG_MERGE, q);
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index dfb75979e455..e8226359c8f7 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -825,6 +825,14 @@ void disable_write_same(struct mapped_device *md)
 	limits->max_write_same_sectors = 0;
 }
 
+void disable_write_zeroes(struct mapped_device *md)
+{
+	struct queue_limits *limits = dm_get_queue_limits(md);
+
+	/* device doesn't really support WRITE ZEROES, disable it */
+	limits->max_write_zeroes_sectors = 0;
+}
+
 static void clone_endio(struct bio *bio)
 {
 	int error = bio->bi_error;
@@ -851,9 +859,14 @@ static void clone_endio(struct bio *bio)
 		}
 	}
 
-	if (unlikely(r == -EREMOTEIO && (bio_op(bio) == REQ_OP_WRITE_SAME) &&
-		     !bdev_get_queue(bio->bi_bdev)->limits.max_write_same_sectors))
-		disable_write_same(md);
+	if (unlikely(r == -EREMOTEIO)) {
+		if (bio_op(bio) == REQ_OP_WRITE_SAME &&
+		    !bdev_get_queue(bio->bi_bdev)->limits.max_write_same_sectors)
+			disable_write_same(md);
+		if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
+		    !bdev_get_queue(bio->bi_bdev)->limits.max_write_zeroes_sectors)
+			disable_write_zeroes(md);
+	}
 
 	free_tio(tio);
 	dec_pending(io, error);
@@ -1202,6 +1215,11 @@ static unsigned get_num_write_same_bios(struct dm_target *ti)
 	return ti->num_write_same_bios;
 }
 
+static unsigned get_num_write_zeroes_bios(struct dm_target *ti)
+{
+	return ti->num_write_zeroes_bios;
+}
+
 typedef bool (*is_split_required_fn)(struct dm_target *ti);
 
 static bool is_split_required_for_discard(struct dm_target *ti)
@@ -1256,6 +1274,11 @@ static int __send_write_same(struct clone_info *ci)
 	return __send_changing_extent_only(ci, get_num_write_same_bios, NULL);
 }
 
+static int __send_write_zeroes(struct clone_info *ci)
+{
+	return __send_changing_extent_only(ci, get_num_write_zeroes_bios, NULL);
+}
+
 /*
  * Select the correct strategy for processing a non-flush bio.
  */
@@ -1270,6 +1293,8 @@ static int __split_and_process_non_flush(struct clone_info *ci)
 		return __send_discard(ci);
 	else if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
 		return __send_write_same(ci);
+	else if (unlikely(bio_op(bio) == REQ_OP_WRITE_ZEROES))
+		return __send_write_zeroes(ci);
 
 	ti = dm_table_find_target(ci->map, ci->sector);
 	if (!dm_target_is_valid(ti))
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index a7e6903866fd..3829bee2302a 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -255,6 +255,12 @@ struct dm_target {
 	unsigned num_write_same_bios;
 
 	/*
+	 * The number of WRITE ZEROES bios that will be submitted to the target.
+	 * The bio number can be accessed with dm_bio_get_target_bio_nr.
+	 */
+	unsigned num_write_zeroes_bios;
+
+	/*
 	 * The minimum number of extra bytes allocated in each io for the
 	 * target to use.
 	 */
-- 
2.11.0

  parent reply	other threads:[~2017-03-23 14:33 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23 14:33 RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload Christoph Hellwig
2017-03-23 14:33 ` [PATCH 01/23] block: renumber REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-28 16:12   ` Bart Van Assche
2017-03-28 16:12     ` Bart Van Assche
     [not found]     ` <1490717553.2573.4.camel-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2017-03-30  8:53       ` hch-jcswGhMUV9g
2017-03-30  8:53         ` hch
2017-03-23 14:33 ` [PATCH 02/23] block: implement splitting of REQ_OP_WRITE_ZEROES bios Christoph Hellwig
2017-03-23 14:33 ` [PATCH 03/23] sd: implement REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-28 18:50   ` Bart Van Assche
2017-03-28 18:50     ` Bart Van Assche
     [not found]     ` <1490726988.2573.16.camel-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2017-03-28 19:33       ` Mike Snitzer
2017-03-28 19:33         ` Mike Snitzer
2017-03-30  2:25       ` Martin K. Petersen
2017-03-30  2:25         ` Martin K. Petersen
2017-03-29 14:51     ` Paolo Bonzini
2017-03-29 16:28       ` Bart Van Assche
2017-03-29 16:28         ` Bart Van Assche
2017-03-29 16:53         ` Paolo Bonzini
2017-03-29 16:53           ` Paolo Bonzini
2017-03-23 14:33 ` [PATCH 04/23] md: support REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-23 14:33 ` Christoph Hellwig [this message]
2017-03-23 14:33 ` [PATCH 06/23] dm-kcopyd: switch to use REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-23 14:55   ` Mike Snitzer
2017-03-23 14:56     ` Christoph Hellwig
2017-03-23 15:10       ` Mike Snitzer
2017-03-27  9:12         ` Christoph Hellwig
2017-03-27  9:12           ` Christoph Hellwig
2017-03-23 14:33 ` [PATCH 07/23] block: stop using blkdev_issue_write_same for zeroing Christoph Hellwig
2017-03-23 14:33 ` [PATCH 08/23] block: add a flags argument to (__)blkdev_issue_zeroout Christoph Hellwig
2017-03-23 14:33 ` [PATCH 09/23] block: add a REQ_UNMAP flag for REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-23 14:33 ` [PATCH 10/23] block: add a new BLKDEV_ZERO_NOFALLBACK flag Christoph Hellwig
2017-03-23 14:33 ` [PATCH 11/23] block_dev: use blkdev_issue_zerout for hole punches Christoph Hellwig
2017-03-28 16:50   ` Bart Van Assche
2017-03-28 16:50     ` Bart Van Assche
     [not found]     ` <1490719834.2573.9.camel-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2017-03-30  8:59       ` hch-jcswGhMUV9g
2017-03-30  8:59         ` hch
2017-03-23 14:33 ` [PATCH 12/23] sd: handle REQ_UNMAP Christoph Hellwig
     [not found]   ` <20170323143341.31549-13-hch-jcswGhMUV9g@public.gmane.org>
2017-03-28 16:48     ` Bart Van Assche
2017-03-28 16:48       ` Bart Van Assche
2017-03-29 14:57       ` Paolo Bonzini
     [not found]       ` <1490719722.2573.8.camel-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2017-03-30  9:02         ` hch-jcswGhMUV9g
2017-03-30  9:02           ` hch
     [not found]           ` <20170330090201.GD12015-jcswGhMUV9g@public.gmane.org>
2017-03-30 15:28             ` Martin K. Petersen
2017-03-30 15:28               ` Martin K. Petersen
2017-03-30 17:30               ` hch
2017-03-30 17:30                 ` hch
     [not found]                 ` <20170330173020.GB24229-jcswGhMUV9g@public.gmane.org>
2017-03-31  2:19                   ` Martin K. Petersen
2017-03-31  2:19                     ` Martin K. Petersen
     [not found]                     ` <yq17f36yypg.fsf-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-03-31  7:18                       ` hch-jcswGhMUV9g
2017-03-31  7:18                         ` hch
2017-03-23 14:33 ` [PATCH 13/23] nvme: implement REQ_OP_WRITE_ZEROES Christoph Hellwig
2017-03-23 14:33 ` [PATCH 14/23] zram: " Christoph Hellwig
2017-03-23 14:33 ` [PATCH 15/23] loop: " Christoph Hellwig
2017-03-23 14:33 ` [PATCH 16/23] brd: remove discard support Christoph Hellwig
2017-03-23 14:33 ` [PATCH 17/23] rbd: remove the discard_zeroes_data flag Christoph Hellwig
2017-03-23 14:33 ` [PATCH 18/23] rsxx: " Christoph Hellwig
2017-03-23 14:33 ` [PATCH 19/23] mmc: " Christoph Hellwig
2017-03-23 14:33 ` [PATCH 20/23] block: stop using discards for zeroing Christoph Hellwig
2017-03-23 14:33 ` [PATCH 21/23] drbd: make intelligent use of blkdev_issue_zeroout Christoph Hellwig
2017-03-23 14:33 ` [PATCH 22/23] drbd: implement REQ_OP_WRITE_ZEROES Christoph Hellwig
     [not found]   ` <20170323143341.31549-23-hch-jcswGhMUV9g@public.gmane.org>
2017-03-30 10:06     ` Lars Ellenberg
2017-03-30 10:06       ` Lars Ellenberg
2017-03-30 11:44       ` Christoph Hellwig
2017-03-30 12:50         ` [Drbd-dev] " Lars Ellenberg
     [not found]         ` <20170330114408.GA15777-jcswGhMUV9g@public.gmane.org>
2017-03-30 13:49           ` Mike Snitzer
2017-03-30 13:49             ` Mike Snitzer
     [not found]             ` <20170330134957.GA508-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-03-30 15:20               ` Martin K. Petersen
2017-03-30 15:20                 ` Martin K. Petersen
2017-03-30 23:15                 ` Mike Snitzer
     [not found]                   ` <20170330231550.GA3102-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-03-31  2:34                     ` Martin K. Petersen
2017-03-31  2:34                       ` Martin K. Petersen
2017-03-31  7:17                   ` Christoph Hellwig
2017-03-23 14:33 ` [PATCH 23/23] block: remove the discard_zeroes_data flag Christoph Hellwig
2017-03-28 17:00   ` Bart Van Assche
2017-03-28 17:00     ` Bart Van Assche
2017-03-29 14:52     ` Paolo Bonzini
2017-03-30  9:06     ` hch
     [not found]       ` <20170330090655.GF12015-jcswGhMUV9g@public.gmane.org>
2017-03-30 15:29         ` Martin K. Petersen
2017-03-30 15:29           ` Martin K. Petersen
2017-03-30 17:29           ` hch
     [not found] ` <20170323143341.31549-1-hch-jcswGhMUV9g@public.gmane.org>
2017-03-23 15:54   ` RFC: always use REQ_OP_WRITE_ZEROES for zeroing offload Lars Ellenberg
2017-03-23 15:54     ` Lars Ellenberg
2017-03-23 17:02     ` Mike Snitzer
2017-03-23 17:02       ` Mike Snitzer
     [not found]       ` <20170323170221.GA20854-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-03-23 22:53         ` Lars Ellenberg
2017-03-23 22:53           ` Lars Ellenberg
2017-03-29 14:57           ` Paolo Bonzini
     [not found]     ` <20170323155410.GD1138-w1SgEEioFePxa46PmUWvFg@public.gmane.org>
2017-03-27  9:10       ` Christoph Hellwig
2017-03-27  9:10         ` Christoph Hellwig
     [not found]         ` <20170327091056.GB6879-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-03-27 14:03           ` Mike Snitzer
2017-03-27 14:03             ` Mike Snitzer
     [not found]             ` <20170327140307.GA13020-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-03-27 14:57               ` Christoph Hellwig
2017-03-27 14:57                 ` Christoph Hellwig
2017-03-27 15:08             ` [Drbd-dev] " Bart Van Assche
2017-03-27 15:08               ` Bart Van Assche
2017-03-30  9:04       ` Christoph Hellwig
2017-03-30  9:04         ` Christoph Hellwig
2017-03-30 15:12 ` Mike Snitzer
2017-03-30 15:22   ` Martin K. Petersen
     [not found]     ` <yq1lgrm3i36.fsf-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-03-30 15:38       ` Mike Snitzer
2017-03-30 15:38         ` Mike Snitzer

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=20170323143341.31549-6-hch@lst.de \
    --to=hch@lst.de \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=philipp.reisner@linbit.com \
    --cc=shli@kernel.org \
    --cc=snitzer@redhat.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 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.