All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Kundan Kumar <kundan.kumar@samsung.com>
Cc: axboe@kernel.dk, hch@lst.de, willy@infradead.org,
	linux-block@vger.kernel.org, joshi.k@samsung.com,
	mcgrof@kernel.org, anuj20.g@samsung.com, nj.shetty@samsung.com,
	c.gameti@samsung.com, gost.dev@samsung.com
Subject: Re: [PATCH] block : add larger order folio size instead of pages
Date: Wed, 24 Apr 2024 10:16:40 -0600	[thread overview]
Message-ID: <ZikwaBHfP0pTu_AK@kbusch-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20240419091721.1790-1-kundan.kumar@samsung.com>

On Fri, Apr 19, 2024 at 02:47:21PM +0530, Kundan Kumar wrote:
> @@ -1289,16 +1291,33 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
>  
>  	for (left = size, i = 0; left > 0; left -= len, i++) {
>  		struct page *page = pages[i];
> +		folio = page_folio(page);
> +
> +		if (!folio_test_large(folio) ||
> +		   (bio_op(bio) == REQ_OP_ZONE_APPEND)) {
> +			len = min_t(size_t, PAGE_SIZE - offset, left);
> +			if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
> +				ret = bio_iov_add_zone_append_page(bio, page,
> +						len, offset);
> +				if (ret)
> +					break;
> +			} else
> +				bio_iov_add_page(bio, page, len, offset);
> +		} else {
> +			/* See the offset of folio and the size */
> +			folio_offset = (folio_page_idx(folio, page)
> +					<< PAGE_SHIFT) + offset;
> +			size_folio = folio_size(folio);
>  
> -		len = min_t(size_t, PAGE_SIZE - offset, left);
> -		if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
> -			ret = bio_iov_add_zone_append_page(bio, page, len,
> -					offset);
> -			if (ret)
> -				break;
> -		} else
> -			bio_iov_add_page(bio, page, len, offset);
> +			/* Calculate the length of folio to be added */
> +			len = min_t(size_t, (size_folio - folio_offset), left);
> +
> +			num_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
>  
> +			bio_iov_add_page(bio, page, len, offset);

I think there's another optimization to be had here. You only need one
reference on the folio for all its pages, so I believe you can safely
drop (num_pages - 1) references right here. Then __bio_release_pages()
can be further simplified by removing the 'do{...}while()" loop
releasing individual pages.

I tested this atop your patch, and it looks okay so far. This could be
more efficient if we had access to gup_put_folio() since we already know
all the pages are part of the same folio (unpin_user_pages()
recalculates that)

---
diff --git a/block/bio.c b/block/bio.c
index 469606494f8f7..9829c79494108 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1155,7 +1155,6 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
 
 	bio_for_each_folio_all(fi, bio) {
 		struct page *page;
-		size_t nr_pages;
 
 		if (mark_dirty) {
 			folio_lock(fi.folio);
@@ -1163,11 +1162,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
 			folio_unlock(fi.folio);
 		}
 		page = folio_page(fi.folio, fi.offset / PAGE_SIZE);
-		nr_pages = (fi.offset + fi.length - 1) / PAGE_SIZE -
-			   fi.offset / PAGE_SIZE + 1;
-		do {
-			bio_release_page(bio, page++);
-		} while (--nr_pages != 0);
+		bio_release_page(bio, page);
 	}
 }
 EXPORT_SYMBOL_GPL(__bio_release_pages);
@@ -1315,6 +1310,8 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
 			num_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
 
 			bio_iov_add_page(bio, page, len, offset);
+			if (bio_flagged(bio, BIO_PAGE_PINNED) && num_pages > 1)
+				unpin_user_pages(pages + i, num_pages - 1);
 			/* Skip the pages which got added */
 			i = i + (num_pages - 1);
 		}
--

      parent reply	other threads:[~2024-04-24 16:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20240419092428epcas5p4f63759b0efa1f12dfbcf13c67fa8d0f0@epcas5p4.samsung.com>
2024-04-19  9:17 ` [PATCH] block : add larger order folio size instead of pages Kundan Kumar
2024-04-19 14:16   ` Matthew Wilcox
2024-04-22  9:44     ` Kundan Kumar
2024-04-22 11:14   ` Christoph Hellwig
2024-04-24 13:22     ` Kundan Kumar
2024-04-24 17:04       ` Keith Busch
2024-04-27  8:14       ` Christoph Hellwig
2024-04-24 16:16   ` Keith Busch [this message]

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=ZikwaBHfP0pTu_AK@kbusch-mbp.dhcp.thefacebook.com \
    --to=kbusch@kernel.org \
    --cc=anuj20.g@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=c.gameti@samsung.com \
    --cc=gost.dev@samsung.com \
    --cc=hch@lst.de \
    --cc=joshi.k@samsung.com \
    --cc=kundan.kumar@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=nj.shetty@samsung.com \
    --cc=willy@infradead.org \
    /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.