Re: [PATCH v2 2/3] md: add cond_resched() to md_do_sync()'s skip path

[email protected] Thu, 23 Jul 2026 14:05:13 +0000
Newsgroups org.kernel.vger.linux-raid
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unbounded waitqueue spam from md_new_event() during sync skip loops.
--

--- Patch [2]: [PATCH v2 2/3] md: add cond_resched() to md_do_sync()'s skip path ---
commit 6f3b7b59be28b3b7daedbe090461ee12870bd481
Author: Yunye Zhao <[email protected]>

md: add cond_resched() to md_do_sync()'s skip path

This patch adds a cond_resched() to the skip loop in md_do_sync(). It
addresses a soft lockup watchdog trigger during raid10 recovery on large,
mostly clean arrays by yielding the CPU when regions are skipped.

> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index d1465bcd86c81..c2e8b203c4db2 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -9881,8 +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 isn't a bug introduced by this patch, but does this code cause unbounded
waitqueue spam from md_new_event() during sync skip loops?

When last_check starts at 0 and the personality skips regions, io_sectors
does not increment. Because last_check remains 0, the block just above this
diff checks:

		if (last_check == 0)
			/* this is the earliest that rebuild will be
			 * visible in /proc/mdstat
			 */
			md_new_event();

Since last_check == 0 evaluates to true on every iteration of the skip loop,
md_new_event() is called continuously.

For a large clean array with small skip chunks (like 128 sectors), this could
execute millions of times.

Could this lead to severe waitqueue spam and lock contention on
md_event_waiters, resulting in spurious wakeups for userspace processes
monitoring mdstat?

>  
>  		last_check = io_sectors;
>  	repeat:

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=2