On 06/06/24 06:56AM, Christoph Hellwig wrote:
@@ -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;
+
+ len = min_t(size_t, (folio_size(folio) - folio_offset), left);
+
+ num_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
+
+ if (num_pages > 1) {
I still hate having this logic in the block layer. Even if it is just
a dumb wrapper with the same logic as here I'd much prefer to have
a iov_iter_extract_folios, which can then shift down into a
pin_user_folios_fast and into the MM slowly rather than adding this
logic to the caller.
iov_iter_extract_folios will require allocation of a folio_vec array
which then will be filled after processing the pages[] array. This will
introduce extra allocation cost in the hot path.
--
Kundan