Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: clean up io_coalesce_buffer()

We don't need special handling for the first page in
io_coalesce_buffer(), move it inside the loop.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
Link: https://lore.kernel.org/r/ad698cddc1eadb3d92a7515e95bb13f79420323d.1745083025.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
9cebcf7b ea769256

+20 -23
+20 -23
io_uring/rsrc.c
··· 685 685 struct io_imu_folio_data *data) 686 686 { 687 687 struct page **page_array = *pages, **new_array = NULL; 688 - int nr_pages_left = *nr_pages, i, j; 689 - int nr_folios = data->nr_folios; 688 + unsigned nr_pages_left = *nr_pages; 689 + unsigned nr_folios = data->nr_folios; 690 + unsigned i, j; 690 691 691 692 /* Store head pages only*/ 692 - new_array = kvmalloc_array(nr_folios, sizeof(struct page *), 693 - GFP_KERNEL); 693 + new_array = kvmalloc_array(nr_folios, sizeof(struct page *), GFP_KERNEL); 694 694 if (!new_array) 695 695 return false; 696 696 697 - new_array[0] = compound_head(page_array[0]); 698 - /* 699 - * The pages are bound to the folio, it doesn't 700 - * actually unpin them but drops all but one reference, 701 - * which is usually put down by io_buffer_unmap(). 702 - */ 703 - if (data->nr_pages_head > 1) 704 - unpin_user_folio(page_folio(new_array[0]), data->nr_pages_head - 1); 697 + for (i = 0, j = 0; i < nr_folios; i++) { 698 + struct page *p = compound_head(page_array[j]); 699 + struct folio *folio = page_folio(p); 700 + unsigned int nr; 705 701 706 - j = data->nr_pages_head; 707 - nr_pages_left -= data->nr_pages_head; 708 - for (i = 1; i < nr_folios; i++) { 709 - unsigned int nr_unpin; 702 + WARN_ON_ONCE(i > 0 && p != page_array[j]); 710 703 711 - new_array[i] = page_array[j]; 712 - nr_unpin = min_t(unsigned int, nr_pages_left - 1, 713 - data->nr_pages_mid - 1); 714 - if (nr_unpin) 715 - unpin_user_folio(page_folio(new_array[i]), nr_unpin); 716 - j += data->nr_pages_mid; 717 - nr_pages_left -= data->nr_pages_mid; 704 + nr = i ? data->nr_pages_mid : data->nr_pages_head; 705 + nr = min(nr, nr_pages_left); 706 + /* Drop all but one ref, the entire folio will remain pinned. */ 707 + if (nr > 1) 708 + unpin_user_folio(folio, nr - 1); 709 + j += nr; 710 + nr_pages_left -= nr; 711 + new_array[i] = p; 718 712 } 713 + 714 + WARN_ON_ONCE(j != *nr_pages); 715 + 719 716 kvfree(page_array); 720 717 *pages = new_array; 721 718 *nr_pages = nr_folios;