Skip to content

Commit 5a17131

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: separate niov number from pages
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>
1 parent 9b58440 commit 5a17131

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

io_uring/zcrx.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
181181
kvfree(area->nia.niovs);
182182
kvfree(area->user_refs);
183183
if (area->pages) {
184-
unpin_user_pages(area->pages, area->nia.num_niovs);
184+
unpin_user_pages(area->pages, area->nr_folios);
185185
kvfree(area->pages);
186186
}
187187
kfree(area);
@@ -192,7 +192,7 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
192192
struct io_uring_zcrx_area_reg *area_reg)
193193
{
194194
struct io_zcrx_area *area;
195-
int i, ret, nr_pages;
195+
int i, ret, nr_pages, nr_iovs;
196196
struct iovec iov;
197197

198198
if (area_reg->flags || area_reg->rq_area_token)
@@ -220,35 +220,36 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
220220
area->pages = NULL;
221221
goto err;
222222
}
223-
area->nia.num_niovs = nr_pages;
223+
area->nr_folios = nr_iovs = nr_pages;
224+
area->nia.num_niovs = nr_iovs;
224225

225-
area->nia.niovs = kvmalloc_array(nr_pages, sizeof(area->nia.niovs[0]),
226+
area->nia.niovs = kvmalloc_array(nr_iovs, sizeof(area->nia.niovs[0]),
226227
GFP_KERNEL | __GFP_ZERO);
227228
if (!area->nia.niovs)
228229
goto err;
229230

230-
area->freelist = kvmalloc_array(nr_pages, sizeof(area->freelist[0]),
231+
area->freelist = kvmalloc_array(nr_iovs, sizeof(area->freelist[0]),
231232
GFP_KERNEL | __GFP_ZERO);
232233
if (!area->freelist)
233234
goto err;
234235

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

238-
area->user_refs = kvmalloc_array(nr_pages, sizeof(area->user_refs[0]),
239+
area->user_refs = kvmalloc_array(nr_iovs, sizeof(area->user_refs[0]),
239240
GFP_KERNEL | __GFP_ZERO);
240241
if (!area->user_refs)
241242
goto err;
242243

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

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

251-
area->free_count = nr_pages;
252+
area->free_count = nr_iovs;
252253
area->ifq = ifq;
253254
/* we're only supporting one area per ifq for now */
254255
area->area_id = 0;

io_uring/zcrx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct io_zcrx_area {
1515
bool is_mapped;
1616
u16 area_id;
1717
struct page **pages;
18+
unsigned long nr_folios;
1819

1920
/* freelist */
2021
spinlock_t freelist_lock ____cacheline_aligned_in_smp;

0 commit comments

Comments
 (0)