public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>,
	"huangjunxian6@hisilicon.com" <huangjunxian6@hisilicon.com>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Subject: RE: [????] Re: [????] Re: [PATCH][v2] RDMA/core: Prevent soft lockup during large user memory region cleanup
Date: Thu, 20 Nov 2025 03:28:18 +0000	[thread overview]
Message-ID: <4482842b3e774a7d996130b0651d1923@baidu.com> (raw)
In-Reply-To: <20251119190602.GN17968@ziepe.ca>



> -----Original Message-----
> From: Jason Gunthorpe <jgg@ziepe.ca>
> Sent: 2025年11月20日 3:06
> To: Li,Rongqing <lirongqing@baidu.com>
> Cc: Leon Romanovsky <leon@kernel.org>; huangjunxian6@hisilicon.com;
> linux-rdma@vger.kernel.org
> Subject: [????] Re: [????] Re: [PATCH][v2] RDMA/core: Prevent soft lockup
> during large user memory region cleanup
> 
> On Wed, Nov 19, 2025 at 02:03:20AM +0000, Li,Rongqing wrote:
> > > > Fix soft lockup issues by incorporating cond_resched() calls
> > > > within __ib_umem_release(), and this SG entries are typically
> > > > grouped in 2MB chunks on x86_64, adding cond_resched() should has
> > > > minimal
> > > performance
> > > > impact.
> > >
> > > This is not true, I think this should have been more careful to only
> > > resched after larger groupings.. How much slower did you make normal
> 4k unpins??
> > >
> > > Jason
> >
> >
> > I don't see this as a issue for several reasons. First, this code path
> > is not performance-critical.
> 
> Yes it is!
> 
> > Second, the number of cond_resched
> > calls added by this modification is identical to what was introduced
> > in commit 928da37a229f3444,
> 
> No its not! That loop does entire batches of pages into a PAGE_SIZE memory
> buffer, this does it for every single 4k page.
> 

Thanks, I understand

To minimize performance impact on releasing memory regions, call cond_resched() per 4k loop, how about the below 

diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index c5b6863..613c16d 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 0xfff
+
 static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty)
 {
        bool make_dirty = umem->writable && dirty;
@@ -55,10 +57,15 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
                ib_dma_unmap_sgtable_attrs(dev, &umem->sgt_append.sgt,
                                           DMA_BIDIRECTIONAL, 0);

-       for_each_sgtable_sg(&umem->sgt_append.sgt, sg, i)
+       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);

+               if (!(i & RESCHED_LOOP_CNT_THRESHOLD)) {
+                       cond_resched();
+               }
+       }
+
        sg_free_append_table(&umem->sgt_append);
 }


-Li


  reply	other threads:[~2025-11-20  3:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13  9:53 [PATCH][v2] RDMA/core: Prevent soft lockup during large user memory region cleanup lirongqing
2025-11-13 11:27 ` Junxian Huang
2025-11-13 13:35 ` Leon Romanovsky
2025-11-17 17:47 ` Jason Gunthorpe
2025-11-19  2:03   ` [????] " Li,Rongqing
2025-11-19 19:06     ` Jason Gunthorpe
2025-11-20  3:28       ` Li,Rongqing [this message]
2025-11-21 23:33         ` [????] " Jason Gunthorpe

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=4482842b3e774a7d996130b0651d1923@baidu.com \
    --to=lirongqing@baidu.com \
    --cc=huangjunxian6@hisilicon.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox