linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix page_is_mergeable() for compound pages
@ 2020-08-17 19:52 Matthew Wilcox (Oracle)
  2020-08-18  2:15 ` Ming Lei
  2020-08-18  2:36 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2020-08-17 19:52 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Matthew Wilcox (Oracle),
	linux-block, linux-kernel, Christoph Hellwig, Ming Lei

If we pass in an offset which is larger than PAGE_SIZE, then
page_is_mergeable() thinks it's not mergeable with the previous bio_vec,
leading to a large number of bio_vecs being used.  Use a slightly more
obvious test that the two pages are compatible with each other.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Fixes: 52d52d1c98a9 ("block: only allow contiguous page structs in a bio_vec")

---
 block/bio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index c63ba04bd629..a9931f23d933 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -740,8 +740,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
 		struct page *page, unsigned int len, unsigned int off,
 		bool *same_page)
 {
-	phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
-		bv->bv_offset + bv->bv_len - 1;
+	size_t bv_end = bv->bv_offset + bv->bv_len;
+	phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + bv_end - 1;
 	phys_addr_t page_addr = page_to_phys(page);
 
 	if (vec_end_addr + 1 != page_addr + off)
@@ -750,9 +750,9 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
 		return false;
 
 	*same_page = ((vec_end_addr & PAGE_MASK) == page_addr);
-	if (!*same_page && pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page)
-		return false;
-	return true;
+	if (*same_page)
+		return true;
+	return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
 }
 
 /*
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: Fix page_is_mergeable() for compound pages
  2020-08-17 19:52 [PATCH] block: Fix page_is_mergeable() for compound pages Matthew Wilcox (Oracle)
@ 2020-08-18  2:15 ` Ming Lei
  2020-08-18  2:36 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2020-08-18  2:15 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: Jens Axboe, linux-block, linux-kernel, Christoph Hellwig

On Mon, Aug 17, 2020 at 08:52:06PM +0100, Matthew Wilcox (Oracle) wrote:
> If we pass in an offset which is larger than PAGE_SIZE, then
> page_is_mergeable() thinks it's not mergeable with the previous bio_vec,
> leading to a large number of bio_vecs being used.  Use a slightly more
> obvious test that the two pages are compatible with each other.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Fixes: 52d52d1c98a9 ("block: only allow contiguous page structs in a bio_vec")
> 
> ---
>  block/bio.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index c63ba04bd629..a9931f23d933 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -740,8 +740,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
>  		struct page *page, unsigned int len, unsigned int off,
>  		bool *same_page)
>  {
> -	phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
> -		bv->bv_offset + bv->bv_len - 1;
> +	size_t bv_end = bv->bv_offset + bv->bv_len;
> +	phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + bv_end - 1;
>  	phys_addr_t page_addr = page_to_phys(page);
>  
>  	if (vec_end_addr + 1 != page_addr + off)
> @@ -750,9 +750,9 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
>  		return false;
>  
>  	*same_page = ((vec_end_addr & PAGE_MASK) == page_addr);
> -	if (!*same_page && pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page)
> -		return false;
> -	return true;
> +	if (*same_page)
> +		return true;
> +	return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);

Looks this way is more straightforward, meantime can cover compound
pages:

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: Fix page_is_mergeable() for compound pages
  2020-08-17 19:52 [PATCH] block: Fix page_is_mergeable() for compound pages Matthew Wilcox (Oracle)
  2020-08-18  2:15 ` Ming Lei
@ 2020-08-18  2:36 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-08-18  2:36 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: linux-block, linux-kernel, Christoph Hellwig, Ming Lei

On 8/17/20 12:52 PM, Matthew Wilcox (Oracle) wrote:
> If we pass in an offset which is larger than PAGE_SIZE, then
> page_is_mergeable() thinks it's not mergeable with the previous bio_vec,
> leading to a large number of bio_vecs being used.  Use a slightly more
> obvious test that the two pages are compatible with each other.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-18  2:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 19:52 [PATCH] block: Fix page_is_mergeable() for compound pages Matthew Wilcox (Oracle)
2020-08-18  2:15 ` Ming Lei
2020-08-18  2:36 ` Jens Axboe

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).