block: create a bio_try_merge_pc_page helper
Passsthrough bio handling should be the same as normal bio handling, except that we need to take hardware limitations into account. Thus use the common try_merge implementation after checking the hardware limits. This changes behavior in that we now also check segment and dma boundary settings for same page merges, which is a little more work but has no effect as those need to be larger than the page size. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
320ea869a1
commit
384209cd5b
34
block/bio.c
34
block/bio.c
@ -646,25 +646,20 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static bool bio_try_merge_pc_page(struct request_queue *q, struct bio *bio,
|
||||||
* Check if the @page can be added to the current segment(@bv), and make
|
struct page *page, unsigned len, unsigned offset,
|
||||||
* sure to call it only if page_is_mergeable(@bv, @page) is true
|
bool *same_page)
|
||||||
*/
|
|
||||||
static bool can_add_page_to_seg(struct request_queue *q,
|
|
||||||
struct bio_vec *bv, struct page *page, unsigned len,
|
|
||||||
unsigned offset)
|
|
||||||
{
|
{
|
||||||
|
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
|
||||||
unsigned long mask = queue_segment_boundary(q);
|
unsigned long mask = queue_segment_boundary(q);
|
||||||
phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
|
phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
|
||||||
phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
|
phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
|
||||||
|
|
||||||
if ((addr1 | mask) != (addr2 | mask))
|
if ((addr1 | mask) != (addr2 | mask))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (bv->bv_len + len > queue_max_segment_size(q))
|
if (bv->bv_len + len > queue_max_segment_size(q))
|
||||||
return false;
|
return false;
|
||||||
|
return __bio_try_merge_page(bio, page, len, offset, same_page);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -700,26 +695,18 @@ static int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (bio->bi_vcnt > 0) {
|
if (bio->bi_vcnt > 0) {
|
||||||
bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
|
if (bio_try_merge_pc_page(q, bio, page, len, offset,
|
||||||
|
&same_page)) {
|
||||||
if (page == bvec->bv_page &&
|
if (put_same_page && same_page)
|
||||||
offset == bvec->bv_offset + bvec->bv_len) {
|
|
||||||
if (put_same_page)
|
|
||||||
put_page(page);
|
put_page(page);
|
||||||
bvec->bv_len += len;
|
return len;
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page_is_mergeable(bvec, page, len, offset, &same_page) &&
|
|
||||||
can_add_page_to_seg(q, bvec, page, len, offset)) {
|
|
||||||
bvec->bv_len += len;
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the queue doesn't support SG gaps and adding this segment
|
* If the queue doesn't support SG gaps and adding this segment
|
||||||
* would create a gap, disallow it.
|
* would create a gap, disallow it.
|
||||||
*/
|
*/
|
||||||
|
bvec = &bio->bi_io_vec[bio->bi_vcnt - 1];
|
||||||
if (bvec_gap_to_prev(q, bvec, offset))
|
if (bvec_gap_to_prev(q, bvec, offset))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -735,7 +722,6 @@ static int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
|
|||||||
bvec->bv_len = len;
|
bvec->bv_len = len;
|
||||||
bvec->bv_offset = offset;
|
bvec->bv_offset = offset;
|
||||||
bio->bi_vcnt++;
|
bio->bi_vcnt++;
|
||||||
done:
|
|
||||||
bio->bi_iter.bi_size += len;
|
bio->bi_iter.bi_size += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user