All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: [PATCH v2 2/9] io_uring: add infra for importing vectored reg buffers
Date: Fri, 7 Mar 2025 14:07:59 +0000	[thread overview]
Message-ID: <75fb61af-0ace-4e2d-ae4d-66573c4a63b8@gmail.com> (raw)
In-Reply-To: <b054a88092767f7767f8447e7a5bdab15fcc0759.1741102644.git.asml.silence@gmail.com>

On 3/4/25 15:40, Pavel Begunkov wrote:
> Add io_import_reg_vec(), which will be responsible for importing
> vectored registered buffers. iovecs are overlapped with the resulting
> bvec in memory, which is why the iovec is expected to be padded in
> iou_vec.
> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
...
> +int io_import_reg_vec(int ddir, struct iov_iter *iter,
> +			struct io_kiocb *req, struct iou_vec *vec,
> +			unsigned nr_iovs, unsigned iovec_off,
> +			unsigned issue_flags)
> +{
> +	struct io_rsrc_node *node;
> +	struct io_mapped_ubuf *imu;
> +	struct iovec *iov;
> +	unsigned nr_segs;
> +
> +	node = io_find_buf_node(req, issue_flags);
> +	if (!node)
> +		return -EFAULT;
> +	imu = node->buf;
> +	if (imu->is_kbuf)
> +		return -EOPNOTSUPP;
> +	if (!(imu->dir & (1 << ddir)))
> +		return -EFAULT;
> +
> +	iov = vec->iovec + iovec_off;
> +	nr_segs = io_estimate_bvec_size(iov, nr_iovs, imu);

if (sizeof(struct bio_vec) > sizeof(struct iovec)) {
	size_t entry_sz = sizeof(struct iovec);
	size_t bvec_bytes = nr_segs * sizeof(struct bio_vec);
	size_t iovec_off = (bvec_bytes + entry_sz - 1) / entry_sz;

	nr_segs += iovec_off;
}

How about fixing it up like this for now? Instead of overlapping
bvec with iovec, it'd put them back to back and waste some memory
on 32bit.

I can try to make it a bit tighter, remove the if and let
the compiler to optimise it into no-op for x64, or allocate
max(bvec, iovec) * nr and see where it leads. But in either
way IMHO it's better to be left until I get more time.


> +
> +	if (WARN_ON_ONCE(iovec_off + nr_iovs != vec->nr) ||
> +	    nr_segs > vec->nr) {
> +		struct iou_vec tmp_vec = {};
> +		int ret;
> +
> +		ret = io_vec_realloc(&tmp_vec, nr_segs);
> +		if (ret)
> +			return ret;
> +
> +		iovec_off = tmp_vec.nr - nr_iovs;
> +		memcpy(tmp_vec.iovec + iovec_off, iov, sizeof(*iov) * nr_iovs);
> +		io_vec_free(vec);
> +
> +		*vec = tmp_vec;
> +		iov = vec->iovec + iovec_off;
> +		req->flags |= REQ_F_NEED_CLEANUP;
> +	}
> +
> +	return io_vec_fill_bvec(ddir, iter, imu, iov, nr_iovs, vec);
> +}


-- 
Pavel Begunkov


  reply	other threads:[~2025-03-07 14:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 15:40 [PATCH v2 0/9] Add support for vectored registered buffers Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 1/9] io_uring: introduce struct iou_vec Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 2/9] io_uring: add infra for importing vectored reg buffers Pavel Begunkov
2025-03-07 14:07   ` Pavel Begunkov [this message]
2025-03-07 14:14     ` Jens Axboe
2025-03-04 15:40 ` [PATCH v2 3/9] io_uring/rw: implement vectored registered rw Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 4/9] io_uring/rw: defer reg buf vec import Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 5/9] io_uring/net: combine msghdr copy Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 6/9] io_uring/net: pull vec alloc out of msghdr import Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 7/9] io_uring/net: convert to struct iou_vec Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 8/9] io_uring/net: implement vectored reg bufs for zctx Pavel Begunkov
2025-03-04 15:40 ` [PATCH v2 9/9] io_uring: cap cached iovec/bvec size Pavel Begunkov
2025-03-06 12:01 ` [PATCH v2 0/9] Add support for vectored registered buffers Jens Axboe
2025-03-06 12:10   ` Jens Axboe
2025-03-06 22:59     ` Jens Axboe
2025-03-07 14:14       ` Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=75fb61af-0ace-4e2d-ae4d-66573c4a63b8@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=andres@anarazel.de \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.