Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/core: Reduce cond_resched() frequency in __ib_umem_release
@ 2025-11-26  2:51 lirongqing
  2025-11-26  8:15 ` Leon Romanovsky
  2025-11-26  8:15 ` Leon Romanovsky
  0 siblings, 2 replies; 3+ messages in thread
From: lirongqing @ 2025-11-26  2:51 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, huangjunxian6, linux-rdma; +Cc: Li RongQing

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();
 	}
 
 	sg_free_append_table(&umem->sgt_append);
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-26  8:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  2:51 [PATCH] RDMA/core: Reduce cond_resched() frequency in __ib_umem_release lirongqing
2025-11-26  8:15 ` Leon Romanovsky
2025-11-26  8:15 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox