Skip to contentSkip to conversation

fix nr_phys_segments vs iterators accounting v2

PATCH In review Christoph Hellwig 5 participants 19 messages May 16, 2019 – May 21, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

Hi all,

we have had a problem for a while where the number of segments that the bvec iterators will iterate over don't match the value in req->nr_phys_segments, causing problems for anyone looking at nr_phys_segments and iterating over bvec directly instead of using blk_rq_map_sg. The first patch in this series fixes this by making sure nr_phys_segments matches the actual number of segments. Drivers using blk_rq_map_sg will still get the lower number returned from function eventually, but the fact that we don't reduce the value earlier will not allow some merges that we might otherwise allow.

With that in place I also noticed that we do not properly account segements sizes on devices with a virt_boundary, but it turns out that segment sizes fundamentally don't make sense for such devices, as their "segment" is a fixed size "device page", and not a variable sized scatter/gather elements as in the block layer, so we make that fact formal.

Once all that is sorted out it is pretty clear that there is no good reason to have the front/back segement accounting to start with.

Changes since v1:
- update a commit log
- add fixes tags
- drop the follow on patches not suitable for 5.2

#1 lore raw

PATCH 1/4 block: don't decrement nr_phys_segments for physically contigous segments

Currently ll_merge_requests_fn, unlike all other merge functions, reduces nr_phys_segments by one if the last segment of the previous, and the first segment of the next segement are contigous. While this seems like a nice solution to avoid building smaller than possible requests it causes a mismatch between the segments actually present in the request and those iterated over by the bvec iterators, including __rq_for_each_bio. This could cause overwrites of too small kmalloc allocations in any driver using ranged discard, or also mistrigger the single segment optimization in the nvme-pci driver.

We could possibly work around this by making the bvec iterators take the front and back segment size into account, but that would require moving them from the bio to the bio_iter and spreading this mess over all users of bvecs. Or we could simply remove this optimization under the assumption that most users already build good enough bvecs, and that the bio merge patch never cared about this optimization either. The latter is what this patch does.

Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Fixes 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")
---
 block/blk-merge.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)
block/blk-merge.c +1 -22
index 21e87a714a73..80a5a0facb87 100644
@@ -358,7 +358,6 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 	unsigned front_seg_size;
 	struct bio *fbio, *bbio;
 	struct bvec_iter iter;
-	bool new_bio = false;
 
 	if (!bio)
 		return 0;
@@ -379,31 +378,12 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 	nr_phys_segs = 0;
 	for_each_bio(bio) {
 		bio_for_each_bvec(bv, bio, iter) {
-			if (new_bio) {
-				if (seg_size + bv.bv_len
-				    > queue_max_segment_size(q))
-					goto new_segment;
-				if (!biovec_phys_mergeable(q, &bvprv, &bv))
-					goto new_segment;
-
-				seg_size += bv.bv_len;
-
-				if (nr_phys_segs == 1 && seg_size >
-						front_seg_size)
-					front_seg_size = seg_size;
-
-				continue;
-			}
-new_segment:
 			bvec_split_segs(q, &bv, &nr_phys_segs, &seg_size,
 					&front_seg_size, NULL, UINT_MAX);
-			new_bio = false;
 		}
 		bbio = bio;
-		if (likely(bio->bi_iter.bi_size)) {
+		if (likely(bio->bi_iter.bi_size))
 			bvprv = bv;
-			new_bio = true;
-		}
 	}
 
 	fbio->bi_seg_front_size = front_seg_size;
@@ -725,7 +705,6 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 			req->bio->bi_seg_front_size = seg_size;
 		if (next->nr_phys_segments == 1)
 			next->biotail->bi_seg_back_size = seg_size;
-		total_phys_segments--;
 	}
 
 	if (total_phys_segments > queue_max_segments(q))
Signature · 1 line
2.20.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] block: don't decrement nr_phys_segments for physically contigous segments

Quoted 18 lines · Christoph Hellwig

Currently ll_merge_requests_fn, unlike all other merge functions, reduces nr_phys_segments by one if the last segment of the previous, and the first segment of the next segement are contigous. While this seems like a nice solution to avoid building smaller than possible requests it causes a mismatch between the segments actually present in the request and those iterated over by the bvec iterators, including __rq_for_each_bio. This could cause overwrites of too small kmalloc allocations in any driver using ranged discard, or also mistrigger the single segment optimization in the nvme-pci driver.

We could possibly work around this by making the bvec iterators take the front and back segment size into account, but that would require moving them from the bio to the bio_iter and spreading this mess over all users of bvecs. Or we could simply remove this optimization under the assumption that most users already build good enough bvecs, and that the bio merge patch never cared about this optimization either. The latter is what this patch does.

Quoted 8 lines
Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Fixes 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")
---
  block/blk-merge.c | 23 +----------------------
  1 file changed, 1 insertion(+), 22 deletions(-)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
#3 lore raw

Re: [PATCH 1/4] block: don't decrement nr_phys_segments for physically contigous segments

In reply to Christoph Hellwig

Hi Christoph,

Quoted 18 lines · Christoph Hellwig

Currently ll_merge_requests_fn, unlike all other merge functions, reduces nr_phys_segments by one if the last segment of the previous, and the first segment of the next segement are contigous. While this seems like a nice solution to avoid building smaller than possible requests it causes a mismatch between the segments actually present in the request and those iterated over by the bvec iterators, including __rq_for_each_bio. This could cause overwrites of too small kmalloc allocations in any driver using ranged discard, or also mistrigger the single segment optimization in the nvme-pci driver.

We could possibly work around this by making the bvec iterators take the front and back segment size into account, but that would require moving them from the bio to the bio_iter and spreading this mess over all users of bvecs. Or we could simply remove this optimization under the assumption that most users already build good enough bvecs, and that the bio merge patch never cared about this optimization either. The latter is what this patch does.

Quoted 2 lines
Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")

ll_merge_requests_fn() is only called from attempt_merge() in case that ELEVATOR_BACK_MERGE is returned from blk_try_req_merge(). However, for discard merge of both virtio_blk and nvme, ELEVATOR_DISCARD_MERGE is always returned from blk_try_req_merge() in attempt_merge(), so looks ll_merge_requests_fn() shouldn't be called for virtio_blk/nvme's discard request. Just wondering if you may explain a bit how the change on ll_merge_requests_fn() in this patch makes a difference on the above two commits?

Quoted 1 line
Fixes 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")

I guess it should be dff824b2aadb ("nvme-pci: optimize mapping of small single segment requests").

Yes, this patch helps for this case, cause blk_rq_nr_phys_segments() may be 1 but there are two bios which share same segment.

Thanks,
Ming

#4 lore raw

Re: [PATCH 1/4] block: don't decrement nr_phys_segments for physically contigous segments

Quoted 33 lines · Ming Lei

Hi Christoph,

Quoted 18 lines · Christoph Hellwig

Currently ll_merge_requests_fn, unlike all other merge functions, reduces nr_phys_segments by one if the last segment of the previous, and the first segment of the next segement are contigous. While this seems like a nice solution to avoid building smaller than possible requests it causes a mismatch between the segments actually present in the request and those iterated over by the bvec iterators, including __rq_for_each_bio. This could cause overwrites of too small kmalloc allocations in any driver using ranged discard, or also mistrigger the single segment optimization in the nvme-pci driver.

We could possibly work around this by making the bvec iterators take the front and back segment size into account, but that would require moving them from the bio to the bio_iter and spreading this mess over all users of bvecs. Or we could simply remove this optimization under the assumption that most users already build good enough bvecs, and that the bio merge patch never cared about this optimization either. The latter is what this patch does.

Quoted 2 lines
Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")

ll_merge_requests_fn() is only called from attempt_merge() in case that ELEVATOR_BACK_MERGE is returned from blk_try_req_merge(). However, for discard merge of both virtio_blk and nvme, ELEVATOR_DISCARD_MERGE is always returned from blk_try_req_merge() in attempt_merge(), so looks ll_merge_requests_fn() shouldn't be called for virtio_blk/nvme's discard request. Just wondering if you may explain a bit how the change on ll_merge_requests_fn() in this patch makes a difference on the above two commits?

Quoted 7 lines
Quoted 1 line
Fixes 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")

I guess it should be dff824b2aadb ("nvme-pci: optimize mapping of small single segment requests").

Yes, this patch helps for this case, cause blk_rq_nr_phys_segments() may be 1 but there are two bios which share same segment.

BTW, I just sent a single-line nvme-pci fix on this issue, which may be more suitable to serve as v5.2 fix:

http://lists.infradead.org/pipermail/linux-nvme/2019-May/024283.html

Thanks,
Ming

#5 lore raw

Re: [PATCH 1/4] block: don't decrement nr_phys_segments for physically contigous segments

In reply to Ming Lei
Quoted 8 lines · Ming Lei

ll_merge_requests_fn() is only called from attempt_merge() in case that ELEVATOR_BACK_MERGE is returned from blk_try_req_merge(). However, for discard merge of both virtio_blk and nvme, ELEVATOR_DISCARD_MERGE is always returned from blk_try_req_merge() in attempt_merge(), so looks ll_merge_requests_fn() shouldn't be called for virtio_blk/nvme's discard request. Just wondering if you may explain a bit how the change on ll_merge_requests_fn() in this patch makes a difference on the above two commits?

Good question. I've seen virtio overwriting its range, but I think this might have been been with a series to actually decrement nr_phys_segments for all cases where we can merge the tail and front bvecs. So mainline probably doesn't see it unless someone calls blk_recalc_rq_segments due to a partial completion or when using dm-multipath. Thinking of it at least the latter seems like a real possibily, although a rather unlikely use case.

Quoted 4 lines
Quoted 1 line
Fixes 297910571f08 ("nvme-pci: optimize mapping single segment requests using SGLs")

I guess it should be dff824b2aadb ("nvme-pci: optimize mapping of small single segment requests").

Indeed.

#6 lore raw

Re: [PATCH 1/4] block: don't decrement nr_phys_segments for physically contigous segments

Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Ming Lei

ll_merge_requests_fn() is only called from attempt_merge() in case that ELEVATOR_BACK_MERGE is returned from blk_try_req_merge(). However, for discard merge of both virtio_blk and nvme, ELEVATOR_DISCARD_MERGE is always returned from blk_try_req_merge() in attempt_merge(), so looks ll_merge_requests_fn() shouldn't be called for virtio_blk/nvme's discard request. Just wondering if you may explain a bit how the change on ll_merge_requests_fn() in this patch makes a difference on the above two commits?

Quoted 7 lines

Good question. I've seen virtio overwriting its range, but I think this might have been been with a series to actually decrement nr_phys_segments for all cases where we can merge the tail and front bvecs. So mainline probably doesn't see it unless someone calls blk_recalc_rq_segments due to a partial completion or when using dm-multipath. Thinking of it at least the latter seems like a real possibily, although a rather unlikely use case.

This patch shouldn't effect discard IO in case of partial completion too cause blk_recalc_rq_segments() always return 0 for discard IO w/wo this patch.

However looks this way is wrong, the following patch may help for this case:

include/linux/blkdev.h +6 -1
index 1aafeb923e7b..302667887ea1 100644
@@ -1109,7 +1109,12 @@ static inline unsigned short blk_rq_nr_phys_segments(struct request *rq)
  */
 static inline unsigned short blk_rq_nr_discard_segments(struct request *rq)
 {
-	return max_t(unsigned short, rq->nr_phys_segments, 1);
+	struct bio *bio;
+	unsigned shart segs = 0;
+
+	__rq_for_each_bio(bio, rq)
+		segs++;
+	return segs;
 }
 
 extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);

Or re-calculate the segment number in this way for multi-range discard IO in __blk_recalc_rq_segments().

Thanks,
Ming

#7 lore raw

PATCH 2/4 block: force an unlimited segment size on queues with a virt boundary

In reply to Christoph Hellwig

We currently fail to update the front/back segment size in the bio when deciding to allow an otherwise gappy segement to a device with a virt boundary. The reason why this did not cause problems is that devices with a virt boundary fundamentally don't use segments as we know it and thus don't care. Make that assumption formal by forcing an unlimited segement size in this case.

Fixes f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
---
 block/blk-settings.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/blk-settings.c +11 -0
index 3facc41476be..2ae348c101a0 100644
@@ -310,6 +310,9 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
 		       __func__, max_size);
 	}
 
+	/* see blk_queue_virt_boundary() for the explanation */
+	WARN_ON_ONCE(q->limits.virt_boundary_mask);
+
 	q->limits.max_segment_size = max_size;
 }
 EXPORT_SYMBOL(blk_queue_max_segment_size);
@@ -742,6 +745,14 @@ EXPORT_SYMBOL(blk_queue_segment_boundary);
 void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
 {
 	q->limits.virt_boundary_mask = mask;
+
+	/*
+	 * Devices that require a virtual boundary do not support scatter/gather
+	 * I/O natively, but instead require a descriptor list entry for each
+	 * page (which might not be idential to the Linux PAGE_SIZE).  Because
+	 * of that they are not limited by our notion of "segment size".
+	 */
+	q->limits.max_segment_size = UINT_MAX;
 }
 EXPORT_SYMBOL(blk_queue_virt_boundary);
 
Signature · 1 line
2.20.1
Reviewed-by on v1 2/4
#8 lore raw

Re: [PATCH 2/4] block: force an unlimited segment size on queues with a virt boundary

Quoted 34 lines · Christoph Hellwig

We currently fail to update the front/back segment size in the bio when deciding to allow an otherwise gappy segement to a device with a virt boundary. The reason why this did not cause problems is that devices with a virt boundary fundamentally don't use segments as we know it and thus don't care. Make that assumption formal by forcing an unlimited segement size in this case.

Fixes f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
---
  block/blk-settings.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
block/blk-settings.c +4 -0
index 3facc41476be..2ae348c101a0 100644
@@ -310,6 +310,9 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
  		       __func__, max_size);
  	}
 
+	/* see blk_queue_virt_boundary() for the explanation */
+	WARN_ON_ONCE(q->limits.virt_boundary_mask);
+
  	q->limits.max_segment_size = max_size;
  }
  EXPORT_SYMBOL(blk_queue_max_segment_size);
@@ -742,6 +745,14 @@ EXPORT_SYMBOL(blk_queue_segment_boundary);
  void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
  {
  	q->limits.virt_boundary_mask = mask;
+

block/blk-settings.c EXPORT_SYMBOL(blk_queue_segment_boundary); · line 758

Quoted 10 lines
block/blk-settings.c +7 -0
+	/*
+	 * Devices that require a virtual boundary do not support scatter/gather
+	 * I/O natively, but instead require a descriptor list entry for each
+	 * page (which might not be idential to the Linux PAGE_SIZE).  Because
+	 * of that they are not limited by our notion of "segment size".
+	 */
+	q->limits.max_segment_size = UINT_MAX;
  }
  EXPORT_SYMBOL(blk_queue_virt_boundary);
 

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
#9 lore raw

PATCH 3/4 block: remove the segment size check in bio_will_gap

In reply to Christoph Hellwig

We fundamentally do not have a maximum segement size for devices with a virt boundary. So don't bother checking it, especially given that the existing checks didn't properly work to start with as we never fully update the front/back segment size and miss the bi_seg_front_size that wuld have been required for some cases.

---
 block/blk-merge.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)
block/blk-merge.c +1 -18
index 80a5a0facb87..eee2c02c50ce 100644
@@ -12,23 +12,6 @@
 
 #include "blk.h"
 
-/*
- * Check if the two bvecs from two bios can be merged to one segment.  If yes,
- * no need to check gap between the two bios since the 1st bio and the 1st bvec
- * in the 2nd bio can be handled in one segment.
- */
-static inline bool bios_segs_mergeable(struct request_queue *q,
-		struct bio *prev, struct bio_vec *prev_last_bv,
-		struct bio_vec *next_first_bv)
-{
-	if (!biovec_phys_mergeable(q, prev_last_bv, next_first_bv))
-		return false;
-	if (prev->bi_seg_back_size + next_first_bv->bv_len >
-			queue_max_segment_size(q))
-		return false;
-	return true;
-}
-
 static inline bool bio_will_gap(struct request_queue *q,
 		struct request *prev_rq, struct bio *prev, struct bio *next)
 {
@@ -60,7 +43,7 @@ static inline bool bio_will_gap(struct request_queue *q,
 	 */
 	bio_get_last_bvec(prev, &pb);
 	bio_get_first_bvec(next, &nb);
-	if (bios_segs_mergeable(q, prev, &pb, &nb))
+	if (biovec_phys_mergeable(q, &pb, &nb))
 		return false;
 	return __bvec_gap_to_prev(q, &pb, nb.bv_offset);
 }
Signature · 1 line
2.20.1
Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] block: remove the segment size check in bio_will_gap

Quoted 6 lines · Christoph Hellwig

We fundamentally do not have a maximum segement size for devices with a virt boundary. So don't bother checking it, especially given that the existing checks didn't properly work to start with as we never fully update the front/back segment size and miss the bi_seg_front_size that wuld have been required for some cases.

Quoted 6 lines
---
  block/blk-merge.c | 19 +------------------
  1 file changed, 1 insertion(+), 18 deletions(-)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
#11 lore raw

PATCH 4/4 block: remove the bi_seg_{front,back}_size fields in struct bio

In reply to Christoph Hellwig

At this point these fields aren't used for anything, so we can remove them.

---
 block/blk-merge.c         | 94 +++++----------------------------------
 include/linux/blk_types.h |  7 ---
 2 files changed, 12 insertions(+), 89 deletions(-)
block/blk-merge.c +12 -82
index eee2c02c50ce..17713d7d98d5 100644
@@ -162,8 +162,7 @@ static unsigned get_max_segment_size(struct request_queue *q,
  * variables.
  */
 static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
-		unsigned *nsegs, unsigned *last_seg_size,
-		unsigned *front_seg_size, unsigned *sectors, unsigned max_segs)
+		unsigned *nsegs, unsigned *sectors, unsigned max_segs)
 {
 	unsigned len = bv->bv_len;
 	unsigned total_len = 0;
@@ -185,28 +184,12 @@ static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
 			break;
 	}
 
-	if (!new_nsegs)
-		return !!len;
-
-	/* update front segment size */
-	if (!*nsegs) {
-		unsigned first_seg_size;
-
-		if (new_nsegs == 1)
-			first_seg_size = get_max_segment_size(q, bv->bv_offset);
-		else
-			first_seg_size = queue_max_segment_size(q);
-
-		if (*front_seg_size < first_seg_size)
-			*front_seg_size = first_seg_size;
+	if (new_nsegs) {
+		*nsegs += new_nsegs;
+		if (sectors)
+			*sectors += total_len >> 9;
 	}
 
-	/* update other varibles */
-	*last_seg_size = seg_size;
-	*nsegs += new_nsegs;
-	if (sectors)
-		*sectors += total_len >> 9;
-
 	/* split in the middle of the bvec if len != 0 */
 	return !!len;
 }
@@ -218,8 +201,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
 {
 	struct bio_vec bv, bvprv, *bvprvp = NULL;
 	struct bvec_iter iter;
-	unsigned seg_size = 0, nsegs = 0, sectors = 0;
-	unsigned front_seg_size = bio->bi_seg_front_size;
+	unsigned nsegs = 0, sectors = 0;
 	bool do_split = true;
 	struct bio *new = NULL;
 	const unsigned max_sectors = get_max_io_size(q, bio);
@@ -243,8 +225,6 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
 				/* split in the middle of bvec */
 				bv.bv_len = (max_sectors - sectors) << 9;
 				bvec_split_segs(q, &bv, &nsegs,
-						&seg_size,
-						&front_seg_size,
 						&sectors, max_segs);
 			}
 			goto split;
@@ -258,12 +238,9 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
 
 		if (bv.bv_offset + bv.bv_len <= PAGE_SIZE) {
 			nsegs++;
-			seg_size = bv.bv_len;
 			sectors += bv.bv_len >> 9;
-			if (nsegs == 1 && seg_size > front_seg_size)
-				front_seg_size = seg_size;
-		} else if (bvec_split_segs(q, &bv, &nsegs, &seg_size,
-				    &front_seg_size, &sectors, max_segs)) {
+		} else if (bvec_split_segs(q, &bv, &nsegs, &sectors,
+				max_segs)) {
 			goto split;
 		}
 	}
@@ -278,10 +255,6 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
 			bio = new;
 	}
 
-	bio->bi_seg_front_size = front_seg_size;
-	if (seg_size > bio->bi_seg_back_size)
-		bio->bi_seg_back_size = seg_size;
-
 	return do_split ? new : NULL;
 }
 
@@ -336,17 +309,13 @@ EXPORT_SYMBOL(blk_queue_split);
 static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 					     struct bio *bio)
 {
-	struct bio_vec uninitialized_var(bv), bvprv = { NULL };
-	unsigned int seg_size, nr_phys_segs;
-	unsigned front_seg_size;
-	struct bio *fbio, *bbio;
+	unsigned int nr_phys_segs = 0;
 	struct bvec_iter iter;
+	struct bio_vec bv;
 
 	if (!bio)
 		return 0;
 
-	front_seg_size = bio->bi_seg_front_size;
-
 	switch (bio_op(bio)) {
 	case REQ_OP_DISCARD:
 	case REQ_OP_SECURE_ERASE:
@@ -356,23 +325,11 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
 		return 1;
 	}
 
-	fbio = bio;
-	seg_size = 0;
-	nr_phys_segs = 0;
 	for_each_bio(bio) {
-		bio_for_each_bvec(bv, bio, iter) {
-			bvec_split_segs(q, &bv, &nr_phys_segs, &seg_size,
-					&front_seg_size, NULL, UINT_MAX);
-		}
-		bbio = bio;
-		if (likely(bio->bi_iter.bi_size))
-			bvprv = bv;
+		bio_for_each_bvec(bv, bio, iter)
+			bvec_split_segs(q, &bv, &nr_phys_segs, NULL, UINT_MAX);
 	}
 
-	fbio->bi_seg_front_size = front_seg_size;
-	if (seg_size > bbio->bi_seg_back_size)
-		bbio->bi_seg_back_size = seg_size;
-
 	return nr_phys_segs;
 }
 
@@ -392,24 +349,6 @@ void blk_recount_segments(struct request_queue *q, struct bio *bio)
 	bio_set_flag(bio, BIO_SEG_VALID);
 }
 
-static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
-				   struct bio *nxt)
-{
-	struct bio_vec end_bv = { NULL }, nxt_bv;
-
-	if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
-	    queue_max_segment_size(q))
-		return 0;
-
-	if (!bio_has_data(bio))
-		return 1;
-
-	bio_get_last_bvec(bio, &end_bv);
-	bio_get_first_bvec(nxt, &nxt_bv);
-
-	return biovec_phys_mergeable(q, &end_bv, &nxt_bv);
-}
-
 static inline struct scatterlist *blk_next_sg(struct scatterlist **sg,
 		struct scatterlist *sglist)
 {
@@ -669,8 +608,6 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 				struct request *next)
 {
 	int total_phys_segments;
-	unsigned int seg_size =
-		req->biotail->bi_seg_back_size + next->bio->bi_seg_front_size;
 
 	if (req_gap_back_merge(req, next->bio))
 		return 0;
@@ -683,13 +620,6 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 		return 0;
 
 	total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
-	if (blk_phys_contig_segment(q, req->biotail, next->bio)) {
-		if (req->nr_phys_segments == 1)
-			req->bio->bi_seg_front_size = seg_size;
-		if (next->nr_phys_segments == 1)
-			next->biotail->bi_seg_back_size = seg_size;
-	}
-
 	if (total_phys_segments > queue_max_segments(q))
 		return 0;
 
include/linux/blk_types.h +0 -7
index be418275763c..95202f80676c 100644
@@ -159,13 +159,6 @@ struct bio {
 	 */
 	unsigned int		bi_phys_segments;
 
-	/*
-	 * To keep track of the max segment size, we account for the
-	 * sizes of the first and last mergeable segments in this bio.
-	 */
-	unsigned int		bi_seg_front_size;
-	unsigned int		bi_seg_back_size;
-
 	struct bvec_iter	bi_iter;
 
 	atomic_t		__bi_remaining;
Signature · 1 line
2.20.1
Reviewed-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] block: remove the bi_seg_{front,back}_size fields in struct bio

Quoted 9 lines · Christoph Hellwig

At this point these fields aren't used for anything, so we can remove them.

---
  block/blk-merge.c         | 94 +++++----------------------------------
  include/linux/blk_types.h |  7 ---
  2 files changed, 12 insertions(+), 89 deletions(-)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
#14 lore raw
Quoted 4 lines · Christoph Hellwig

Jens,

is this ok for 5.2? If not we need to hack around the sector accounting in nvme, and possibly virtio.

I'd rather do it right in 5.2, especially if we can get something acceptable cobbled together this week.

Signature · 1 line
Jens Axboe
#15 lore raw
Quoted 8 lines · Jens Axboe
Quoted 4 lines · Christoph Hellwig

Jens,

is this ok for 5.2? If not we need to hack around the sector accounting in nvme, and possibly virtio.

I'd rather do it right in 5.2, especially if we can get something acceptable cobbled together this week.

If this patchset will be merged to 5.2, please remove the following two lines from patch 1:

Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")

Because the patch 1 doesn't fix them actually.

Thanks,
Ming

maintainer
#16 lore raw
Quoted 10 lines · Ming Lei
Quoted 8 lines · Jens Axboe
Quoted 4 lines · Christoph Hellwig

Jens,

is this ok for 5.2? If not we need to hack around the sector accounting in nvme, and possibly virtio.

I'd rather do it right in 5.2, especially if we can get something acceptable cobbled together this week.

Quoted 8 lines

If this patchset will be merged to 5.2, please remove the following two lines from patch 1:

Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")

Because the patch 1 doesn't fix them actually.

I don't want to merge something unless you are happy with it as well. Are you fine with going this route?

Signature · 1 line
Jens Axboe
#17 lore raw
Quoted 14 lines · Jens Axboe
Quoted 13 lines · Ming Lei
Quoted 8 lines · Jens Axboe
Quoted 4 lines · Christoph Hellwig

Jens,

is this ok for 5.2? If not we need to hack around the sector accounting in nvme, and possibly virtio.

I'd rather do it right in 5.2, especially if we can get something acceptable cobbled together this week.

If this patchset will be merged to 5.2, please remove the following two lines from patch 1:

Quoted 8 lines
Quoted 5 lines
Fixes b35ba01ea697 ("nvme: support ranged discard requests")
Fixes 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")

Because the patch 1 doesn't fix them actually.

I don't want to merge something unless you are happy with it as well. Are you fine with going this route?

I am fine with this route, and just try to make the commit log not misleading.

Thanks,
Ming

#18 lore raw
Quoted 2 lines · Ming Lei

I am fine with this route, and just try to make the commit log not misleading.

I'll resend with the updated tags. And I'll also look into the whole recalc segments vs discard issue later, as we might have more dragons hidden there.