All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] md: fix soft lockup during resync when sync is repeatedly skipped
@ 2026-07-17  6:27 Yunye Zhao
  2026-07-17  6:51 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yunye Zhao @ 2026-07-17  6:27 UTC (permalink / raw)
  To: Song Liu, Yu Kuai
  Cc: Li Nan, Xiao Ni, Joseph Qi, linux-raid, linux-kernel, Yunye Zhao

md_do_sync()'s main loop advances io_sectors only when I/O is actually
issued (skipped == 0).  When sync_request() keeps returning skipped == 1,
io_sectors never increases, the "last_check + window > io_sectors" test
stays true, and every iteration takes the continue branch:

	sectors = mddev->pers->sync_request(mddev, j, max_sectors, &skipped);
	...
	if (!skipped)
		io_sectors += sectors;
	j += sectors;
	...
	if (last_check + window > io_sectors || j == max_sectors)
		continue;

During recovery or resync of a large array with a sparse bitmap, many
regions that need no syncing are skipped:

	raid10_sync_request()
	  md_bitmap_start_sync()	-> must_sync = false (no bitmap page)
	  /* every mirror skipped */
	  biolist == NULL -> *skipped = 1; return max_sync;

j then traverses the whole skipped range while io_sectors stays
unchanged.  On a non-preemptive kernel the resync thread (mdX_resync)
hogs the CPU for a long time and eventually triggers a soft lockup:

  watchdog: BUG: soft lockup - CPU#149 stuck for 313s! [mdX_resync]
   md_bitmap_start_sync+0x6f/0xe0
   raid10_sync_request+0x2c9/0x1530 [raid10]
   md_do_sync+0x810/0x1030
   md_thread+0xa7/0x150

Add cond_resched() to this continue path.

Signed-off-by: Yunye Zhao <yunye.zhao@linux.alibaba.com>
---
 drivers/md/md.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index d1465bcd86c8..e7411b033490 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9881,9 +9881,10 @@ void md_do_sync(struct md_thread *thread)
 			 */
 			md_new_event();
 
-		if (last_check + window > io_sectors || j == max_sectors)
+		if (last_check + window > io_sectors || j == max_sectors) {
+			cond_resched();
 			continue;
-
+		}
 		last_check = io_sectors;
 	repeat:
 		if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) {
-- 
2.19.1.6.gb485710b


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

* Re: [PATCH] md: fix soft lockup during resync when sync is repeatedly skipped
  2026-07-17  6:27 [PATCH] md: fix soft lockup during resync when sync is repeatedly skipped Yunye Zhao
@ 2026-07-17  6:51 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-07-17  6:51 UTC (permalink / raw)
  To: Yunye Zhao; +Cc: yukuai, linux-raid

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Repeatedly skipped I/O blocks cause an event storm, calling md_new_event() millions of times in a tight loop.
--

--- Patch [1]: [PATCH] md: fix soft lockup during resync when sync is repeatedly skipped ---
commit 02c063c34357030eaa8514f57d5e37328d410c0b
Author: Yunye Zhao <yunye.zhao@linux.alibaba.com>

md: fix soft lockup during resync when sync is repeatedly skipped

The md_do_sync() main loop advances io_sectors only when I/O is actually
issued. When regions are skipped, io_sectors never increases and the loop
takes the continue branch, eventually triggering a soft lockup on
non-preemptive kernels. This patch adds cond_resched() to this continue
path to prevent the soft lockup.

> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index d1465bcd86c81..e7411b0334901 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -9881,9 +9881,10 @@ void md_do_sync(struct md_thread *thread)
>  			 */
>  			md_new_event();
>  
> -		if (last_check + window > io_sectors || j == max_sectors)
> +		if (last_check + window > io_sectors || j == max_sectors) {
> +			cond_resched();
>  			continue;

[Severity: High]
This is a pre-existing issue, but can this loop in md_do_sync() cause an event
storm when I/O is repeatedly skipped?

During array recovery or resync with a sparse bitmap, io_sectors remains 0
when regions are skipped. Because last_check starts at 0, the check
(last_check + window > io_sectors) evaluates to true, causing the loop to
continue.

Since last_check is only updated after this continue statement, it remains 0
permanently across skipped regions. As a result, the preceding check for
(last_check == 0) remains true, calling md_new_event() on every skipped
iteration. This repeatedly wakes up user-space processes polling /proc/mdstat
and causes lock contention.

> -
> +		}
>  		last_check = io_sectors;
>  	repeat:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717062743.128189-1-yunye.zhao@linux.alibaba.com?part=1

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

end of thread, other threads:[~2026-07-17  6:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17  6:27 [PATCH] md: fix soft lockup during resync when sync is repeatedly skipped Yunye Zhao
2026-07-17  6:51 ` sashiko-bot

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.