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: introduce struct iou_vec

I need a convenient way to pass around and work with iovec+size pair,
put them into a structure and makes use of it in rw.c

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/d39fadafc9e9047b0a292e5be6db3cf2f48bb1f7.1741362889.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
e1d49959 6e3da40e

+39 -12
+5
include/linux/io_uring_types.h
··· 110 110 } ____cacheline_aligned_in_smp; 111 111 }; 112 112 113 + struct iou_vec { 114 + struct iovec *iovec; 115 + unsigned nr; 116 + }; 117 + 113 118 struct io_uring { 114 119 u32 head; 115 120 u32 tail;
+9
io_uring/rsrc.c
··· 1260 1260 fput(file); 1261 1261 return ret; 1262 1262 } 1263 + 1264 + void io_vec_free(struct iou_vec *iv) 1265 + { 1266 + if (!iv->iovec) 1267 + return; 1268 + kfree(iv->iovec); 1269 + iv->iovec = NULL; 1270 + iv->nr = 0; 1271 + }
+16
io_uring/rsrc.h
··· 145 145 atomic_long_sub(nr_pages, &user->locked_vm); 146 146 } 147 147 148 + void io_vec_free(struct iou_vec *iv); 149 + 150 + static inline void io_vec_reset_iovec(struct iou_vec *iv, 151 + struct iovec *iovec, unsigned nr) 152 + { 153 + io_vec_free(iv); 154 + iv->iovec = iovec; 155 + iv->nr = nr; 156 + } 157 + 158 + static inline void io_alloc_cache_vec_kasan(struct iou_vec *iv) 159 + { 160 + if (IS_ENABLED(CONFIG_KASAN)) 161 + io_vec_free(iv); 162 + } 163 + 148 164 #endif
+7 -10
io_uring/rw.c
··· 87 87 int ret, nr_segs; 88 88 struct iovec *iov; 89 89 90 - if (io->free_iovec) { 91 - nr_segs = io->free_iov_nr; 92 - iov = io->free_iovec; 90 + if (io->vec.iovec) { 91 + nr_segs = io->vec.nr; 92 + iov = io->vec.iovec; 93 93 } else { 94 94 nr_segs = 1; 95 95 iov = &io->fast_iov; ··· 101 101 return ret; 102 102 if (iov) { 103 103 req->flags |= REQ_F_NEED_CLEANUP; 104 - io->free_iov_nr = io->iter.nr_segs; 105 - kfree(io->free_iovec); 106 - io->free_iovec = iov; 104 + io_vec_reset_iovec(&io->vec, iov, io->iter.nr_segs); 107 105 } 108 106 return 0; 109 107 } ··· 149 151 if (unlikely(issue_flags & IO_URING_F_UNLOCKED)) 150 152 return; 151 153 152 - io_alloc_cache_kasan(&rw->free_iovec, &rw->free_iov_nr); 154 + io_alloc_cache_vec_kasan(&rw->vec); 153 155 if (io_alloc_cache_put(&req->ctx->rw_cache, rw)) { 154 156 req->async_data = NULL; 155 157 req->flags &= ~REQ_F_ASYNC_DATA; ··· 199 201 rw = io_uring_alloc_async_data(&ctx->rw_cache, req); 200 202 if (!rw) 201 203 return -ENOMEM; 202 - if (rw->free_iovec) 204 + if (rw->vec.iovec) 203 205 req->flags |= REQ_F_NEED_CLEANUP; 204 206 rw->bytes_done = 0; 205 207 return 0; ··· 1325 1327 { 1326 1328 struct io_async_rw *rw = (struct io_async_rw *) entry; 1327 1329 1328 - if (rw->free_iovec) 1329 - kfree(rw->free_iovec); 1330 + io_vec_free(&rw->vec); 1330 1331 kfree(rw); 1331 1332 }
+2 -2
io_uring/rw.h
··· 9 9 }; 10 10 11 11 struct io_async_rw { 12 + struct iou_vec vec; 12 13 size_t bytes_done; 13 - struct iovec *free_iovec; 14 + 14 15 struct_group(clear, 15 16 struct iov_iter iter; 16 17 struct iov_iter_state iter_state; 17 18 struct iovec fast_iov; 18 - int free_iov_nr; 19 19 /* 20 20 * wpq is for buffered io, while meta fields are used with 21 21 * direct io