Skip to content

Commit

Permalink
io_uring/zcrx: separate niov number from pages
Browse files Browse the repository at this point in the history
A preparation patch that separates the number of pages / folios from
the number of niovs. They will not match in the future to support huge
pages, improved dma mapping and/or larger chunk sizes.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/0780ac966ee84200385737f45bb0f2ada052392b.1743848231.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Apr 7, 2025
1 parent 9b58440 commit 5a17131
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions io_uring/zcrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
kvfree(area->nia.niovs);
kvfree(area->user_refs);
if (area->pages) {
unpin_user_pages(area->pages, area->nia.num_niovs);
unpin_user_pages(area->pages, area->nr_folios);
kvfree(area->pages);
}
kfree(area);
Expand All @@ -192,7 +192,7 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
struct io_uring_zcrx_area_reg *area_reg)
{
struct io_zcrx_area *area;
int i, ret, nr_pages;
int i, ret, nr_pages, nr_iovs;
struct iovec iov;

if (area_reg->flags || area_reg->rq_area_token)
Expand Down Expand Up @@ -220,35 +220,36 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
area->pages = NULL;
goto err;
}
area->nia.num_niovs = nr_pages;
area->nr_folios = nr_iovs = nr_pages;
area->nia.num_niovs = nr_iovs;

area->nia.niovs = kvmalloc_array(nr_pages, sizeof(area->nia.niovs[0]),
area->nia.niovs = kvmalloc_array(nr_iovs, sizeof(area->nia.niovs[0]),
GFP_KERNEL | __GFP_ZERO);
if (!area->nia.niovs)
goto err;

area->freelist = kvmalloc_array(nr_pages, sizeof(area->freelist[0]),
area->freelist = kvmalloc_array(nr_iovs, sizeof(area->freelist[0]),
GFP_KERNEL | __GFP_ZERO);
if (!area->freelist)
goto err;

for (i = 0; i < nr_pages; i++)
for (i = 0; i < nr_iovs; i++)
area->freelist[i] = i;

area->user_refs = kvmalloc_array(nr_pages, sizeof(area->user_refs[0]),
area->user_refs = kvmalloc_array(nr_iovs, sizeof(area->user_refs[0]),
GFP_KERNEL | __GFP_ZERO);
if (!area->user_refs)
goto err;

for (i = 0; i < nr_pages; i++) {
for (i = 0; i < nr_iovs; i++) {
struct net_iov *niov = &area->nia.niovs[i];

niov->owner = &area->nia;
area->freelist[i] = i;
atomic_set(&area->user_refs[i], 0);
}

area->free_count = nr_pages;
area->free_count = nr_iovs;
area->ifq = ifq;
/* we're only supporting one area per ifq for now */
area->area_id = 0;
Expand Down
1 change: 1 addition & 0 deletions io_uring/zcrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct io_zcrx_area {
bool is_mapped;
u16 area_id;
struct page **pages;
unsigned long nr_folios;

/* freelist */
spinlock_t freelist_lock ____cacheline_aligned_in_smp;
Expand Down

0 comments on commit 5a17131

Please sign in to comment.