On Thu, Jul 11, 2024 at 10:50 AM Kundan Kumar <kundan.kumar@xxxxxxxxxxx> wrote: > > Using a helper function check if pages are contiguous and belong to same > folio, this is done as a COW may happen and change contiguous mapping of > pages of folio. > You can consider removing this part in the commit description, as the same comment is present below in the code as well. > #define PAGE_PTRS_PER_BVEC (sizeof(struct bio_vec) / sizeof(struct page *)) > > /** > @@ -1298,9 +1329,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt; > struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt; > struct page **pages = (struct page **)bv; > - ssize_t size, left; > - unsigned len, i = 0; > - size_t offset; > + ssize_t size; > + unsigned int i = 0, num_pages; > + size_t offset, folio_offset, left, len; > int ret = 0; > > /* > @@ -1342,15 +1373,29 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) > > for (left = size, i = 0; left > 0; left -= len, i++) { Can we do a i+=num_pages here, given that you are incrementing i by 1 here and by (num_pages-1) at the end of the loop. This way you can get rid of the increment that you are doing at the end of the loop. > struct page *page = pages[i]; > + struct folio *folio = page_folio(page); > + > + folio_offset = ((size_t)folio_page_idx(folio, page) << > + PAGE_SHIFT) + 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) > + len = get_contig_folio_len(&num_pages, pages, i, > + folio, left, offset); > > - 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); > + ret = bio_iov_add_zone_append_folio(bio, folio, len, > + folio_offset); > if (ret) > break; > } else > - bio_iov_add_page(bio, page, len, offset); > + bio_iov_add_folio(bio, folio, len, folio_offset); > + > + /* Skip the pages which got added */ > + i = i + (num_pages - 1); > > offset = 0; > } > -- > 2.25.1 > -- Anuj Gupta