From: Leon Romanovsky <leon@kernel.org>
To: lirongqing <lirongqing@baidu.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
huangjunxian6@hisilicon.com, linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/core: Reduce cond_resched() frequency in __ib_umem_release
Date: Wed, 26 Nov 2025 10:15:12 +0200 [thread overview]
Message-ID: <20251126081512.GG12483@unreal> (raw)
In-Reply-To: <20251126025147.2627-1-lirongqing@baidu.com>
On Wed, Nov 26, 2025 at 10:51:47AM +0800, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> The current implementation calls cond_resched() for every SG entry
> in __ib_umem_release(), which can increase needless overhead.
>
> This patch introduces RESCHED_LOOP_CNT_THRESHOLD (0x1000) to limit
> how often cond_resched() is called. The function now yields the CPU
> once every 4096 iterations, and yield at the very first iteration
> for lots of small umem case, to reduce scheduling overhead.
>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> drivers/infiniband/core/umem.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
> index 8fd84aa..ff540a2 100644
> --- a/drivers/infiniband/core/umem.c
> +++ b/drivers/infiniband/core/umem.c
> @@ -45,6 +45,8 @@
>
> #include "uverbs.h"
>
> +#define RESCHED_LOOP_CNT_THRESHOLD 0x1000
> +
> static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty)
> {
> bool make_dirty = umem->writable && dirty;
> @@ -58,7 +60,9 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
> for_each_sgtable_sg(&umem->sgt_append.sgt, sg, i) {
> unpin_user_page_range_dirty_lock(sg_page(sg),
> DIV_ROUND_UP(sg->length, PAGE_SIZE), make_dirty);
> - cond_resched();
> +
> + if (!(i % RESCHED_LOOP_CNT_THRESHOLD))
> + cond_resched();
I applied it, but added a fix to skip the initial cond_resched() call on the
first iteration.
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index ff540a230297..8137031c2a65 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -61,7 +61,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
unpin_user_page_range_dirty_lock(sg_page(sg),
DIV_ROUND_UP(sg->length, PAGE_SIZE), make_dirty);
- if (!(i % RESCHED_LOOP_CNT_THRESHOLD))
+ if (i && !(i % RESCHED_LOOP_CNT_THRESHOLD))
cond_resched();
}
> }
>
> sg_free_append_table(&umem->sgt_append);
> --
> 2.9.4
>
next prev parent reply other threads:[~2025-11-26 8:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 2:51 [PATCH] RDMA/core: Reduce cond_resched() frequency in __ib_umem_release lirongqing
2025-11-26 8:15 ` Leon Romanovsky [this message]
2025-11-26 8:15 ` Leon Romanovsky
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=20251126081512.GG12483@unreal \
--to=leon@kernel.org \
--cc=huangjunxian6@hisilicon.com \
--cc=jgg@ziepe.ca \
--cc=linux-rdma@vger.kernel.org \
--cc=lirongqing@baidu.com \
/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