Skip to content

Commit de3b9e2

Browse files
isilenceaxboe
authored andcommitted
io_uring: don't vmap single page regions
When io_check_coalesce_buffer() meets a single page buffer it bails out and tells that it can be coalesced. That's fine for registered buffers as io_coalesce_buffer() wouldn't change anything, but the region code now uses the function to decided on whether to vmap the buffer or not. Report that a single page buffer is trivially coalescable and let io_sqe_buffer_register() to filter them. Fixes: c4d0ac1 ("io_uring/memmap: optimise single folio regions") Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/cb83e053f318857068447d40c95becebcd8aeced.1733689833.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 2e6406a commit de3b9e2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

io_uring/rsrc.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,9 @@ bool io_check_coalesce_buffer(struct page **page_array, int nr_pages,
675675
unsigned int count = 1, nr_folios = 1;
676676
int i;
677677

678-
if (nr_pages <= 1)
679-
return false;
680-
681678
data->nr_pages_mid = folio_nr_pages(folio);
682-
if (data->nr_pages_mid == 1)
683-
return false;
684-
685679
data->folio_shift = folio_shift(folio);
680+
686681
/*
687682
* Check if pages are contiguous inside a folio, and all folios have
688683
* the same page count except for the head and tail.
@@ -750,8 +745,10 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
750745
}
751746

752747
/* If it's huge page(s), try to coalesce them into fewer bvec entries */
753-
if (io_check_coalesce_buffer(pages, nr_pages, &data))
754-
coalesced = io_coalesce_buffer(&pages, &nr_pages, &data);
748+
if (nr_pages > 1 && io_check_coalesce_buffer(pages, nr_pages, &data)) {
749+
if (data.nr_pages_mid != 1)
750+
coalesced = io_coalesce_buffer(&pages, &nr_pages, &data);
751+
}
755752

756753
imu = kvmalloc(struct_size(imu, bvec, nr_pages), GFP_KERNEL);
757754
if (!imu)

0 commit comments

Comments
 (0)