Skip to content

Commit 3d6106a

Browse files
Chenliang Liaxboe
authored andcommitted
io_uring/rsrc: store folio shift and mask into imu
Store the folio shift and folio mask into imu struct and use it in iov_iter adjust, as we will have non PAGE_SIZE'd chunks if a multi-hugepage buffer get coalesced. Signed-off-by: Chenliang Li <cliang01.li@samsung.com> Reviewed-by: Anuj Gupta <anuj20.g@samsung.com> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/20240731090133.4106-2-cliang01.li@samsung.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d843634 commit 3d6106a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

io_uring/rsrc.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
915915
imu->ubuf = (unsigned long) iov->iov_base;
916916
imu->ubuf_end = imu->ubuf + iov->iov_len;
917917
imu->nr_bvecs = nr_pages;
918+
imu->folio_shift = PAGE_SHIFT;
919+
imu->folio_mask = PAGE_MASK;
918920
*pimu = imu;
919921
ret = 0;
920922

@@ -1031,23 +1033,18 @@ int io_import_fixed(int ddir, struct iov_iter *iter,
10311033
* we know that:
10321034
*
10331035
* 1) it's a BVEC iter, we set it up
1034-
* 2) all bvecs are PAGE_SIZE in size, except potentially the
1036+
* 2) all bvecs are the same in size, except potentially the
10351037
* first and last bvec
10361038
*
10371039
* So just find our index, and adjust the iterator afterwards.
10381040
* If the offset is within the first bvec (or the whole first
10391041
* bvec, just use iov_iter_advance(). This makes it easier
10401042
* since we can just skip the first segment, which may not
1041-
* be PAGE_SIZE aligned.
1043+
* be folio_size aligned.
10421044
*/
10431045
const struct bio_vec *bvec = imu->bvec;
10441046

10451047
if (offset < bvec->bv_len) {
1046-
/*
1047-
* Note, huge pages buffers consists of one large
1048-
* bvec entry and should always go this way. The other
1049-
* branch doesn't expect non PAGE_SIZE'd chunks.
1050-
*/
10511048
iter->bvec = bvec;
10521049
iter->count -= offset;
10531050
iter->iov_offset = offset;
@@ -1056,12 +1053,12 @@ int io_import_fixed(int ddir, struct iov_iter *iter,
10561053

10571054
/* skip first vec */
10581055
offset -= bvec->bv_len;
1059-
seg_skip = 1 + (offset >> PAGE_SHIFT);
1056+
seg_skip = 1 + (offset >> imu->folio_shift);
10601057

10611058
iter->bvec = bvec + seg_skip;
10621059
iter->nr_segs -= seg_skip;
10631060
iter->count -= bvec->bv_len + offset;
1064-
iter->iov_offset = offset & ~PAGE_MASK;
1061+
iter->iov_offset = offset & ~imu->folio_mask;
10651062
}
10661063
}
10671064

io_uring/rsrc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ struct io_mapped_ubuf {
4646
u64 ubuf;
4747
u64 ubuf_end;
4848
unsigned int nr_bvecs;
49+
unsigned int folio_shift;
4950
unsigned long acct_pages;
51+
unsigned long folio_mask;
5052
struct bio_vec bvec[] __counted_by(nr_bvecs);
5153
};
5254

0 commit comments

Comments
 (0)