From: Pavel Begunkov <[email protected]>
To: Chenliang Li <[email protected]>, [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected],
[email protected], [email protected]
Subject: Re: [PATCH v5 3/3] io_uring/rsrc: enable multi-hugepage buffer coalescing
Date: Tue, 9 Jul 2024 14:17:50 +0100 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 6/28/24 09:44, Chenliang Li wrote:
> Modify io_sqe_buffer_register to enable the coalescing for
> multi-hugepage fixed buffers.
>
> Signed-off-by: Chenliang Li <[email protected]>
> ---
> io_uring/rsrc.c | 47 ++++++++++++++++-------------------------------
> 1 file changed, 16 insertions(+), 31 deletions(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 3198cf854db1..790ed3c1bcc8 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -945,7 +945,8 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
> unsigned long off;
> size_t size;
> int ret, nr_pages, i;
> - struct folio *folio = NULL;
> + struct io_imu_folio_data data;
> + bool coalesced;
>
> *pimu = (struct io_mapped_ubuf *)&dummy_ubuf;
> if (!iov->iov_base)
> @@ -960,31 +961,8 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
> goto done;
> }
>
> - /* If it's a huge page, try to coalesce them into a single bvec entry */
> - if (nr_pages > 1) {
> - folio = page_folio(pages[0]);
> - for (i = 1; i < nr_pages; i++) {
> - /*
> - * Pages must be consecutive and on the same folio for
> - * this to work
> - */
> - if (page_folio(pages[i]) != folio ||
> - pages[i] != pages[i - 1] + 1) {
> - folio = NULL;
> - break;
> - }
> - }
> - if (folio) {
> - /*
> - * The pages are bound to the folio, it doesn't
> - * actually unpin them but drops all but one reference,
> - * which is usually put down by io_buffer_unmap().
> - * Note, needs a better helper.
> - */
> - unpin_user_pages(&pages[1], nr_pages - 1);
> - nr_pages = 1;
> - }
> - }
> + /* If it's huge page(s), try to coalesce them into fewer bvec entries */
> + coalesced = io_try_coalesce_buffer(&pages, &nr_pages, &data);
>
> imu = kvmalloc(struct_size(imu, bvec, nr_pages), GFP_KERNEL);
> if (!imu)
> @@ -1004,17 +982,24 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
> imu->nr_bvecs = nr_pages;
> imu->folio_shift = PAGE_SHIFT;
> imu->folio_mask = PAGE_MASK;
> + if (coalesced) {
> + imu->folio_shift = data.folio_shift;
> + imu->folio_mask = ~((1UL << data.folio_shift) - 1);
> + }
> *pimu = imu;
> ret = 0;
>
> - if (folio) {
> - bvec_set_page(&imu->bvec[0], pages[0], size, off);
> - goto done;
> - }
> for (i = 0; i < nr_pages; i++) {
> size_t vec_len;
>
> - vec_len = min_t(size_t, size, PAGE_SIZE - off);
> + if (coalesced) {
> + size_t seg_size = i ? data.folio_size :
> + PAGE_SIZE * data.nr_pages_head;
When you're compacting the page array, instead of taking a middle
page for the first folio, you can set it to the first page in the
folio and fix up the offset. Kind of:
new_array[0] = compound_head(old_array[0]);
off += folio_page_idx(folio, old_array[0]) << PAGE_SHIFT;
With that change you should be able to treat it in a uniform way
without branching.
off = (unsigned long) iov->iov_base & ~folio_mask;
vec_len = min_t(size_t, size, folio_size - off);
> +
> + vec_len = min_t(size_t, size, seg_size - off);
> + } else {
> + vec_len = min_t(size_t, size, PAGE_SIZE - off);
> + }
> bvec_set_page(&imu->bvec[i], pages[i], vec_len, off);
> off = 0;
> size -= vec_len;
--
Pavel Begunkov
next prev parent reply other threads:[~2024-07-09 13:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20240628084418epcas5p14c304761ca375a6afba3aa199c27f9e3@epcas5p1.samsung.com>
2024-06-28 8:44 ` [PATCH v5 0/3] io_uring/rsrc: coalescing multi-hugepage registered buffers Chenliang Li
[not found] ` <CGME20240628084420epcas5p32f49e7c977695d20bcef7734eb2e38b4@epcas5p3.samsung.com>
2024-06-28 8:44 ` [PATCH v5 1/3] io_uring/rsrc: add hugepage fixed buffer coalesce helpers Chenliang Li
2024-07-09 13:09 ` Pavel Begunkov
[not found] ` <CGME20240710022336epcas5p2685a44c8e04962830f4e7f8ffee8168f@epcas5p2.samsung.com>
2024-07-10 2:23 ` Chenliang Li
[not found] ` <CGME20240628084422epcas5p3b5d4c93e5fa30069c703bcead1fa0033@epcas5p3.samsung.com>
2024-06-28 8:44 ` [PATCH v5 2/3] io_uring/rsrc: store folio shift and mask into imu Chenliang Li
[not found] ` <CGME20240628084424epcas5p3c34ec2fb8fb45752ef6a11447812ae0d@epcas5p3.samsung.com>
2024-06-28 8:44 ` [PATCH v5 3/3] io_uring/rsrc: enable multi-hugepage buffer coalescing Chenliang Li
2024-07-09 13:17 ` Pavel Begunkov [this message]
[not found] ` <CGME20240710022900epcas5p368c4ebc44f3ace1ca0804116bd913512@epcas5p3.samsung.com>
2024-07-10 2:28 ` Chenliang Li
[not found] ` <CGME20240708021432epcas5p4e7e74d81a42a559f2b059e94e7022740@epcas5p4.samsung.com>
2024-07-08 2:14 ` [PATCH v5 0/3] io_uring/rsrc: coalescing multi-hugepage registered buffers Chenliang Li
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox