On 2024-07-09 13:17 UTC, Pavel Begunkov wrote: > On 6/28/24 09:44, Chenliang Li wrote: >> - if (folio) { >> - bvec_set_page(&imu->bvec[0], pages[0], size, off); >> - goto done; >> - } >> for (i = 0; i < nr_pages; i++) { >> size_t vec_len; >> >> - vec_len = min_t(size_t, size, PAGE_SIZE - off); >> + if (coalesced) { >> + size_t seg_size = i ? data.folio_size : >> + PAGE_SIZE * data.nr_pages_head; > > When you're compacting the page array, instead of taking a middle > page for the first folio, you can set it to the first page in the > folio and fix up the offset. Kind of: > > new_array[0] = compound_head(old_array[0]); > off += folio_page_idx(folio, old_array[0]) << PAGE_SHIFT; > > > With that change you should be able to treat it in a uniform way > without branching. > > off = (unsigned long) iov->iov_base & ~folio_mask; > vec_len = min_t(size_t, size, folio_size - off); That's brilliant. Will change it this way. Thanks, Chenliang Li