Re: [PATCH v4 1/2] block: add folio awareness instead of looping through pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 05, 2024 at 02:54:54PM +0530, Kundan Kumar wrote:
> @@ -1214,27 +1214,27 @@ static int bio_iov_add_page(struct bio *bio, struct page *page,
>  
>  	if (bio->bi_vcnt > 0 &&
>  	    bvec_try_merge_page(&bio->bi_io_vec[bio->bi_vcnt - 1],
> -				page, len, offset, &same_page)) {
> +				&folio->page, len, offset, &same_page)) {

Let's make that folio_page(folio, 0)

> +static int bio_iov_add_zone_append_folio(struct bio *bio, struct folio *folio,
>  		unsigned int len, unsigned int offset)
>  {
>  	struct request_queue *q = bdev_get_queue(bio->bi_bdev);
>  	bool same_page = false;
>  
> -	if (bio_add_hw_page(q, bio, page, len, offset,
> +	if (bio_add_hw_page(q, bio, &folio->page, len, offset,

Likewise.

> @@ -1301,15 +1301,49 @@ 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];
> +		struct folio *folio = page_folio(page);
> +
> +		/* Calculate the offset of page in folio */
> +		folio_offset = (folio_page_idx(folio, page) << PAGE_SHIFT) +
> +				offset;

No it doesn't.  I'd drop the comment entirely, but if you must have a
comment, it turns the page offset into a folio offset.

> +		len = min_t(size_t, (folio_size(folio) - folio_offset), left);
> +
> +		num_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
> +
> +		if (num_pages > 1) {
> +			ssize_t bytes = left;
> +			size_t contig_sz = min_t(size_t,  PAGE_SIZE - offset,
> +						 bytes);
> +
> +			/*
> +			 * Check if pages are contiguous and belong to the
> +			 * same folio.
> +			 */

You do like writing obvious comments, don't you?

> +			for (j = i + 1; j < i + num_pages; j++) {
> +				size_t next = min_t(size_t, PAGE_SIZE, bytes);
> +
> +				if (page_folio(pages[j]) != folio ||
> +				    pages[j] != pages[j - 1] + 1) {
> +					break;
> +				}
> +				contig_sz += next;
> +				bytes -= next;
> +			}
> +			num_pages = j - i;
> +			len = contig_sz;
> +		}





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux